Skip to content

Commit

Permalink
Merge pull request #136 from zf-fr/remove-collection-hydrator
Browse files Browse the repository at this point in the history
Remove hydrator mapping for Collection
  • Loading branch information
bakura10 committed Mar 10, 2014
2 parents 47dbf7a + 8d4ed85 commit 12fa1d3
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 53 deletions.
8 changes: 3 additions & 5 deletions docs/02. Quick Start.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ use ZfrRest\Resource\Metadata\Annotation as REST;
* hydrator="Zend\Stdlib\Hydrator\ClassMethods"
* )
* @REST\Collection(
* controller="Application\Controller\UsersController",
* hydrator="Zend\Stdlib\Hydrator\ClassMethods"
* controller="Application\Controller\UsersController"
* )
*/
class User
Expand Down Expand Up @@ -246,7 +245,7 @@ to do is **passing the resource to the service for your business logic**.

For the `put` method, you don't even need to manually validate the user data, because it has already been validated
using the input filter you specified in the mapping. If data would have been invalid, it would have returned a
400 Bad Request error, with the various error messages under the `errors` key.
`422 Unprocessable Entity` error, with the various error messages under the `errors` key.

If you want automatic serialization of the resource, you must return a ResourceModel (it needs a resource). ZfrRest
provides you a utility controller plugin called `resourceModel` that you can use to create one.
Expand Down Expand Up @@ -361,8 +360,7 @@ use ZfrRest\Resource\Metadata\Annotation as REST;
* hydrator="Zend\Stdlib\Hydrator\ClassMethods"
* )
* @REST\Collection(
* controller="Application\Controller\TweetsController",
* hydrator="Zend\Stdlib\Hydrator\ClassMethods"
* controller="Application\Controller\TweetsController"
* )
*/
class Tweet
Expand Down
1 change: 0 additions & 1 deletion docs/08. Mapping reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Allow to define mapping when a resource is accessed as a collection.
Attributes:

* `controller`: FQCN of the controller (pulled from the controller plugin manager)
* `hydrator`: FQCN of the hydrator (pulled from the hydrator plugin manager).

### Association

Expand Down
8 changes: 1 addition & 7 deletions src/ZfrRest/Resource/Metadata/Annotation/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ final class Collection implements AnnotationInterface
*/
public $controller;

/**
* @var string
*/
public $hydrator;

/**
* {@inheritDoc}
*/
public function getValue()
{
return [
'controller' => $this->controller,
'hydrator' => $this->hydrator
'controller' => $this->controller
];
}
}
8 changes: 0 additions & 8 deletions src/ZfrRest/Resource/Metadata/CollectionResourceMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,4 @@ public function getControllerName()
{
return $this->propertyMetadata['controller'];
}

