ClassMetadataTest.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Metadata\Tests;
  3. use Metadata\ClassMetadata;
  4. class ClassMetadataTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testConstructor()
  7. {
  8. $metadata = new ClassMetadata('Metadata\Tests\Fixtures\TestObject');
  9. $this->assertEquals('Metadata\Tests\Fixtures\TestObject', $metadata->name);
  10. $this->assertEquals('Metadata\Tests\Fixtures\TestObject', $metadata->reflection->getName());
  11. }
  12. public function testSerializeUnserialize()
  13. {
  14. $metadata = new ClassMetadata('Metadata\Tests\Fixtures\TestObject');
  15. $this->assertEquals($metadata, unserialize(serialize($metadata)));
  16. }
  17. public function testIsFresh()
  18. {
  19. $ref = new \ReflectionClass('Metadata\Tests\Fixtures\TestObject');
  20. touch($ref->getFilename());
  21. sleep(2);
  22. $metadata = new ClassMetadata($ref->getName());
  23. $metadata->fileResources[] = $ref->getFilename();
  24. $this->assertTrue($metadata->isFresh());
  25. sleep(2);
  26. clearstatcache($ref->getFilename());
  27. touch($ref->getFilename());
  28. $this->assertFalse($metadata->isFresh());
  29. }
  30. }