Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class AuthorElementCollectionTest extends \PHPUnit_Framework_TestCase {
public function testAuthorElementCanBeRetrievedFromCollection() {
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><author xmlns="https://phar.io/xml/manifest/1.0" name="Reiner Zufall" email="reiner@zufall.de" />');
$collection = new AuthorElementCollection($dom->childNodes);
foreach($collection as $authorElement) {
$this->assertInstanceOf(AuthorElement::class, $authorElement);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace PharIo\Manifest;
class AuthorElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var AuthorElement
*/
private $author;
protected function setUp() {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><author xmlns="https://phar.io/xml/manifest/1.0" name="Reiner Zufall" email="reiner@zufall.de" />');
$this->author = new AuthorElement($dom->documentElement);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('Reiner Zufall', $this->author->getName());
}
public function testEmailCanBeRetrieved() {
$this->assertEquals('reiner@zufall.de', $this->author->getEmail());
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class BundlesElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var DOMDocument
*/
private $dom;
/**
* @var BundlesElement
*/
private $bundles;
protected function setUp() {
$this->dom = new DOMDocument();
$this->dom->loadXML('<?xml version="1.0" ?><bundles xmlns="https://phar.io/xml/manifest/1.0" />');
$this->bundles = new BundlesElement($this->dom->documentElement);
}
public function testThrowsExceptionWhenGetComponentElementsIsCalledButNodesAreMissing() {
$this->expectException(ManifestElementException::class);
$this->bundles->getComponentElements();
}
public function testGetComponentElementsReturnsComponentElementCollection() {
$this->addComponent();
$this->assertInstanceOf(
ComponentElementCollection::class, $this->bundles->getComponentElements()
);
}
private function addComponent() {
$this->dom->documentElement->appendChild(
$this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'component')
);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class ComponentElementCollectionTest extends \PHPUnit_Framework_TestCase {
public function testComponentElementCanBeRetrievedFromCollection() {
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><component xmlns="https://phar.io/xml/manifest/1.0" />');
$collection = new ComponentElementCollection($dom->childNodes);
foreach($collection as $componentElement) {
$this->assertInstanceOf(ComponentElement::class, $componentElement);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace PharIo\Manifest;
class ComponentElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var ComponentElement
*/
private $component;
protected function setUp() {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><component xmlns="https://phar.io/xml/manifest/1.0" name="phar-io/phive" version="0.6.0" />');
$this->component = new ComponentElement($dom->documentElement);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('phar-io/phive', $this->component->getName());
}
public function testEmailCanBeRetrieved() {
$this->assertEquals('0.6.0', $this->component->getVersion());
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
use DOMElement;
class ContainsElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var DOMElement
*/
private $domElement;
/**
* @var ContainsElement
*/
private $contains;
protected function setUp() {
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><php xmlns="https://phar.io/xml/manifest/1.0" name="phpunit/phpunit" version="5.6.5" type="application" />');
$this->domElement = $dom->documentElement;
$this->contains = new ContainsElement($this->domElement);
}
public function testVersionCanBeRetrieved() {
$this->assertEquals('5.6.5', $this->contains->getVersion());
}
public function testThrowsExceptionWhenVersionAttributeIsMissing() {
$this->domElement->removeAttribute('version');
$this->expectException(ManifestElementException::class);
$this->contains->getVersion();
}
public function testNameCanBeRetrieved() {
$this->assertEquals('phpunit/phpunit', $this->contains->getName());
}
public function testThrowsExceptionWhenNameAttributeIsMissing() {
$this->domElement->removeAttribute('name');
$this->expectException(ManifestElementException::class);
$this->contains->getName();
}
public function testTypeCanBeRetrieved() {
$this->assertEquals('application', $this->contains->getType());
}
public function testThrowsExceptionWhenTypeAttributeIsMissing() {
$this->domElement->removeAttribute('type');
$this->expectException(ManifestElementException::class);
$this->contains->getType();
}
public function testGetExtensionElementReturnsExtensionElement() {
$this->domElement->appendChild(
$this->domElement->ownerDocument->createElementNS('https://phar.io/xml/manifest/1.0', 'extension')
);
$this->assertInstanceOf(ExtensionElement::class, $this->contains->getExtensionElement());
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class CopyrightElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var DOMDocument
*/
private $dom;
/**
* @var CopyrightElement
*/
private $copyright;
protected function setUp() {
$this->dom = new DOMDocument();
$this->dom->loadXML('<?xml version="1.0" ?><copyright xmlns="https://phar.io/xml/manifest/1.0" />');
$this->copyright = new CopyrightElement($this->dom->documentElement);
}
public function testThrowsExceptionWhenGetAuthroElementsIsCalledButNodesAreMissing() {
$this->expectException(ManifestElementException::class);
$this->copyright->getAuthorElements();
}
public function testThrowsExceptionWhenGetLicenseElementIsCalledButNodeIsMissing() {
$this->expectException(ManifestElementException::class);
$this->copyright->getLicenseElement();
}
public function testGetAuthorElementsReturnsAuthorElementCollection() {
$this->dom->documentElement->appendChild(
$this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'author')
);
$this->assertInstanceOf(
AuthorElementCollection::class, $this->copyright->getAuthorElements()
);
}
public function testGetLicenseElementReturnsLicenseElement() {
$this->dom->documentElement->appendChild(
$this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'license')
);
$this->assertInstanceOf(
LicenseElement::class, $this->copyright->getLicenseElement()
);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class ExtElementCollectionTest extends \PHPUnit_Framework_TestCase {
public function testComponentElementCanBeRetrievedFromCollection() {
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><ext xmlns="https://phar.io/xml/manifest/1.0" />');
$collection = new ExtElementCollection($dom->childNodes);
foreach($collection as $position => $extElement) {
$this->assertInstanceOf(ExtElement::class, $extElement);
$this->assertEquals(0, $position);
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace PharIo\Manifest;
class ExtElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var ExtElement
*/
private $ext;
protected function setUp() {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><ext xmlns="https://phar.io/xml/manifest/1.0" name="dom" />');
$this->ext = new ExtElement($dom->documentElement);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('dom', $this->ext->getName());
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace PharIo\Manifest;
class ExtensionElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var ExtensionElement
*/
private $extension;
protected function setUp() {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><extension xmlns="https://phar.io/xml/manifest/1.0" for="phar-io/phive" compatible="~0.6" />');
$this->extension = new ExtensionElement($dom->documentElement);
}
public function testNForCanBeRetrieved() {
$this->assertEquals('phar-io/phive', $this->extension->getFor());
}
public function testCompatibleVersionConstraintCanBeRetrieved() {
$this->assertEquals('~0.6', $this->extension->getCompatible());
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace PharIo\Manifest;
class LicenseElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var LicenseElement
*/
private $license;
protected function setUp() {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><license xmlns="https://phar.io/xml/manifest/1.0" type="BSD-3" url="https://some.tld/LICENSE" />');
$this->license = new LicenseElement($dom->documentElement);
}
public function testTypeCanBeRetrieved() {
$this->assertEquals('BSD-3', $this->license->getType());
}
public function testUrlCanBeRetrieved() {
$this->assertEquals('https://some.tld/LICENSE', $this->license->getUrl());
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace PharIo\Manifest;
class ManifestDocumentTest extends \PHPUnit_Framework_TestCase {
public function testThrowsExceptionWhenFileDoesNotExist() {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromFile('/does/not/exist');
}
public function testCanBeCreatedFromFile() {
$this->assertInstanceOf(
ManifestDocument::class,
ManifestDocument::fromFile(__DIR__ . '/../_fixture/phpunit-5.6.5.xml')
);
}
public function testCaneBeConstructedFromString() {
$content = file_get_contents(__DIR__ . '/../_fixture/phpunit-5.6.5.xml');
$this->assertInstanceOf(
ManifestDocument::class,
ManifestDocument::fromString($content)
);
}
public function testThrowsExceptionOnInvalidXML() {
$this->expectException(ManifestDocumentLoadingException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><root>');
}
public function testLoadingDocumentWithWrongRootNameThrowsException() {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><root />');
}
public function testLoadingDocumentWithWrongNamespaceThrowsException() {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><phar xmlns="foo:bar" />');
}
public function testContainsElementCanBeRetrieved() {
$this->assertInstanceOf(
ContainsElement::class,
$this->loadFixture()->getContainsElement()
);
}
public function testRequiresElementCanBeRetrieved() {
$this->assertInstanceOf(
RequiresElement::class,
$this->loadFixture()->getRequiresElement()
);
}
public function testCopyrightElementCanBeRetrieved() {
$this->assertInstanceOf(
CopyrightElement::class,
$this->loadFixture()->getCopyrightElement()
);
}
public function testBundlesElementCanBeRetrieved() {
$this->assertInstanceOf(
BundlesElement::class,
$this->loadFixture()->getBundlesElement()
);
}
public function testThrowsExceptionWhenContainsIsMissing() {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getContainsElement();
}
public function testThrowsExceptionWhenCopyirhgtIsMissing() {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getCopyrightElement();
}
public function testThrowsExceptionWhenRequiresIsMissing() {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getRequiresElement();
}
public function testThrowsExceptionWhenBundlesIsMissing() {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getBundlesElement();
}
public function testHasBundlesReturnsTrueWhenBundlesNodeIsPresent() {
$this->assertTrue(
$this->loadFixture()->hasBundlesElement()
);
}
public function testHasBundlesReturnsFalseWhenBundlesNoNodeIsPresent() {
$this->assertFalse(
$this->loadEmptyFixture()->hasBundlesElement()
);
}
private function loadFixture() {
return ManifestDocument::fromFile(__DIR__ . '/../_fixture/phpunit-5.6.5.xml');
}
private function loadEmptyFixture() {
return ManifestDocument::fromString(
'<?xml version="1.0" ?><phar xmlns="https://phar.io/xml/manifest/1.0" />'
);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class PhpElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var DOMDocument
*/
private $dom;
/**
* @var PhpElement
*/
private $php;
protected function setUp() {
$this->dom = new DOMDocument();
$this->dom->loadXML('<?xml version="1.0" ?><php xmlns="https://phar.io/xml/manifest/1.0" version="^5.6 || ^7.0" />');
$this->php = new PhpElement($this->dom->documentElement);
}
public function testVersionConstraintCanBeRetrieved() {
$this->assertEquals('^5.6 || ^7.0', $this->php->getVersion());
}
public function testHasExtElementsReturnsFalseWhenNoExtensionsAreRequired() {
$this->assertFalse($this->php->hasExtElements());
}
public function testHasExtElementsReturnsTrueWhenExtensionsAreRequired() {
$this->addExtElement();
$this->assertTrue($this->php->hasExtElements());
}
public function testGetExtElementsReturnsExtElementCollection() {
$this->addExtElement();
$this->assertInstanceOf(ExtElementCollection::class, $this->php->getExtElements());
}
private function addExtElement() {
$this->dom->documentElement->appendChild(
$this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'ext')
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
class RequiresElementTest extends \PHPUnit_Framework_TestCase {
/**
* @var DOMDocument
*/
private $dom;
/**
* @var RequiresElement
*/
private $requires;
protected function setUp() {
$this->dom = new DOMDocument();
$this->dom->loadXML('<?xml version="1.0" ?><requires xmlns="https://phar.io/xml/manifest/1.0" />');
$this->requires = new RequiresElement($this->dom->documentElement);
}
public function testThrowsExceptionWhenGetPhpElementIsCalledButElementIsMissing() {
$this->expectException(ManifestElementException::class);
$this->requires->getPHPElement();
}
public function testHasExtElementsReturnsTrueWhenExtensionsAreRequired() {
$this->dom->documentElement->appendChild(
$this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'php')
);
$this->assertInstanceOf(PhpElement::class, $this->requires->getPHPElement());
}
}