/**
* {@inheritDoc}
*/
public function getHydratorName()
{
return $this->propertyMetadata['hydrator'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,4 @@ interface CollectionResourceMetadataInterface
* @return string|null
*/
public function getControllerName();

/**
* Get the hydrator's FQCN to be used for this resource
*
* @return string|null
*/
public function getHydratorName();
}
2 changes: 1 addition & 1 deletion src/ZfrRest/View/Renderer/SimpleResourceRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function renderItem(ResourceInterface $resource)
*/
public function renderCollection(ResourceInterface $resource)
{
$hydratorName = $resource->getMetadata()->getCollectionMetadata()->getHydratorName();
$hydratorName = $resource->getMetadata()->getHydratorName();
$hydrator = $this->hydratorPluginManager->get($hydratorName);

$data = $resource->getData();
Expand Down
3 changes: 1 addition & 2 deletions tests/ZfrRestTest/Asset/Resource/Metadata/Annotation/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* hydrator="ResourceHydrator"
* )
* @REST\Collection(
* controller="CollectionController",
* hydrator="CollectionHydrator"
* controller="CollectionController"
* )
*/
class A
Expand Down
3 changes: 1 addition & 2 deletions tests/ZfrRestTest/Asset/Resource/Metadata/Annotation/B.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* hydrator="ResourceHydrator"
* )
* @REST\Collection(
* controller="CollectionController",
* hydrator="CollectionHydrator"
* controller="CollectionController"
* )
*/
class B
Expand Down
3 changes: 1 addition & 2 deletions tests/ZfrRestTest/Asset/Resource/Metadata/Annotation/C.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
* hydrator="ResourceHydrator"
* )
* @REST\Collection(
* controller="CollectionController",
* hydrator="CollectionHydrator"
* controller="CollectionController"
* )
*/
class C
Expand Down
3 changes: 1 addition & 2 deletions tests/ZfrRestTest/Asset/Resource/Metadata/Annotation/D.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* hydrator="ResourceHydrator"
* )
* @REST\Collection(
* controller="CollectionController",
* hydrator="CollectionHydrator"
* controller="CollectionController"
* )
*/
class D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ class CollectionTest extends PHPUnit_Framework_TestCase
public function testAnnotation()
{
$annotation = new Collection();
$annotation->controller = 'Controller';
$annotation->hydrator = 'Hydrator';
$annotation->controller = 'Controller';

$expected = [
'controller' => 'Controller',
'hydrator' => 'Hydrator'
'controller' => 'Controller'
];

$this->assertEquals($expected, $annotation->getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ public function testSettersAndGetters()
$collectionResourceMetadata = new CollectionResourceMetadata('stdClass');

$data = [
'controller' => 'Controller',
'hydrator' => 'Hydrator'
'controller' => 'Controller'
];

foreach ($data as $key => $value) {
$collectionResourceMetadata->propertyMetadata[$key] = $value;
}

$this->assertEquals($data['controller'], $collectionResourceMetadata->getControllerName());
$this->assertEquals($data['hydrator'], $collectionResourceMetadata->getHydratorName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function testMetadataFromAnnotation()

$collectionMetadata = $metadata->getCollectionMetadata();
$this->assertEquals('CollectionController', $collectionMetadata->getControllerName());
$this->assertEquals('CollectionHydrator', $collectionMetadata->getHydratorName());

$this->assertTrue($metadata->hasAssociationMetadata('b'));
$this->assertFalse($metadata->hasAssociationMetadata('c'));
Expand Down
14 changes: 6 additions & 8 deletions tests/ZfrRestTest/View/Renderer/SimpleResourceRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @group Coverage
* @covers \ZfrRest\View\Renderer\SimpleResourceRenderer
*/
class ResourceRendererTest extends PHPUnit_Framework_TestCase
class SimpleResourceRendererTest extends PHPUnit_Framework_TestCase
{
/**
* ResourceRenderer does not really have engine
Expand Down Expand Up @@ -90,11 +90,10 @@ public function testCanRenderPaginator()
{
$hydratorPluginManager = $this->getMock('Zend\Stdlib\Hydrator\HydratorPluginManager');

$renderer = new SimpleResourceRenderer($hydratorPluginManager);
$resource = $this->getMock('ZfrRest\Resource\ResourceInterface');
$metadata = $this->getMock('ZfrRest\Resource\Metadata\ResourceMetadataInterface');
$collectionMetadata = $this->getMock('ZfrRest\Resource\Metadata\CollectionResourceMetadataInterface');
$hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface');
$renderer = new SimpleResourceRenderer($hydratorPluginManager);
$resource = $this->getMock('ZfrRest\Resource\ResourceInterface');
$metadata = $this->getMock('ZfrRest\Resource\Metadata\ResourceMetadataInterface');
$hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface');

$resourceModel = new ResourceModel($resource, $hydrator);
$paginator = $this->getMock('Zend\Paginator\Paginator', [], [], '', false);
Expand Down Expand Up @@ -123,8 +122,7 @@ public function testCanRenderPaginator()
$resource->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata));
$resource->expects($this->once())->method('getData')->will($this->returnValue($paginator));

$metadata->expects($this->once())->method('getCollectionMetadata')->will($this->returnValue($collectionMetadata));
$collectionMetadata->expects($this->once())->method('getHydratorName')->will($this->returnValue('Hydrator'));
$metadata->expects($this->once())->method('getHydratorName')->will($this->returnValue('Hydrator'));

$hydratorPluginManager->expects($this->once())
->method('get')
Expand Down

0 comments on commit 12fa1d3

Please sign in to comment.