From 354c82846b86ca6484e247f6abe0c7d00184dbef Mon Sep 17 00:00:00 2001 From: zairigimad Date: Sat, 24 Oct 2020 22:06:30 +0200 Subject: [PATCH 1/4] Create DataPersister Maker --- src/Maker/MakeDataPersister.php | 74 +++++++++++++++++++ src/Resources/config/makers.xml | 4 + src/Resources/help/MakeDataPersister.txt | 5 ++ .../skeleton/api/DataPersister.tpl.php | 25 +++++++ tests/Maker/MakeDataPersisterTest.php | 32 ++++++++ 5 files changed, 140 insertions(+) create mode 100644 src/Maker/MakeDataPersister.php create mode 100644 src/Resources/help/MakeDataPersister.txt create mode 100644 src/Resources/skeleton/api/DataPersister.tpl.php create mode 100644 tests/Maker/MakeDataPersisterTest.php diff --git a/src/Maker/MakeDataPersister.php b/src/Maker/MakeDataPersister.php new file mode 100644 index 000000000..c4c0d719d --- /dev/null +++ b/src/Maker/MakeDataPersister.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MakerBundle\Maker; + +use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; +use Symfony\Bundle\MakerBundle\ConsoleStyle; +use Symfony\Bundle\MakerBundle\DependencyBuilder; +use Symfony\Bundle\MakerBundle\Generator; +use Symfony\Bundle\MakerBundle\InputConfiguration; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; + +/** + * @author Imad ZAIRIG + * + * @internal + */ +final class MakeDataPersister extends AbstractMaker +{ + public static function getCommandName(): string + { + return 'make:api:data-persister'; + } + + public function configureCommand(Command $command, InputConfiguration $inputConfig) + { + $command + ->setDescription('Creates a API Platform Data Persister') + ->addArgument('name', InputArgument::OPTIONAL, 'The name of the Data Persister class (e.g. CustomDataPersister)') + ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeDataPersister.txt')); + } + + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) + { + $dataPersisterClassNameDetails = $generator->createClassNameDetails( + $input->getArgument('name'), + 'DataPersister\\', + 'DataPersister' + ); + + $generator->generateClass( + $dataPersisterClassNameDetails->getFullName(), + 'api/DataPersister.tpl.php' + ); + + $generator->writeChanges(); + + $this->writeSuccessMessage($io); + + $io->text([ + 'Next:', + sprintf('- Open the %s class and add the code you need', $dataPersisterClassNameDetails->getFullName()), + 'Find the documentation at https://api-platform.com/docs/core/data-persisters/#creating-a-custom-data-persister', + ]); + } + + public function configureDependencies(DependencyBuilder $dependencies) + { + $dependencies->addClassDependency( + ContextAwareDataPersisterInterface::class, + 'api' + ); + } +} diff --git a/src/Resources/config/makers.xml b/src/Resources/config/makers.xml index e17b72538..1c8b2185e 100644 --- a/src/Resources/config/makers.xml +++ b/src/Resources/config/makers.xml @@ -123,5 +123,9 @@ %kernel.project_dir% + + + + diff --git a/src/Resources/help/MakeDataPersister.txt b/src/Resources/help/MakeDataPersister.txt new file mode 100644 index 000000000..d7f066299 --- /dev/null +++ b/src/Resources/help/MakeDataPersister.txt @@ -0,0 +1,5 @@ +The %command.name% command generates a new Data Persister class. + +php %command.full_name% CustomDataPersister + +If the argument is missing, the command will ask for the message class interactively. \ No newline at end of file diff --git a/src/Resources/skeleton/api/DataPersister.tpl.php b/src/Resources/skeleton/api/DataPersister.tpl.php new file mode 100644 index 000000000..60bc543af --- /dev/null +++ b/src/Resources/skeleton/api/DataPersister.tpl.php @@ -0,0 +1,25 @@ + + +namespace ; + +use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; + +final class implements ContextAwareDataPersisterInterface +{ + public function supports($data, array $context = []): bool + { + // implement your logic to check whether the given data is supported by this data persister + return true; + } + + public function persist($data, array $context = []) + { + // call your persistence layer to save $data + return $data; + } + + public function remove($data, array $context = []) + { + // call your persistence layer to delete $data + } +} diff --git a/tests/Maker/MakeDataPersisterTest.php b/tests/Maker/MakeDataPersisterTest.php new file mode 100644 index 000000000..d477ac3d8 --- /dev/null +++ b/tests/Maker/MakeDataPersisterTest.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MakerBundle\Tests\Maker; + +use Symfony\Bundle\MakerBundle\Maker\MakeDataPersister; +use Symfony\Bundle\MakerBundle\Test\MakerTestCase; +use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; + +class MakeDataPersisterTest extends MakerTestCase +{ + public function getTestDetails() + { + yield 'api_data_persister' => [MakerTestDetails::createTest( + $this->getMakerInstance(MakeDataPersister::class), + [ + // data persister name + 'CustomDataPersister', + ])->assert(function (string $output, string $directory) { + $this->assertFileExists($directory.'/src/DataPersister/CustomDataPersister.php'); + }), + ]; + } +} From f7409ab5647e6da6640234b93a13713560af7496 Mon Sep 17 00:00:00 2001 From: zairigimad Date: Thu, 29 Oct 2020 20:30:35 +0100 Subject: [PATCH 2/4] Add Question to ask for resource --- src/Maker/MakeDataPersister.php | 57 ++++++++++++++++++- src/Resources/config/makers.xml | 2 + .../skeleton/api/DataPersister.tpl.php | 11 ++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/Maker/MakeDataPersister.php b/src/Maker/MakeDataPersister.php index c4c0d719d..3aa467c4f 100644 --- a/src/Maker/MakeDataPersister.php +++ b/src/Maker/MakeDataPersister.php @@ -12,6 +12,8 @@ namespace Symfony\Bundle\MakerBundle\Maker; use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; +use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; +use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; use Symfony\Bundle\MakerBundle\Generator; @@ -19,6 +21,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Question\Question; /** * @author Imad ZAIRIG @@ -27,6 +30,17 @@ */ final class MakeDataPersister extends AbstractMaker { + protected $ressourceNameCollectionFactory; + protected $ressourceMetaDataFactory; + + public function __construct( + ResourceNameCollectionFactoryInterface $ressourceNameCollectionFactory, + ResourceMetadataFactoryInterface $ressourceMetaDataFactory + ) { + $this->ressourceNameCollection = $ressourceNameCollectionFactory; + $this->ressourceMetaDataFactory = $ressourceMetaDataFactory; + } + public static function getCommandName(): string { return 'make:api:data-persister'; @@ -37,11 +51,31 @@ public function configureCommand(Command $command, InputConfiguration $inputConf $command ->setDescription('Creates a API Platform Data Persister') ->addArgument('name', InputArgument::OPTIONAL, 'The name of the Data Persister class (e.g. CustomDataPersister)') + ->addArgument('resource', InputArgument::OPTIONAL, 'The name of the resource class') ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeDataPersister.txt')); } + public function interact(InputInterface $input, ConsoleStyle $io, Command $command) + { + if (null === $input->getArgument('resource')) { + $argument = $command->getDefinition()->getArgument('resource'); + $question = $this->createResourceClassQuestion($argument->getDescription()); + $value = $io->askQuestion($question); + $input->setArgument('resource', $value); + } + } + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) { + $resourcesClassNames = array_flip($this->getResources()); + $resourceShortName = $input->getArgument('resource'); + $templateVariables = []; + + if ($resourceShortName) { + $templateVariables['resource_short_name'] = $resourceShortName; + $templateVariables['resource_class_name'] = $resourcesClassNames[$resourceShortName]; + } + $dataPersisterClassNameDetails = $generator->createClassNameDetails( $input->getArgument('name'), 'DataPersister\\', @@ -50,7 +84,8 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $generator->generateClass( $dataPersisterClassNameDetails->getFullName(), - 'api/DataPersister.tpl.php' + 'api/DataPersister.tpl.php', + $templateVariables ); $generator->writeChanges(); @@ -71,4 +106,24 @@ public function configureDependencies(DependencyBuilder $dependencies) 'api' ); } + + private function createResourceClassQuestion(string $questionText): Question + { + $question = new Question($questionText); + $question->setAutocompleterValues(array_values($this->getResources())); + + return $question; + } + + private function getResources(): array + { + $collection = $this->ressourceNameCollection->create(); + $resources = []; + + foreach ($collection as $className) { + $resources[$className] = $this->ressourceMetaDataFactory->create($className)->getShortName(); + } + + return $resources; + } } diff --git a/src/Resources/config/makers.xml b/src/Resources/config/makers.xml index 1c8b2185e..dcaf11f82 100644 --- a/src/Resources/config/makers.xml +++ b/src/Resources/config/makers.xml @@ -125,6 +125,8 @@ + + diff --git a/src/Resources/skeleton/api/DataPersister.tpl.php b/src/Resources/skeleton/api/DataPersister.tpl.php index 60bc543af..b091b1e5c 100644 --- a/src/Resources/skeleton/api/DataPersister.tpl.php +++ b/src/Resources/skeleton/api/DataPersister.tpl.php @@ -3,23 +3,24 @@ namespace ; use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; + final class implements ContextAwareDataPersisterInterface { public function supports($data, array $context = []): bool { // implement your logic to check whether the given data is supported by this data persister - return true; + } public function persist($data, array $context = []) { - // call your persistence layer to save $data - return $data; + // call your persistence layer to save $data + return $data; } public function remove($data, array $context = []) { - // call your persistence layer to delete $data + // call your persistence layer to delete $data } -} +} \ No newline at end of file From 424b74928a84eeefc1ee96a41bac801adb49c16c Mon Sep 17 00:00:00 2001 From: zairigimad Date: Fri, 30 Oct 2020 14:47:03 +0100 Subject: [PATCH 3/4] Add Check if Entity to Inject Doctrine Persister, and fix tests --- src/Maker/MakeDataPersister.php | 37 ++++++++++++++++--- src/Resources/config/makers.xml | 5 ++- .../skeleton/api/DataPersister.tpl.php | 19 +++++++--- tests/Maker/MakeDataPersisterTest.php | 1 + 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/Maker/MakeDataPersister.php b/src/Maker/MakeDataPersister.php index 3aa467c4f..287ac97d2 100644 --- a/src/Maker/MakeDataPersister.php +++ b/src/Maker/MakeDataPersister.php @@ -16,11 +16,14 @@ use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; +use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper; use Symfony\Bundle\MakerBundle\Generator; use Symfony\Bundle\MakerBundle\InputConfiguration; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\Question; /** @@ -30,13 +33,18 @@ */ final class MakeDataPersister extends AbstractMaker { + /** @var ResourceNameCollectionFactoryInterface */ protected $ressourceNameCollectionFactory; + /** @var ResourceMetadataFactoryInterface */ protected $ressourceMetaDataFactory; + protected $resourcesClassNames = []; public function __construct( - ResourceNameCollectionFactoryInterface $ressourceNameCollectionFactory, - ResourceMetadataFactoryInterface $ressourceMetaDataFactory + DoctrineHelper $doctrineHelper, + $ressourceNameCollectionFactory = null, + $ressourceMetaDataFactory = null ) { + $this->doctrineHelper = $doctrineHelper; $this->ressourceNameCollection = $ressourceNameCollectionFactory; $this->ressourceMetaDataFactory = $ressourceMetaDataFactory; } @@ -53,6 +61,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf ->addArgument('name', InputArgument::OPTIONAL, 'The name of the Data Persister class (e.g. CustomDataPersister)') ->addArgument('resource', InputArgument::OPTIONAL, 'The name of the resource class') ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeDataPersister.txt')); + $inputConfig->setArgumentAsNonInteractive('resource'); } public function interact(InputInterface $input, ConsoleStyle $io, Command $command) @@ -62,18 +71,34 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $question = $this->createResourceClassQuestion($argument->getDescription()); $value = $io->askQuestion($question); $input->setArgument('resource', $value); + $doctrineOption = new InputOption('is_doctrine_persister', 'a', InputOption::VALUE_NONE, 'Would you like your persister to call the core Doctrine persister?'); + $command->getDefinition()->addOption($doctrineOption); + + if (\in_array($value, $this->resourcesClassNames) && $this->doctrineHelper->isClassAMappedEntity($this->resourcesClassNames[$value])) { + $description = $command->getDefinition()->getOption('is_doctrine_persister')->getDescription(); + $question = new ConfirmationQuestion($description, false); + $value = $io->askQuestion($question); + + $input->setOption('is_doctrine_persister', $value); + } } } public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) { - $resourcesClassNames = array_flip($this->getResources()); - $resourceShortName = $input->getArgument('resource'); $templateVariables = []; + $resourceShortName = $input->getArgument('resource'); + $this->resourcesClassNames = array_flip($this->getResources()); - if ($resourceShortName) { + if ($resourceShortName && \in_array($resourceShortName, $this->resourcesClassNames)) { + $resourceClasseName = $this->resourcesClassNames[$resourceShortName]; $templateVariables['resource_short_name'] = $resourceShortName; - $templateVariables['resource_class_name'] = $resourcesClassNames[$resourceShortName]; + $templateVariables['resource_class_name'] = $resourceClasseName; + } + + if ($input->hasOption('is_doctrine_persister')) { + $templateVariables['is_doctrine_persister'] = true; + //configure the service } $dataPersisterClassNameDetails = $generator->createClassNameDetails( diff --git a/src/Resources/config/makers.xml b/src/Resources/config/makers.xml index dcaf11f82..92b6a75af 100644 --- a/src/Resources/config/makers.xml +++ b/src/Resources/config/makers.xml @@ -125,8 +125,9 @@ - - + + + diff --git a/src/Resources/skeleton/api/DataPersister.tpl.php b/src/Resources/skeleton/api/DataPersister.tpl.php index b091b1e5c..0be6f1298 100644 --- a/src/Resources/skeleton/api/DataPersister.tpl.php +++ b/src/Resources/skeleton/api/DataPersister.tpl.php @@ -7,20 +7,29 @@ final class implements ContextAwareDataPersisterInterface { + + private $decorated; + + public function __construct(ContextAwareDataPersisterInterface $decorated) + { + $this->decorated = $decorated; + } + + public function supports($data, array $context = []): bool { // implement your logic to check whether the given data is supported by this data persister - + } public function persist($data, array $context = []) { - // call your persistence layer to save $data - return $data; + // call your persistence layer to save $data + return $data; } public function remove($data, array $context = []) { - // call your persistence layer to delete $data + // call your persistence layer to delete $data } -} \ No newline at end of file +} diff --git a/tests/Maker/MakeDataPersisterTest.php b/tests/Maker/MakeDataPersisterTest.php index d477ac3d8..f85955019 100644 --- a/tests/Maker/MakeDataPersisterTest.php +++ b/tests/Maker/MakeDataPersisterTest.php @@ -24,6 +24,7 @@ public function getTestDetails() [ // data persister name 'CustomDataPersister', + ' ', ])->assert(function (string $output, string $directory) { $this->assertFileExists($directory.'/src/DataPersister/CustomDataPersister.php'); }), From 221a17e376d0481654f5c65dff6fbc295e161183 Mon Sep 17 00:00:00 2001 From: zairigimad Date: Fri, 30 Oct 2020 21:19:40 +0100 Subject: [PATCH 4/4] Add Service Declaration with decorator --- src/Maker/MakeDataPersister.php | 28 ++++++++++--- src/Resources/config/makers.xml | 1 + .../skeleton/api/DataPersister.tpl.php | 18 ++++++-- tests/Maker/MakeDataPersisterTest.php | 34 +++++++++++++++ .../fixtures/MakeDataPersister/Model/Book.php | 32 ++++++++++++++ .../MakeDataPersister/src/Entity/Article.php | 42 +++++++++++++++++++ 6 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 tests/fixtures/MakeDataPersister/Model/Book.php create mode 100644 tests/fixtures/MakeDataPersister/src/Entity/Article.php diff --git a/src/Maker/MakeDataPersister.php b/src/Maker/MakeDataPersister.php index 287ac97d2..2e730f04c 100644 --- a/src/Maker/MakeDataPersister.php +++ b/src/Maker/MakeDataPersister.php @@ -17,8 +17,11 @@ use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper; +use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; +use Symfony\Bundle\MakerBundle\FileManager; use Symfony\Bundle\MakerBundle\Generator; use Symfony\Bundle\MakerBundle\InputConfiguration; +use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -37,13 +40,17 @@ final class MakeDataPersister extends AbstractMaker protected $ressourceNameCollectionFactory; /** @var ResourceMetadataFactoryInterface */ protected $ressourceMetaDataFactory; + protected $fileManager; + protected $doctrineHelper; protected $resourcesClassNames = []; public function __construct( + FileManager $fileManager, DoctrineHelper $doctrineHelper, $ressourceNameCollectionFactory = null, $ressourceMetaDataFactory = null ) { + $this->fileManager = $fileManager; $this->doctrineHelper = $doctrineHelper; $this->ressourceNameCollection = $ressourceNameCollectionFactory; $this->ressourceMetaDataFactory = $ressourceMetaDataFactory; @@ -73,8 +80,9 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $input->setArgument('resource', $value); $doctrineOption = new InputOption('is_doctrine_persister', 'a', InputOption::VALUE_NONE, 'Would you like your persister to call the core Doctrine persister?'); $command->getDefinition()->addOption($doctrineOption); + $this->resourcesClassNames = array_flip($this->getResources()); - if (\in_array($value, $this->resourcesClassNames) && $this->doctrineHelper->isClassAMappedEntity($this->resourcesClassNames[$value])) { + if (\in_array($value, $this->getResources()) && $this->doctrineHelper->isClassAMappedEntity($this->resourcesClassNames[$value])) { $description = $command->getDefinition()->getOption('is_doctrine_persister')->getDescription(); $question = new ConfirmationQuestion($description, false); $value = $io->askQuestion($question); @@ -96,17 +104,25 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $templateVariables['resource_class_name'] = $resourceClasseName; } - if ($input->hasOption('is_doctrine_persister')) { - $templateVariables['is_doctrine_persister'] = true; - //configure the service - } - $dataPersisterClassNameDetails = $generator->createClassNameDetails( $input->getArgument('name'), 'DataPersister\\', 'DataPersister' ); + if ($input->getOption('is_doctrine_persister')) { + $templateVariables['is_doctrine_persister'] = true; + if (!$this->fileManager->fileExists($path = 'config/services.yaml')) { + throw new RuntimeCommandException('The file "config/packages/security.yaml" does not exist. This command requires that file to exist so that it can be updated.'); + } + $manipulator = new YamlSourceManipulator($this->fileManager->getFileContents($path)); + + $servicesData = $manipulator->getData(); + $servicesData['services'] = [$dataPersisterClassNameDetails->getFullName() => ['decorates' => 'api_platform.doctrine.orm.data_persister']] + $servicesData['services']; + $manipulator->setData($servicesData); + $this->fileManager->dumpFile($path, $manipulator->getContents()); + } + $generator->generateClass( $dataPersisterClassNameDetails->getFullName(), 'api/DataPersister.tpl.php', diff --git a/src/Resources/config/makers.xml b/src/Resources/config/makers.xml index 92b6a75af..b6638e81e 100644 --- a/src/Resources/config/makers.xml +++ b/src/Resources/config/makers.xml @@ -125,6 +125,7 @@ + diff --git a/src/Resources/skeleton/api/DataPersister.tpl.php b/src/Resources/skeleton/api/DataPersister.tpl.php index 0be6f1298..d4de54e45 100644 --- a/src/Resources/skeleton/api/DataPersister.tpl.php +++ b/src/Resources/skeleton/api/DataPersister.tpl.php @@ -18,18 +18,28 @@ public function __construct(ContextAwareDataPersisterInterface $decorated) public function supports($data, array $context = []): bool { - // implement your logic to check whether the given data is supported by this data persister - + + return $this->decorated->supports($data, $context); + + return $data instanceof ; + + return true; + } public function persist($data, array $context = []) { - // call your persistence layer to save $data + + $data = $this->decorated->persist($data, $context); + + return $data; } public function remove($data, array $context = []) { - // call your persistence layer to delete $data + + return $this->decorated->persist($data, $context); + } } diff --git a/tests/Maker/MakeDataPersisterTest.php b/tests/Maker/MakeDataPersisterTest.php index f85955019..26fc35a38 100644 --- a/tests/Maker/MakeDataPersisterTest.php +++ b/tests/Maker/MakeDataPersisterTest.php @@ -29,5 +29,39 @@ public function getTestDetails() $this->assertFileExists($directory.'/src/DataPersister/CustomDataPersister.php'); }), ]; + yield 'entity_with_doctrine_persister' => [MakerTestDetails::createTest( + $this->getMakerInstance(MakeDataPersister::class), + [ + 'ArticleDataPersister', + 'Article', + 'yes', + ]) + ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeDataPersister') + ->assert(function (string $output, string $directory) { + $this->assertFileExists($directory.'/src/DataPersister/ArticleDataPersister.php'); + }), + ]; + yield 'entity_without_doctrine_persister' => [MakerTestDetails::createTest( + $this->getMakerInstance(MakeDataPersister::class), + [ + 'ArticleBlogDataPersister', + 'Article', + ]) + ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeDataPersister') + ->assert(function (string $output, string $directory) { + $this->assertFileExists($directory.'/src/DataPersister/ArticleBlogDataPersister.php'); + }), + ]; + yield 'model_class_persister' => [MakerTestDetails::createTest( + $this->getMakerInstance(MakeDataPersister::class), + [ + 'BookDataPersister', + 'Book', + ]) + ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeDataPersister') + ->assert(function (string $output, string $directory) { + $this->assertFileExists($directory.'/src/DataPersister/BookDataPersister.php'); + }), + ]; } } diff --git a/tests/fixtures/MakeDataPersister/Model/Book.php b/tests/fixtures/MakeDataPersister/Model/Book.php new file mode 100644 index 000000000..bbf4263f0 --- /dev/null +++ b/tests/fixtures/MakeDataPersister/Model/Book.php @@ -0,0 +1,32 @@ +id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } +} diff --git a/tests/fixtures/MakeDataPersister/src/Entity/Article.php b/tests/fixtures/MakeDataPersister/src/Entity/Article.php new file mode 100644 index 000000000..a32fa07f3 --- /dev/null +++ b/tests/fixtures/MakeDataPersister/src/Entity/Article.php @@ -0,0 +1,42 @@ +id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): self + { + $this->title = $title; + + return $this; + } +}