-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from zf-fr/fix-cache
Properly wakeup ClassMetadata
- Loading branch information
Showing
7 changed files
with
130 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrRest\Resource\Metadata; | ||
|
||
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory; | ||
use Metadata\Driver\DriverInterface; | ||
use Metadata\MetadataFactory; | ||
|
||
/** | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* @licence MIT | ||
*/ | ||
class ResourceMetadataFactory extends MetadataFactory | ||
{ | ||
/** | ||
* @var ClassMetadataFactory | ||
*/ | ||
protected $classMetadataFactory; | ||
|
||
/** | ||
* @param ClassMetadataFactory $classMetadataFactory | ||
* @param DriverInterface $driver | ||
*/ | ||
public function __construct(ClassMetadataFactory $classMetadataFactory, DriverInterface $driver) | ||
{ | ||
$this->classMetadataFactory = $classMetadataFactory; | ||
parent::__construct($driver); | ||
} | ||
|
||
/** | ||
* @param string $className | ||
* @return ResourceMetadataInterface | ||
*/ | ||
public function getMetadataForClass($className) | ||
{ | ||
$resourceMetadata = parent::getMetadataForClass($className); | ||
$resourceMetadata->propertyMetadata['classMetadata'] = $this->classMetadataFactory->getMetadataFor($className); | ||
|
||
return $resourceMetadata; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/ZfrRestTest/Resource/Metadata/ResourceMetadataFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrRestTest\Resource\Metadata; | ||
|
||
use ZfrRest\Resource\Metadata\ResourceMetadataFactory; | ||
|
||
/** | ||
* @licence MIT | ||
* @author Michaël Gallego <mic.gallego@gmail.com> | ||
* | ||
* @group Coverage | ||
* @covers \ZfrRest\Resource\Metadata\ResourceMetadataFactory | ||
*/ | ||
class ResourceMetadataFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testAssertDoctrineClassMetadataIsFilled() | ||
{ | ||
$classMetadataFactory = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadataFactory'); | ||
$driver = $this->getMock('Metadata\Driver\DriverInterface'); | ||
|
||
$metadataFactory = new ResourceMetadataFactory($classMetadataFactory, $driver); | ||
|
||
$classMetadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); | ||
|
||
$classMetadataFactory->expects($this->once()) | ||
->method('getMetadataFor') | ||
->will($this->returnValue($classMetadata)); | ||
|
||
$resourceMetadata = $metadataFactory->getMetadataForClass('stdClass'); | ||
|
||
$this->assertSame($classMetadata, $resourceMetadata->propertyMetadata['classMetadata']); | ||
} | ||
} |