* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Tests\Config; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\AutowirePass; use Symfony\Component\DependencyInjection\Config\AutowireServiceResource; /** * @group legacy */ class AutowireServiceResourceTest extends TestCase { /** * @var AutowireServiceResource */ private $resource; private $file; private $class; private $time; protected function setUp() { $this->file = realpath(sys_get_temp_dir()).'/tmp.php'; $this->time = time(); touch($this->file, $this->time); $this->class = __NAMESPACE__.'\Foo'; $this->resource = new AutowireServiceResource( $this->class, $this->file, array() ); } public function testToString() { $this->assertSame('service.autowire.'.$this->class, (string) $this->resource); } public function testSerializeUnserialize() { $unserialized = unserialize(serialize($this->resource)); $this->assertEquals($this->resource, $unserialized); } public function testIsFresh() { $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second'); $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed'); $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated'); } public function testIsFreshForDeletedResources() { unlink($this->file); $this->assertFalse($this->resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the resource does not exist'); } public function testIsNotFreshChangedResource() { $oldResource = new AutowireServiceResource( $this->class, $this->file, array('will_be_different') ); // test with a stale file *and* a resource that *will* be different than the actual $this->assertFalse($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed'); } public function testIsFreshSameConstructorArgs() { $oldResource = AutowirePass::createResourceForClass( new \ReflectionClass(__NAMESPACE__.'\Foo') ); // test with a stale file *but* the resource will not be changed $this->assertTrue($oldResource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the constructor arguments have changed'); } public function testNotFreshIfClassNotFound() { $resource = new AutowireServiceResource( 'Some\Non\Existent\Class', $this->file, array() ); $this->assertFalse($resource->isFresh($this->getStaleFileTime()), '->isFresh() returns false if the class no longer exists'); } protected function tearDown() { if (!file_exists($this->file)) { return; } unlink($this->file); } private function getStaleFileTime() { return $this->time - 10; } } class Foo { public function __construct($foo) { } } __halt_compiler();----SIGNATURE:----dLBdj7YB/ZDtNqs5HeoQz0igWGkX5HC6JLgeVGpxW7ppk0vNd4RSX4Yrp1G4zhVXICcSHf2A6qASoiQ52daRzpQmlQBTStSHqNV1qynubApNyCnkICN55ujTEf5wcpI+US1No6cCTs6ykZnF85OT93Jju9PM+y52TkmfsqP78ExYrpjEhmHqdZFwFx4dvPkGNFxjO9BVFTedXDWoIafKSUa2QZ0nGN+pwDYn2FxE6xVYxdcyOdSpWexMxaKgsniCgKCaszLM7NwwMn86ew5o3xhoTYKnF6jLph+TRFG2I2cLNXIBPFqbqgIHbDGq5QeaiqAnJWN+uHv/Lvzml7QRJ0Ma4srKzeKJNFL0yAL4+jBBkRJgu/qwdJuNGishgLvdloGsLRkxDlU/Y3zN7/RbGi+mmQM433J/+S5NVsvqnn3eozbBqm8gFEIIlxc15/jgJIvuPFt+fdHbkSkR+KWOUxj1OF7NpsPvSB3pBE/dG3HXa5G/ys//bekx20vpDXMNvASzJgM4jK5h6QE1PTEeh+zS6SDBJf8tQ+DIqCjAJAOi2ywJfCXPH3TN2A+b3/KhV8ubBZirc8uMBV+gQy070HBtq4aSq0h8KBNflsTyMEgLVm31OjMVXfE+6FMV2Kdtz37nk8umL30weJRc5mhX+NcJ4+9EqdTLNN7OOt+rYPE=----ATTACHMENT:----NTI0OTI3Mjk4NTMyMDY3NiA5OTQ1NjY3NDQ4NzM4ODY4IDU1OTU3Njk1NjY3MzQyOTA=