public function testMissingClass() { $expectedItems = array('Epa\\Schema\\AdditionalIdentifier', 'Epa\\Schema\\AdditionalIdentifierType', 'Epa\\Schema\\AdditionalIdentifierTypes', 'Epa\\Schema\\AdditionalIdentifiers'); $expectedItems = array_combine($expectedItems, $expectedItems); $reader = new SchemaReader(); $schema = $reader->readFile(__DIR__ . '/data.xsd'); $yamlConv = new YamlConverter(new ShortNamingStrategy()); $yamlConv->addNamespace('', 'Epa\\Schema'); $yamlItems = $yamlConv->convert([$schema]); $this->assertCount(count($expectedItems), $yamlItems); $this->assertEmpty(array_diff_key($expectedItems, $yamlItems)); $phpConv = new PhpConverter(new ShortNamingStrategy()); $phpConv->addNamespace('', 'Epa\\Schema'); $phpClasses = $phpConv->convert([$schema]); $this->assertCount(count($expectedItems), $phpClasses); $this->assertEmpty(array_diff_key($expectedItems, $phpClasses)); $yamlClass = $yamlItems['Epa\\Schema\\AdditionalIdentifier']['Epa\\Schema\\AdditionalIdentifier']; $yamlProperty = $yamlClass['properties']['additionalIdentifierType']; /** @var PHPClass $phpClass */ $phpClass = $phpClasses['Epa\\Schema\\AdditionalIdentifier']; /** @var PHPProperty $phpProperty */ $phpProperty = $phpClass->getProperty('additionalIdentifierType'); /** @var PHPClass $phpType */ $phpType = $phpProperty->getType(); $this->assertSame($yamlProperty['type'], $phpType->getFullName()); }
public function testNamespace() { $reader = new SchemaReader(); $schema = $reader->readFile(__DIR__ . '/data.xsd'); $jmsConv = new YamlConverter(new ShortNamingStrategy()); $jmsConv->addNamespace('http://www.example.com', 'Tst'); $jmsConv->addNamespace('http://www.example2.com', 'Tst'); $phpClasses = $jmsConv->convert([$schema]); $type1 = $phpClasses['Tst\\ComplexType1Type']['Tst\\ComplexType1Type']; $propertyElement2 = $type1['properties']['element2']; self::assertEquals('http://www.example2.com', $propertyElement2['xml_element']['namespace']); $propertyElement1 = $type1['properties']['element1']; self::assertEquals('http://www.example.com', $propertyElement1['xml_element']['namespace']); }
public function testMissingClass() { $expectedItems = array('Epa\\Job', 'Epa\\Item', 'Epa\\Item\\PriceAType'); $reader = new SchemaReader(); $schema = $reader->readFile(__DIR__ . '/data.xsd'); $yamlConv = new YamlConverter(new ShortNamingStrategy()); $yamlConv->addNamespace('http://www.trogon.si/Schemas/2010/JobXML/2.0', 'Epa'); $yamlItems = $yamlConv->convert([$schema]); $yamlItems = array_keys($yamlItems); $this->assertEmpty(array_diff($expectedItems, $yamlItems)); $phpConv = new PhpConverter(new ShortNamingStrategy()); $phpConv->addNamespace('http://www.trogon.si/Schemas/2010/JobXML/2.0', 'Epa'); $phpClasses = $phpConv->convert([$schema]); $phpClasses = array_keys($phpClasses); $this->assertEmpty(array_diff_key($expectedItems, $phpClasses)); }
/** * * @param mixed $xml * @return array[] */ protected function getYamlFiles($xml, array $types = array()) { $creator = new YamlConverter(new ShortNamingStrategy()); $creator->addNamespace('', 'Example'); foreach ($types as $typeData) { list($ns, $name, $type) = $typeData; $creator->addAliasMapType($ns, $name, $type); } $reader = new SchemaReader(); if (!is_array($xml)) { $xml = ['schema.xsd' => $xml]; } $schemas = []; foreach ($xml as $name => $str) { $schemas[] = $reader->readString($str, $name); } $items = $creator->convert($schemas); return $items; }
protected function getClasses($xml) { $schema = $this->reader->readString($xml); return $this->converter->convert(array($schema)); }