protected function load()
 {
     $doc = new \DOMDocument();
     $doc->load($this->filename);
     if ($this->entityId) {
         $entitiesDescriptor = new EntitiesDescriptor();
         $entitiesDescriptor->loadFromXml($doc->firstChild);
         $this->entityDescriptor = $entitiesDescriptor->getByEntityId($this->entityId);
     } else {
         $this->entityDescriptor = new EntityDescriptor();
         $this->entityDescriptor->loadFromXml($doc->firstChild);
     }
 }
 /**
  * @test
  */
 public function shouldLoadTestshibMetadata()
 {
     $doc = new \DOMDocument();
     $doc->load(__DIR__ . '/../../../../../../../resources/sample/EntitiesDescriptor/testshib-providers.xml');
     $ed = new EntitiesDescriptor();
     $ed->loadFromXml($doc->firstChild);
     $arr = $ed->getAllEntityDescriptors();
     $this->assertCount(2, $arr);
     $this->assertEquals('https://idp.testshib.org/idp/shibboleth', $arr[0]->getEntityID());
     $this->assertCount(1, $arr[0]->getAllIdpSsoDescriptors());
     $this->assertCount(0, $arr[0]->getAllSpSsoDescriptors());
     $this->assertEquals('https://sp.testshib.org/shibboleth-sp', $arr[1]->getEntityID());
     $this->assertCount(0, $arr[1]->getAllIdpSsoDescriptors());
     $this->assertCount(1, $arr[1]->getAllSpSsoDescriptors());
 }
    /**
     * @test
     */
    public function shouldLoadXml()
    {
        $xml = '<?xml version="1.0"?>
<md:EntitiesDescriptor ID="esd1" Name="first" validUntil="2013-10-27T11:55:37.035Z" cacheDuration="P1D" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
    <md:EntityDescriptor entityID="ed1"/>
    <md:EntityDescriptor entityID="ed2"/>
    <md:EntitiesDescriptor ID="esd2" Name="second">
        <md:EntityDescriptor entityID="ed3"/>
    </md:EntitiesDescriptor>
</md:EntitiesDescriptor>';
        $doc = new \DOMDocument();
        $doc->loadXML($xml);
        $esd = new EntitiesDescriptor();
        $esd->loadFromXml($doc->firstChild);
        $this->assertEquals('esd1', $esd->getId());
        $this->assertEquals('first', $esd->getName());
        $this->assertEquals(1382874937, $esd->getValidUntil());
        $this->assertEquals('P1D', $esd->getCacheDuration());
        $items = $esd->getAllItems();
        $this->assertCount(3, $items);
        $this->assertInstanceOf('AerialShip\\LightSaml\\Model\\Metadata\\EntityDescriptor', $items[0]);
        $this->assertInstanceOf('AerialShip\\LightSaml\\Model\\Metadata\\EntityDescriptor', $items[1]);
        $this->assertInstanceOf('AerialShip\\LightSaml\\Model\\Metadata\\EntitiesDescriptor', $items[2]);
    }
 /**
  * @param EntitiesDescriptor|EntityDescriptor $item
  * @return $this|EntitiesDescriptor
  * @throws \InvalidArgumentException
  */
 public function addItem($item)
 {
     if (!$item instanceof EntitiesDescriptor && !$item instanceof EntityDescriptor) {
         throw new \InvalidArgumentException('Expected EntitiesDescriptor or EntityDescriptor');
     }
     if ($item === $this) {
         throw new \InvalidArgumentException('Circular reference detected');
     }
     if ($item instanceof EntitiesDescriptor) {
         if ($item->containsItem($this)) {
             throw new \InvalidArgumentException('Circular reference detected');
         }
     }
     $this->items[] = $item;
     return $this;
 }