Skip to content
This repository was archived by the owner on Jun 8, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 4 additions & 0 deletions features/extension.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Feature: I can execute Behat tests with current API Extension
"name"
]
},
"ean13": {
"type": "any"
},
"name": {
"type": [
"string"
Expand Down Expand Up @@ -146,6 +149,7 @@ Feature: I can execute Behat tests with current API Extension
"@type",
"id",
"company",
"ean13",
"name",
"active",
"price",
Expand Down
25 changes: 25 additions & 0 deletions tests/app/Entity/Beer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}
6 changes: 6 additions & 0 deletions tests/app/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions tests/app/Populator/Guesser/Ean13Guesser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace ApiExtension\App\Populator\Guesser;

use Doctrine\DBAL\Types\Type;
use ApiExtension\App\Type\EanType;
use ApiExtension\Populator\Guesser\AbstractGuesser;

/**
* @author Mathieu Dewet <mathieu.dewet@gmail.com>
*/
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;
}
}
36 changes: 36 additions & 0 deletions tests/app/Type/EanType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace ApiExtension\App\Type;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
* My custom ean type.
*/
class EanType extends Type
{
const EAN = 'ean';

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$fieldDeclaration['length'] = 13;

return $platform->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;
}
}
2 changes: 2 additions & 0 deletions tests/app/behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion tests/app/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vincentchalamon@gmail.com>
*/
Expand All @@ -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);
}
}

/**
Expand Down