Skip to content

Commit

Permalink
laminas-api-tools#28 Removed ODM support, fixed dependencies and PHPU…
Browse files Browse the repository at this point in the history
…nit tests.
  • Loading branch information
tasselchof committed Apr 20, 2022
1 parent 831b12d commit 37a292a
Show file tree
Hide file tree
Showing 7 changed files with 650 additions and 2,486 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"api-skeletons/doctrine-orm-hydration-module": "^1.0"
},
"require-dev": {
"doctrine/doctrine-module": "^4.0 || ^5.1",
"doctrine/doctrine-mongo-odm-module": "^0.11.0 || ^1.0.0 || ^2.0.0",
"doctrine/doctrine-orm-module": "^4.0 || ^5.1",
"doctrine/mongodb-odm": "^1.1.0",
"doctrine/common": "^2.1",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-module": "^5.1",
"doctrine/doctrine-orm-module": "^5.1",
"laminas-api-tools/api-tools-admin": "^1.5.7",
"laminas-api-tools/api-tools-hal": "^1.6.1",
"laminas/laminas-coding-standard": "~2.3.0",
Expand Down
2,585 changes: 625 additions & 1,960 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions test/src/Admin/Model/DoctrineAutodiscoveryModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,4 @@ public function testORMAutodiscoveryEntitiesWithFields(): void
$this->assertEquals('Product', $result[2]['service_name']);
$this->assertCount(1, $result[2]['fields']);
}

public function testODMAutodiscoveryEntitiesWithFields(): void
{
$this->setApplicationConfig(
include __DIR__ . '/../../../config/ODM/application.config.php'
);

$model = new DoctrineAutodiscoveryModel([]);
$model->setServiceLocator($this->getApplicationServiceLocator());

$result = $model->fetchFields(null, null, 'doctrine.documentmanager.odm_default');

$this->assertIsArray($result);
$this->assertCount(1, $result);

$this->assertEquals(Meta::class, $result[0]['entity_class']);
$this->assertEquals('Meta', $result[0]['service_name']);
$this->assertCount(2, $result[0]['fields']);
}
}
22 changes: 15 additions & 7 deletions test/src/Server/Event/Listener/CollectionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Instantiator\InstantiatorInterface;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use Laminas\ApiTools\Doctrine\Server\Event\Listener\CollectionListener;
use Laminas\Hydrator\HydratorInterface;
use LaminasTestApiToolsDb\Entity\Artist;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
use ReflectionMethod;
Expand All @@ -19,19 +21,22 @@ class CollectionListenerTest extends TestCase
{
/**
* @dataProvider trueFalseProvider
*
* @param bool $withEntityFactory
*
* @return void
*/
public function testProcessNewEntity($withEntityFactory)
{
$artist = $this->getMockBuilder(Artist::class)->getMock();
$data = [];
$data = [];

/** @var ObjectManager|PHPUnit_Framework_MockObject_MockObject $om */
$om = $this->getMockBuilder(ObjectManager::class)->getMock();
/** @var EntityManager|MockObject $om */
$om = $this->getMockBuilder(EntityManager::class)
->disableOriginalConstructor()->getMock();
$classMetadata = $this->getMockBuilder(ClassMetadata::class)
->disableOriginalConstructor()
->getMock();
->disableOriginalConstructor()
->getMock();
$classMetadata->expects(self::once())
->method('getIdentifierFieldNames')
->with(Artist::class)
Expand All @@ -53,7 +58,8 @@ public function testProcessNewEntity($withEntityFactory)

if ($withEntityFactory) {
/** @var InstantiatorInterface|PHPUnit_Framework_MockObject_MockObject $entityFactory */
$entityFactory = $this->getMockBuilder(InstantiatorInterface::class)->getMock();
$entityFactory = $this->getMockBuilder(InstantiatorInterface::class)
->getMock();

$entityFactory->expects(self::once())
->method('instantiate')
Expand All @@ -66,7 +72,9 @@ public function testProcessNewEntity($withEntityFactory)
$listener = new CollectionListener($entityFactory);
$listener->setObjectManager($om);

$hydratorMapProperty = new ReflectionProperty($listener, 'entityHydratorMap');
$hydratorMapProperty = new ReflectionProperty(
$listener, 'entityHydratorMap'
);
$hydratorMapProperty->setAccessible(true);
$hydratorMapProperty->setValue($listener, [Artist::class => $hydrator]);

Expand Down
Loading

0 comments on commit 37a292a

Please sign in to comment.