Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Config / AutowireServiceResourceTest.php
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\DependencyInjection\Tests\Config;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
16 use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
17
18 /**
19  * @group legacy
20  */
21 class AutowireServiceResourceTest extends TestCase
22 {
23     /**
24      * @var AutowireServiceResource
25      */
26     private $resource;
27     private $file;
28     private $class;
29     private $time;
30
31     protected function setUp()
32     {
33         $this->file = realpath(sys_get_temp_dir()).'/tmp.php';
34         $this->time = time();
35         touch($this->file, $this->time);
36
37         $this->class = __NAMESPACE__.'\Foo';
38         $this->resource = new AutowireServiceResource(
39             $this->class,
40             $this->file,
41             array()
42         );
43     }
44
45     public function testToString()
46     {
47         $this->assertSame('service.autowire.'.$this->class, (string) $this->resource);
48     }
49
50     public function testSerializeUnserialize()
51     {
52         $unserialized = unserialize(serialize($this->resource));
53
54         $this->assertEquals($this->resource, $unserialized);
55     }
56
57     public function testIsFresh()
58     {
59         $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
60         $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
61         $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
62     }
63
64     public function testIsFreshForDeletedResources()
65     {
66         unlink($this->file);
67
68         $this->assertFalse($this->resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the resource does not exist');
69     }
70
71     public function testIsNotFreshChangedResource()
72     {
73         $oldResource = new AutowireServiceResource(
74             $this->class,
75             $this->file,
76             array('will_be_different')
77         );
78
79         // test with a stale file *and* a resource that *will* be different than the actual
80         $this->assertFalse($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
81     }
82
83     public function testIsFreshSameConstructorArgs()
84     {
85         $oldResource = AutowirePass::createResourceForClass(
86             new \ReflectionClass(__NAMESPACE__.'\Foo')
87         );
88
89         // test with a stale file *but* the resource will not be changed
90         $this->assertTrue($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed');
91     }
92
93     public function testNotFreshIfClassNotFound()
94     {
95         $resource = new AutowireServiceResource(
96             'Some\Non\Existent\Class',
97             $this->file,
98             array()
99         );
100
101         $this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists');
102     }
103
104     protected function tearDown()
105     {
106         if (!file_exists($this->file)) {
107             return;
108         }
109
110         unlink($this->file);
111     }
112
113     private function getStaleFileTime()
114     {
115         return $this->time - 10;
116     }
117 }
118
119 class Foo
120 {
121     public function __construct($foo)
122     {
123     }
124 }