-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Toilal/element-local-property
Add local property to elements
- Loading branch information
Showing
5 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GoetasWebservices\XML\XSDReader\Tests; | ||
|
||
use GoetasWebservices\XML\XSDReader\Schema\Element\Element; | ||
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef; | ||
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef; | ||
use GoetasWebservices\XML\XSDReader\Schema\Schema; | ||
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType; | ||
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType; | ||
|
||
class LocalTest extends BaseTest | ||
{ | ||
public function testSchemaCanBeLoaded() | ||
{ | ||
$schema = $this->reader->readFile(__DIR__.'/schema/local.xsd'); | ||
$this->assertInstanceOf(Schema::class, $schema); | ||
} | ||
|
||
public function testTypesLocalPropertyIsValid() | ||
{ | ||
$schema = $this->reader->readFile(__DIR__.'/schema/local.xsd'); | ||
$this->assertInstanceOf(Schema::class, $schema); | ||
|
||
$type1 = $schema->getType("type1"); | ||
$this->assertInstanceOf(ComplexType::class, $type1); | ||
|
||
$localElements = $type1->getElements(); | ||
$this->assertCount(1, $localElements); | ||
/** @var ElementRef $localElement */ | ||
$localElement = $localElements[0]; | ||
|
||
$this->assertInstanceOf(ElementRef::class, $localElement); | ||
$this->assertFalse($localElement->isLocal()); | ||
|
||
$referencedElement = $localElement->getReferencedElement(); | ||
$this->assertNotNull($referencedElement); | ||
|
||
/** @var ComplexType $referencedElementType */ | ||
$referencedElementType = $referencedElement->getType(); | ||
$this->assertNotNull($referencedElementType); | ||
|
||
$this->assertInstanceOf(ComplexType::class, $referencedElementType); | ||
$elements = $referencedElementType->getElements(); | ||
$this->assertCount(1, $elements); | ||
|
||
$dataElement = $elements[0]; | ||
$this->assertInstanceOf(Element::class, $dataElement); | ||
|
||
$this->assertEquals("data", $dataElement->getName()); | ||
$this->assertTrue($dataElement->isLocal()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:example:local" | ||
attributeFormDefault="unqualified" elementFormDefault="unqualified" | ||
targetNamespace="urn:example:local"> | ||
<xs:element name="element1" type="tns:type1"/> | ||
<xs:element name="element2"> | ||
<xs:complexType> | ||
<xs:sequence> | ||
<xs:element minOccurs="0" name="data" type="tns:type2"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:element> | ||
<xs:complexType name="type1"> | ||
<xs:sequence> | ||
<xs:element minOccurs="0" ref="tns:element2"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
<xs:complexType name="type2"> | ||
<xs:sequence> | ||
<xs:element name="Id" type="xs:int"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:schema> |