Ejemplo n.º 1
0
 /**
  * @group 7
  */
 public function testDispatchEvent()
 {
     $queryParams = new Parameters(['foo' => 'bar']);
     $event = new ResourceEvent();
     $event->setName('fetchAll');
     $event->setQueryParams($queryParams);
     //        $event->setParam('user_id', 1);
     $event->setRouteMatch(new RouteMatch(['user_id' => 1]));
     $result = $this->listener->dispatch($event);
     $this->assertInstanceOf(ResultSet::class, $result);
 }
 /**
  * @depends testFetch
  */
 public function testGetResource()
 {
     $this->imgManMock = $this->getMockBuilder('ImgMan\\Service\\ImageService')->disableOriginalConstructor()->getMock();
     $resource = new ImgManConnectedResource($this->imgManMock);
     $this->assertNull($resource->getResource());
     $this->imgManMock = $this->getMockBuilder('ImgMan\\Service\\ImageService')->disableOriginalConstructor()->setMethods(['has', 'get', 'getSrc'])->getMock();
     $this->imgManMock->expects($this->any())->method('has')->with($this->equalTo('testId'), $this->equalTo(CoreInterface::RENDITION_ORIGINAL))->will($this->returnValue(true));
     $this->imgManMock->expects($this->any())->method('getSrc')->with($this->equalTo('testId'), $this->equalTo(CoreInterface::RENDITION_ORIGINAL))->will($this->returnValue(null));
     $this->imgManMock->expects($this->any())->method('get')->with($this->equalTo('testId'))->will($this->returnValue($this->getMock('ImgManTest\\Apigility\\Asset\\TestImage')));
     $resource = new ImgManConnectedResource($this->imgManMock);
     $event = new ResourceEvent();
     $event->setTarget(new Resource());
     $event->setName('fetch');
     $event->setParam('id', 'testId');
     $event->setRequest(new Request());
     $resource->setEntityClass('ImgManTest\\Apigility\\Asset\\TestImage');
     $resource->dispatch($event);
     $this->assertInstanceOf('ZF\\Rest\\ResourceInterface', $resource->getResource());
 }
 /**
  * @group 7
  */
 public function testDispatchShouldPassWhitelistedQueryParamsToFetchAllMethod()
 {
     $queryParams = new Parameters(array('foo' => 'bar'));
     $event = new ResourceEvent();
     $event->setName('fetchAll');
     $event->setQueryParams($queryParams);
     $this->listener->dispatch($event);
     $this->assertEquals($queryParams, $this->listener->testCase->paramsPassedToListener);
 }