Skip to content

Commit 7988dec

Browse files
committed
Add test
1 parent f1b4de0 commit 7988dec

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

src/Symfony/Component/Serializer/Mapping/Factory/Psr6MetadataFactory.php renamed to src/Symfony/Component/Serializer/Mapping/Factory/CacheClassMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Kévin Dunglas <dunglas@gmail.com>
2020
*/
21-
class Psr6CacheDecorator implements ClassMetadataFactoryInterface
21+
class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
2222
{
2323
use ClassResolverTrait;
2424

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Mapping\Factory;
13+
14+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
15+
use Symfony\Component\Serializer\Mapping\ClassMetadata;
16+
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
17+
18+
/**
19+
* @author Kévin Dunglas <dunglas@gmail.com>
20+
*/
21+
class CacheMetadataFactoryTest extends \PHPUnit_Framework_TestCase
22+
{
23+
public function testGetMetadataFor()
24+
{
25+
$metadata = new ClassMetadata('Symfony\Component\Serializer\Tests\Fixtures\Dummy');
26+
27+
$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
28+
$decorated
29+
->expects($this->once())
30+
->method('getMetadataFor')
31+
->will($this->returnValue($metadata))
32+
;
33+
34+
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
35+
36+
$this->assertEquals($metadata, $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
37+
// The second call should retrieve the value from the cache
38+
$this->assertEquals($metadata, $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
39+
}
40+
41+
public function testHasMetadataFor()
42+
{
43+
$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
44+
$decorated
45+
->expects($this->once())
46+
->method('hasMetadataFor')
47+
->will($this->returnValue(true))
48+
;
49+
50+
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
51+
52+
$this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\Dummy'));
53+
}
54+
55+
/**
56+
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
57+
*/
58+
public function testInvalidClassThrowsException()
59+
{
60+
$decorated = $this->getMock('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface');
61+
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
62+
63+
$factory->getMetadataFor('Not\Exist');
64+
}
65+
}

src/Symfony/Component/Serializer/Tests/Mapping/Factory/ClassMetadataFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
2525
public function testInterface()
2626
{
2727
$classMetadata = new ClassMetadataFactory(new LoaderChain(array()));
28-
$this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory', $classMetadata);
28+
$this->assertInstanceOf('Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface', $classMetadata);
2929
}
3030

3131
public function testGetMetadataFor()

src/Symfony/Component/Serializer/composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
"symfony/yaml": "~2.8|~3.0",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/property-access": "~2.8|~3.0",
25+
"symfony/cache": "~3.1",
2526
"doctrine/annotations": "~1.0",
2627
"doctrine/cache": "~1.0"
2728
},
2829
"suggest": {
29-
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
30-
"doctrine/cache": "For using the default cached annotation reader and metadata cache.",
30+
"symfony/cache": "For using the metadata cache.",
3131
"symfony/yaml": "For using the default YAML mapping loader.",
3232
"symfony/config": "For using the XML mapping loader.",
33-
"symfony/property-access": "For using the ObjectNormalizer."
33+
"symfony/property-access": "For using the ObjectNormalizer.",
34+
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
35+
"doctrine/cache": "For using the default cached annotation reader and metadata cache."
3436
},
3537
"autoload": {
3638
"psr-4": { "Symfony\\Component\\Serializer\\": "" },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy