/** * {@inheritDoc} * * @param string $className * @param string $file * @return null|ClassMetadata * @throws RuntimeException */ protected function loadMetadataFromFile($className, $file) { $config = Yaml::parse(file_get_contents($file)); if (!isset($config[$name = $className])) { throw new RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $className, $file)); } $config = $config[$name]; $metadata = new ClassMetadata($name); $metadata->addFileResource($file); foreach ($config['properties'] as $propertyName => $propertyOptions) { $pMetadata = new PropertyMetadata($propertyName); if (isset($propertyOptions['expose'])) { $pMetadata->setExpose((bool) $propertyOptions['expose']); } if (isset($propertyOptions['serialized_name'])) { $pMetadata->setSerializedName((string) $propertyOptions['serialized_name']); } if (isset($propertyOptions['since_version'])) { $pMetadata->setSinceVersion((string) $propertyOptions['since_version']); } if (isset($propertyOptions['until_version'])) { $pMetadata->setUntilVersion((string) $propertyOptions['until_version']); } if (isset($propertyOptions['type'])) { $pMetadata->setType((string) $propertyOptions['type']); } if (isset($propertyOptions['groups'])) { $pMetadata->setGroups($propertyOptions['groups']); } $metadata->addPropertyMetadata($pMetadata); } return $metadata; }
/** * @depends testPutClassMetadataInCache */ public function testRemoveClassMetadataFromCache() { $metadata = new ClassMetadata('test'); $metadata->addFileResource(__FILE__); $this->unitUderTest->putClassMetadataInCache($metadata); $this->unitUderTest->removeClassMetadataFromCache('test'); $this->assertFileNotExists($this->cacheDir . '/test.cache.php'); }
public function testAddClassMetadata() { $metadata = new ClassMetadata('testClass'); sleep(2); $unitUnderTest = new ClassHierarchyMetadata(); $property = new PropertyMetadata('property'); $property->setType('string'); $metadata->addFileResource('/tmp/fileNotExists')->addPropertyMetadata($property); $unitUnderTest->addFileResource('/tmp/fileNotExists2'); $property = new PropertyMetadata('property2'); $property->setType('integer'); $unitUnderTest->addPropertyMetadata($property); $unitUnderTest->addClassMetadata($metadata); $this->assertEquals($metadata->getName(), $unitUnderTest->getName()); $this->assertEquals($metadata->getCreatedAt(), $unitUnderTest->getCreatedAt()); $this->assertCount(2, $unitUnderTest->getFileResources()); $this->assertCount(2, $unitUnderTest->getProperties()); $this->assertEquals(array('/tmp/fileNotExists2', '/tmp/fileNotExists'), $unitUnderTest->getFileResources()); $this->assertArrayHasKey('property', $unitUnderTest->getProperties()); $this->assertArrayHasKey('property2', $unitUnderTest->getProperties()); }
/** * @depends testConstructor * @depends testSettersGetters */ public function testSerializeUnserialize() { $unitUnderTest = new ClassMetadata('testClass'); $property = new PropertyMetadata('property'); $property->setType('string'); $unitUnderTest->addFileResource('/tmp/fileNotExists')->addPropertyMetadata($property); $serializedString = serialize($unitUnderTest); $unserializedObject = unserialize($serializedString); $this->assertInstanceOf('Opensoft\\SimpleSerializer\\Metadata\\ClassMetadata', $unserializedObject); $this->assertEquals('testClass', $unserializedObject->getName()); $this->assertNotNull($unserializedObject->getCreatedAt()); $fileResources = $unserializedObject->getFileResources(); $this->assertCount(1, $fileResources); $this->assertEquals('/tmp/fileNotExists', $fileResources[0]); $properties = $unserializedObject->getProperties(); $this->assertCount(1, $properties); $this->assertArrayHasKey('property', $properties); $this->assertInstanceOf('Opensoft\\SimpleSerializer\\Metadata\\PropertyMetadata', $properties['property']); $this->assertEquals('property', $properties['property']->getName()); $this->assertEquals('string', $properties['property']->getType()); }