菜谱项目

CompanyTest.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Faker\Test\Provider\fr_FR;
  3. use Faker\Calculator\Luhn;
  4. use Faker\Generator;
  5. use Faker\Provider\fr_FR\Company;
  6. class CompanyTest extends \PHPUnit_Framework_TestCase
  7. {
  8. private $faker;
  9. public function setUp()
  10. {
  11. $faker = new Generator();
  12. $faker->addProvider(new Company($faker));
  13. $this->faker = $faker;
  14. }
  15. public function testSiretReturnsAValidSiret()
  16. {
  17. $siret = $this->faker->siret(false);
  18. $this->assertRegExp("/^\d{14}$/", $siret);
  19. $this->assertTrue(Luhn::isValid($siret));
  20. }
  21. public function testSiretReturnsAWellFormattedSiret()
  22. {
  23. $siret = $this->faker->siret();
  24. $this->assertRegExp("/^\d{3}\s\d{3}\s\d{3}\s\d{5}$/", $siret);
  25. $siret = str_replace(' ', '', $siret);
  26. $this->assertTrue(Luhn::isValid($siret));
  27. }
  28. public function testSirenReturnsAValidSiren()
  29. {
  30. $siren = $this->faker->siren(false);
  31. $this->assertRegExp("/^\d{9}$/", $siren);
  32. $this->assertTrue(Luhn::isValid($siren));
  33. }
  34. public function testSirenReturnsAWellFormattedSiren()
  35. {
  36. $siren = $this->faker->siren();
  37. $this->assertRegExp("/^\d{3}\s\d{3}\s\d{3}$/", $siren);
  38. $siren = str_replace(' ', '', $siren);
  39. $this->assertTrue(Luhn::isValid($siren));
  40. }
  41. public function testCatchPhraseReturnsValidCatchPhrase()
  42. {
  43. $this->assertTrue(TestableCompany::isCatchPhraseValid($this->faker->catchPhrase()));
  44. }
  45. public function testIsCatchPhraseValidReturnsFalseWhenAWordsAppearsTwice()
  46. {
  47. $isCatchPhraseValid = TestableCompany::isCatchPhraseValid('La sécurité de rouler en toute sécurité');
  48. $this->assertFalse($isCatchPhraseValid);
  49. }
  50. public function testIsCatchPhraseValidReturnsTrueWhenNoWordAppearsTwice()
  51. {
  52. $isCatchPhraseValid = TestableCompany::isCatchPhraseValid('La sécurité de rouler en toute simplicité');
  53. $this->assertTrue($isCatchPhraseValid);
  54. }
  55. }
  56. class TestableCompany extends Company
  57. {
  58. public static function isCatchPhraseValid($catchPhrase)
  59. {
  60. return parent::isCatchPhraseValid($catchPhrase);
  61. }
  62. }