Skip to content

Commit

Permalink
PD-13 Setup codeception and add test for events. (#3)
Browse files Browse the repository at this point in the history
* PD-105 Setup codeception and add test for events.

* Apply php-cs-fixer changes
  • Loading branch information
martineiber authored Jan 24, 2024
1 parent 0aed427 commit 086e1f0
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 43 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ services:
environment:
PHP_IDE_CONFIG: serverName=localhost
volumes:
- .:/var/cli/
- .:/var/cli/
- ./.docker/30-xdebug.ini:/usr/local/etc/php/conf.d/30-xdebug.ini
8 changes: 4 additions & 4 deletions src/Event/DataObject/ExtractMappingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/Event/Asset/ExtractMappingEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Tests\Unit\Event\Asset;

use Codeception\Test\Unit;
use Pimcore\Bundle\GenericDataIndexBundle\Event\Asset\ExtractMappingEvent;

class ExtractMappingEventTest extends Unit
{
public function testGetCustomFieldsMapping(): void
{
$event = new ExtractMappingEvent(['test']);
$this->assertSame(['test'], $event->getCustomFieldsMapping());
}

public function testSetCustomFieldsMapping(): void
{
$event = new ExtractMappingEvent(['test']);
$event->setCustomFieldsMapping(['test2']);
$this->assertSame(['test2'], $event->getCustomFieldsMapping());
}
}
43 changes: 43 additions & 0 deletions tests/Unit/Event/Asset/UpdateIndexDataEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Tests\Unit\Event\Asset;

use Codeception\Test\Unit;
use Pimcore\Bundle\GenericDataIndexBundle\Event\Asset\UpdateIndexDataEvent;
use Pimcore\Model\Asset;

class UpdateIndexDataEventTest extends Unit
{
public function testGetElement(): void
{
$assetMock = $this->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());
}
}
43 changes: 43 additions & 0 deletions tests/Unit/Event/DataObject/ExtractMappingEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Tests\Unit\Event\DataObject;

use Codeception\Test\Unit;
use Pimcore\Bundle\GenericDataIndexBundle\Event\DataObject\ExtractMappingEvent;
use Pimcore\Model\DataObject\ClassDefinitionInterface;

class ExtractMappingEventTest extends Unit
{
public function testGetCustomFieldsMapping(): void
{
$classDefinition = $this->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());
}
}
43 changes: 43 additions & 0 deletions tests/Unit/Event/DataObject/UpdateIndexDataEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Tests\Unit\Event\DataObject;

use Codeception\Test\Unit;
use Pimcore\Bundle\GenericDataIndexBundle\Event\DataObject\UpdateIndexDataEvent;
use Pimcore\Model\DataObject\Concrete;

class UpdateIndexDataEventTest extends Unit
{
public function testGetElement(): void
{
$assetMock = $this->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());
}
}
38 changes: 0 additions & 38 deletions tests/Unit/Service/DataObject/SelectOptionsServiceTest.php

This file was deleted.

0 comments on commit 086e1f0

Please sign in to comment.