您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

46 行
1.1KB

  1. <?php
  2. namespace Faker\Test\Provider;
  3. use Faker\Generator;
  4. use Faker\Provider\Barcode;
  5. class BarcodeTest extends \PHPUnit_Framework_TestCase
  6. {
  7. private $faker;
  8. public function setUp()
  9. {
  10. $faker = new Generator();
  11. $faker->addProvider(new Barcode($faker));
  12. $faker->seed(0);
  13. $this->faker = $faker;
  14. }
  15. public function testEan8()
  16. {
  17. $code = $this->faker->ean8();
  18. $this->assertRegExp('/^\d{8}$/i', $code);
  19. $codeWithoutChecksum = substr($code, 0, -1);
  20. $checksum = substr($code, -1);
  21. $this->assertEquals(TestableBarcode::eanChecksum($codeWithoutChecksum), $checksum);
  22. }
  23. public function testEan13()
  24. {
  25. $code = $this->faker->ean13();
  26. $this->assertRegExp('/^\d{13}$/i', $code);
  27. $codeWithoutChecksum = substr($code, 0, -1);
  28. $checksum = substr($code, -1);
  29. $this->assertEquals(TestableBarcode::eanChecksum($codeWithoutChecksum), $checksum);
  30. }
  31. }
  32. class TestableBarcode extends Barcode
  33. {
  34. public static function eanChecksum($input)
  35. {
  36. return parent::eanChecksum($input);
  37. }
  38. }