diff --git a/composer.json b/composer.json index 21f45cc..2beae22 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "doctrine/doctrine-bundle": "^1.8", "friendsofphp/php-cs-fixer": "^2.10", "phpstan/phpstan": "^0.9", - "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0", + "phpunit/phpunit": "^5.7.10 || ^6.0 || ^7.0", "symfony/asset": "^3.4 || ^4.0", "symfony/dom-crawler": "^3.0", "symfony/framework-bundle": "^3.4 || ^4.0", diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index b513772..58761e1 100755 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -148,6 +148,7 @@ public function theJsonOutputShouldBeEqualTo(PyStringNode $text) throw new \LogicException('Invalid JSON.'); } $diff = array_map('unserialize', array_diff(array_map('serialize', $output), array_map('serialize', $json))); + if (0 < count($diff)) { throw new \LogicException("JSON response does not match:\n".print_r($diff, true)); } diff --git a/features/extension.feature b/features/extension.feature index ad60e6d..0aeeb2a 100644 --- a/features/extension.feature +++ b/features/extension.feature @@ -50,6 +50,9 @@ Feature: I can execute Behat tests with current API Extension "name" ] }, + "ean13": { + "type": "any" + }, "name": { "type": [ "string" @@ -146,6 +149,7 @@ Feature: I can execute Behat tests with current API Extension "@type", "id", "company", + "ean13", "name", "active", "price", diff --git a/tests/app/Entity/Beer.php b/tests/app/Entity/Beer.php index 711cf6a..9fc4e1d 100644 --- a/tests/app/Entity/Beer.php +++ b/tests/app/Entity/Beer.php @@ -56,6 +56,14 @@ class Beer */ private $company; + /** + * @var string + * @ORM\Column(type="ean") + * @Groups({"beer_read", "beer_write"}) + * @Assert\NotBlank + */ + private $ean13; + /** * @var string * @ORM\Column @@ -334,4 +342,21 @@ public function setMisc($misc = null) { $this->misc = $misc; } + + /** + * @return string + */ + public function getEan13(): string + { + return $this->ean13; + } + + /** + * @param string $ean13 + */ + public function setEan13(string $ean13) + { + $this->ean13 = $ean13; + } + } diff --git a/tests/app/Kernel.php b/tests/app/Kernel.php index 08b7728..7b18384 100644 --- a/tests/app/Kernel.php +++ b/tests/app/Kernel.php @@ -61,6 +61,12 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'driver' => 'pdo_sqlite', 'path' => '%kernel.cache_dir%/db.sqlite', 'charset' => 'UTF8', + 'mapping_types' => [ + 'ean' => 'string', + ], + 'types' => [ + 'ean' => 'ApiExtension\App\Type\EanType', + ], ], 'orm' => [ 'auto_generate_proxy_classes' => true, diff --git a/tests/app/Populator/Guesser/Ean13Guesser.php b/tests/app/Populator/Guesser/Ean13Guesser.php new file mode 100644 index 0000000..a5c0010 --- /dev/null +++ b/tests/app/Populator/Guesser/Ean13Guesser.php @@ -0,0 +1,24 @@ + + */ +class Ean13Guesser extends AbstractGuesser +{ + public function supports(array $mapping): bool + { + return \in_array($mapping['type'], [EanType::EAN], true); + } + public function getValue(array $mapping): string + { + return $this->faker->ean13; + } +} diff --git a/tests/app/Type/EanType.php b/tests/app/Type/EanType.php new file mode 100644 index 0000000..224758c --- /dev/null +++ b/tests/app/Type/EanType.php @@ -0,0 +1,36 @@ +getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + public function convertToPHPValue($value, AbstractPlatform $platform) + { + return (string) trim($value); + } + + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return (string) trim($value); + } + + public function getName() + { + return self::EAN; + } +} diff --git a/tests/app/behat.yml.dist b/tests/app/behat.yml.dist index c78dc69..e2d742b 100644 --- a/tests/app/behat.yml.dist +++ b/tests/app/behat.yml.dist @@ -23,6 +23,8 @@ default: symfony2: ~ Behatch\Extension: ~ ApiExtension: + guessers: + - ApiExtension\App\Populator\Guesser\Ean13Guesser services: metadataFactory: '@test.api_platform.metadata.resource.metadata_factory.annotation' iriConverter: '@test.api_platform.iri_converter' diff --git a/tests/app/features/bootstrap/FeatureContext.php b/tests/app/features/bootstrap/FeatureContext.php index d77992f..34353ca 100644 --- a/tests/app/features/bootstrap/FeatureContext.php +++ b/tests/app/features/bootstrap/FeatureContext.php @@ -15,7 +15,8 @@ use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\Tools\SchemaTool; - +use Doctrine\DBAL\Types\Type; +use ApiExtension\App\Type\EanType; /** * @author Vincent Chalamon */ @@ -28,6 +29,9 @@ public function __construct(ManagerRegistry $doctrine, string $cacheDir) { $this->doctrine = $doctrine; $this->cacheDir = $cacheDir; + if (!Type::hasType(EanType::EAN)) { + Type::addType('ean', EanType::class); + } } /**