From 2087146db3bb3aa4965ef665173f9d4d80d05091 Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Wed, 24 Jan 2024 15:29:26 +0100 Subject: [PATCH 1/2] Use Jane v8 --- composer.json | 13 +++++++++---- tests/Jane/JaneTest.php | 38 ++++++++++++++------------------------ tests/Jane/jane-config.php | 18 ------------------ tests/SearchTest.php | 2 ++ 4 files changed, 25 insertions(+), 46 deletions(-) delete mode 100644 tests/Jane/jane-config.php diff --git a/composer.json b/composer.json index d425e49..e231159 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,12 @@ "homepage": "https://jolicode.com/" } ], + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/Korbeil/jane-v8" + } + ], "require": { "php": ">=8.0", "ext-json": "*", @@ -22,13 +28,12 @@ "symfony/deprecation-contracts": "^2.4 || ^3.0", "symfony/property-access": "^5.4 || ^6.0", "symfony/property-info": "^5.4 || ^6.0", - "symfony/serializer": "^5.4 || ^6.0", - "symfony/yaml": "^5.4 || ^6.0" + "symfony/serializer": "^7.0", + "symfony/yaml": "^7.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.17.0", - "jane-php/json-schema": "^7.4", - "jane-php/json-schema-runtime": "^7.4", + "jane-php/jane-php": "@dev", "phpstan/phpstan": "^1.9", "symfony/browser-kit": "^5.4 || ^6.0", "symfony/framework-bundle": "^5.4.17 || ^6.0", diff --git a/tests/Jane/JaneTest.php b/tests/Jane/JaneTest.php index 35e4373..8150808 100644 --- a/tests/Jane/JaneTest.php +++ b/tests/Jane/JaneTest.php @@ -13,9 +13,8 @@ namespace JoliCode\Elastically\Tests\Jane; -use Jane\Component\JsonSchema\Console\Command\GenerateCommand; -use Jane\Component\JsonSchema\Console\Loader\ConfigLoader; -use Jane\Component\JsonSchema\Console\Loader\SchemaLoader; +use Jane\Component\JsonSchemaGenerator\Configuration; +use Jane\Component\JsonSchemaGenerator\Generator; use JoliCode\Elastically\Client; use JoliCode\Elastically\IndexBuilder; use JoliCode\Elastically\Indexer; @@ -25,11 +24,9 @@ use JoliCode\Elastically\ResultSetBuilder; use JoliCode\Elastically\Serializer\StaticContextBuilder; use JoliCode\Elastically\Tests\Jane\generated\Model\MyModel; -use JoliCode\Elastically\Tests\Jane\generated\Model\MyModelIngredientsItemAnyOf; -use JoliCode\Elastically\Tests\Jane\generated\Normalizer\JaneObjectNormalizer; +use JoliCode\Elastically\Tests\Jane\generated\Model\MyModelIngredients; +use JoliCode\Elastically\Tests\Jane\generated\Normalizer\JaneNormalizer; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Serializer\Encoder\JsonDecode; use Symfony\Component\Serializer\Encoder\JsonEncode; use Symfony\Component\Serializer\Encoder\JsonEncoder; @@ -41,17 +38,16 @@ class JaneTest extends TestCase public function testCreateIndexAndSearchWithJaneObject() { // Build the models - $command = new GenerateCommand(new ConfigLoader(), new SchemaLoader()); - $inputArray = new ArrayInput([ - '--config-file' => __DIR__ . '/jane-config.php', - ], $command->getDefinition()); - - $command->execute($inputArray, new NullOutput()); + $generator = new Generator(new Configuration( + outputDirectory: __DIR__ . '/generated/', + baseNamespace: 'JoliCode\\Elastically\\Tests\\Jane\\generated', + )); + $generator->fromPath(__DIR__ . '/schema.json', 'MyModel'); // Build the Serializer $normalizers = [ new ArrayDenormalizer(), - new JaneObjectNormalizer(), + new JaneNormalizer(), ]; $encoders = [ new JsonEncoder( @@ -81,16 +77,10 @@ public function testCreateIndexAndSearchWithJaneObject() $indexBuilder->markAsLive($index, 'beers'); // Create a DTO - $dto = new MyModel(); - $dto->setName('La Montreuilloise Smoked Porter'); - $dto->setPrice(3.20); - $ingredient1 = new MyModelIngredientsItemAnyOf(); - $ingredient1->setName('Water'); - $ingredient2 = new MyModelIngredientsItemAnyOf(); - $ingredient2->setName('Malt'); - $ingredient3 = new MyModelIngredientsItemAnyOf(); - $ingredient3->setName('Hops'); - $dto->setIngredients([$ingredient1, $ingredient2, $ingredient3]); + $ingredient1 = new MyModelIngredients('Water'); + $ingredient2 = new MyModelIngredients('Malt'); + $ingredient3 = new MyModelIngredients('Hops'); + $dto = new MyModel('La Montreuilloise Smoked Porter', 3.20, [$ingredient1, $ingredient2, $ingredient3]); // Index the DTO $indexer->scheduleIndex('beers', new Document('123', $dto)); diff --git a/tests/Jane/jane-config.php b/tests/Jane/jane-config.php deleted file mode 100644 index f77407b..0000000 --- a/tests/Jane/jane-config.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'json-schema-file' => __DIR__ . '/schema.json', - 'root-class' => 'MyModel', - 'namespace' => 'JoliCode\Elastically\Tests\Jane\generated', - 'directory' => __DIR__ . '/generated', - 'clean-generated' => false, -]; diff --git a/tests/SearchTest.php b/tests/SearchTest.php index bdaba10..ac4ad52 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -134,6 +134,8 @@ public function supportsDenormalization($data, $type, $format = null, array $con public function serialize(mixed $data, string $format, array $context = []): string {} public function deserialize(mixed $data, string $type, string $format, array $context = []): mixed {} + + public function getSupportedTypes(?string $format): array {} } class SearchTestDto From e33bd81590c1ab6f60354429248fc5cb4fd23039 Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Wed, 24 Jan 2024 15:45:54 +0100 Subject: [PATCH 2/2] CI