From 086e1f09a426784bb7c333c29dc259f88cf413b6 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Wed, 24 Jan 2024 15:39:51 +0100 Subject: [PATCH] PD-13 Setup codeception and add test for events. (#3) * PD-105 Setup codeception and add test for events. * Apply php-cs-fixer changes --- docker-compose.yml | 3 +- src/Event/DataObject/ExtractMappingEvent.php | 8 ++-- .../Event/Asset/ExtractMappingEventTest.php | 33 ++++++++++++++ .../Event/Asset/UpdateIndexDataEventTest.php | 43 +++++++++++++++++++ .../DataObject/ExtractMappingEventTest.php | 43 +++++++++++++++++++ .../DataObject/UpdateIndexDataEventTest.php | 43 +++++++++++++++++++ .../DataObject/SelectOptionsServiceTest.php | 38 ---------------- 7 files changed, 168 insertions(+), 43 deletions(-) create mode 100644 tests/Unit/Event/Asset/ExtractMappingEventTest.php create mode 100644 tests/Unit/Event/Asset/UpdateIndexDataEventTest.php create mode 100644 tests/Unit/Event/DataObject/ExtractMappingEventTest.php create mode 100644 tests/Unit/Event/DataObject/UpdateIndexDataEventTest.php delete mode 100644 tests/Unit/Service/DataObject/SelectOptionsServiceTest.php diff --git a/docker-compose.yml b/docker-compose.yml index 58320e0a..00e86656 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,5 @@ services: environment: PHP_IDE_CONFIG: serverName=localhost volumes: - - .:/var/cli/ \ No newline at end of file + - .:/var/cli/ + - ./.docker/30-xdebug.ini:/usr/local/etc/php/conf.d/30-xdebug.ini \ No newline at end of file diff --git a/src/Event/DataObject/ExtractMappingEvent.php b/src/Event/DataObject/ExtractMappingEvent.php index 6cd86b4f..e3373e31 100644 --- a/src/Event/DataObject/ExtractMappingEvent.php +++ b/src/Event/DataObject/ExtractMappingEvent.php @@ -13,7 +13,7 @@ namespace Pimcore\Bundle\GenericDataIndexBundle\Event\DataObject; -use Pimcore\Model\DataObject\ClassDefinition; +use Pimcore\Model\DataObject\ClassDefinitionInterface; use Symfony\Contracts\EventDispatcher\Event; /** @@ -23,17 +23,17 @@ */ final class ExtractMappingEvent extends Event { - protected ClassDefinition $classDefinition; + protected ClassDefinitionInterface $classDefinition; protected array $customFieldsMapping; - public function __construct(ClassDefinition $classDefinition, array $customFieldsMapping) + public function __construct(ClassDefinitionInterface $classDefinition, array $customFieldsMapping) { $this->classDefinition = $classDefinition; $this->customFieldsMapping = $customFieldsMapping; } - public function getClassDefinition(): ClassDefinition + public function getClassDefinition(): ClassDefinitionInterface { return $this->classDefinition; } diff --git a/tests/Unit/Event/Asset/ExtractMappingEventTest.php b/tests/Unit/Event/Asset/ExtractMappingEventTest.php new file mode 100644 index 00000000..e45b2525 --- /dev/null +++ b/tests/Unit/Event/Asset/ExtractMappingEventTest.php @@ -0,0 +1,33 @@ +assertSame(['test'], $event->getCustomFieldsMapping()); + } + + public function testSetCustomFieldsMapping(): void + { + $event = new ExtractMappingEvent(['test']); + $event->setCustomFieldsMapping(['test2']); + $this->assertSame(['test2'], $event->getCustomFieldsMapping()); + } +} diff --git a/tests/Unit/Event/Asset/UpdateIndexDataEventTest.php b/tests/Unit/Event/Asset/UpdateIndexDataEventTest.php new file mode 100644 index 00000000..19f1a6b7 --- /dev/null +++ b/tests/Unit/Event/Asset/UpdateIndexDataEventTest.php @@ -0,0 +1,43 @@ +createMock(Asset::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $this->assertEquals($assetMock, $event->getElement()); + } + + public function testGetCustomFields(): void + { + $assetMock = $this->createMock(Asset::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $this->assertEquals(['test' => 'test'], $event->getCustomFields()); + } + + public function testSetCustomFields(): void + { + $assetMock = $this->createMock(Asset::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $event->setCustomFields(['test2' => 'test2']); + $this->assertEquals(['test2' => 'test2'], $event->getCustomFields()); + } +} diff --git a/tests/Unit/Event/DataObject/ExtractMappingEventTest.php b/tests/Unit/Event/DataObject/ExtractMappingEventTest.php new file mode 100644 index 00000000..b51662fd --- /dev/null +++ b/tests/Unit/Event/DataObject/ExtractMappingEventTest.php @@ -0,0 +1,43 @@ +createMock(ClassDefinitionInterface::class); + $event = new ExtractMappingEvent($classDefinition, ['test']); + $this->assertSame(['test'], $event->getCustomFieldsMapping()); + } + + public function testSetCustomFieldsMapping(): void + { + $classDefinition = $this->createMock(ClassDefinitionInterface::class); + $event = new ExtractMappingEvent($classDefinition, ['test']); + $event->setCustomFieldsMapping(['test2']); + $this->assertSame(['test2'], $event->getCustomFieldsMapping()); + } + + public function testGetClassDefinition(): void + { + $classDefinition = $this->createMock(ClassDefinitionInterface::class); + $event = new ExtractMappingEvent($classDefinition, ['test']); + $this->assertSame($classDefinition, $event->getClassDefinition()); + } +} diff --git a/tests/Unit/Event/DataObject/UpdateIndexDataEventTest.php b/tests/Unit/Event/DataObject/UpdateIndexDataEventTest.php new file mode 100644 index 00000000..442a5dfc --- /dev/null +++ b/tests/Unit/Event/DataObject/UpdateIndexDataEventTest.php @@ -0,0 +1,43 @@ +createMock(Concrete::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $this->assertEquals($assetMock, $event->getElement()); + } + + public function testGetCustomFields(): void + { + $assetMock = $this->createMock(Concrete::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $this->assertEquals(['test' => 'test'], $event->getCustomFields()); + } + + public function testSetCustomFields(): void + { + $assetMock = $this->createMock(Concrete::class); + $event = new UpdateIndexDataEvent($assetMock, ['test' => 'test']); + $event->setCustomFields(['test2' => 'test2']); + $this->assertEquals(['test2' => 'test2'], $event->getCustomFields()); + } +} diff --git a/tests/Unit/Service/DataObject/SelectOptionsServiceTest.php b/tests/Unit/Service/DataObject/SelectOptionsServiceTest.php deleted file mode 100644 index 692e047f..00000000 --- a/tests/Unit/Service/DataObject/SelectOptionsServiceTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 'key1', - 'value' => 'value1', - ], - [ - 'key' => 'key2', - 'value' => 'value2', - ], - ]; - - $service = new SelectOptionsService(); - $key = SelectOptionsService::getKeyByValue('value1', $options); - static::assertEquals('key1', $key); - } -}