Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Provides a test verifying zf-rest ResourceEvent is present in Doctrin…
Browse files Browse the repository at this point in the history
…eResourceEvent during pre-fetch operations
  • Loading branch information
weierophinney committed Dec 3, 2018
1 parent 9df97b7 commit 20b5070
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/src/Server/ORM/CRUD/CRUDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Tools\SchemaTool;
use PHPUnit\Framework\Assert;
use Zend\Filter\FilterChain;
use Zend\Http\Request;
use Zend\ServiceManager\ServiceManager;
Expand All @@ -21,6 +22,7 @@
use ZF\Apigility\Doctrine\Server\Event\DoctrineResourceEvent;
use ZF\ApiProblem\ApiProblem;
use ZF\ApiProblem\ApiProblemResponse;
use ZF\Rest\ResourceEvent;
use ZFTest\Apigility\Doctrine\TestCase;
use ZFTestApigilityDb\Entity\Album;
use ZFTestApigilityDb\Entity\Artist;
Expand Down Expand Up @@ -261,6 +263,33 @@ public function testFetchByCustomIdField()
]);
}

/**
* @see https://github.com/zfcampus/zf-apigility-doctrine/pull/316
*/
public function testFetchByCustomIdFieldIncludesApigilityResourceEventInDoctrineResourceEvent()
{
$product = $this->createProduct();

$this->getRequest()->getHeaders()->addHeaderLine('Accept', 'application/json');
$this->getRequest()->setMethod(Request::METHOD_GET);

$spy = (object) ['caught' => false];
$sharedEvents = $this->getApplication()->getEventManager()->getSharedManager();
$sharedEvents->attach(
DoctrineResource::class,
DoctrineResourceEvent::EVENT_FETCH_PRE,
function (DoctrineResourceEvent $e) use ($spy) {
Assert::assertInstanceOf(ResourceEvent::class, $e->getResourceEvent());
$spy->caught = true;
}
);

$this->dispatch('/test/rest/product/' . $product->getId());

$this->assertResponseStatusCode(200);
$this->assertTrue($spy->caught, 'EVENT_FETCH_PRE listener was not triggered');
}

public function testFetchEntityWithVersionFieldWithVersionParamInPath()
{
$product = $this->createProduct();
Expand Down

0 comments on commit 20b5070

Please sign in to comment.