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,110 @@
<?php
namespace PharIo\Manifest;
/**
* @covers \PharIo\Manifest\ManifestDocumentMapper
*
* @uses \PharIo\Manifest\ApplicationName
* @uses \PharIo\Manifest\Author
* @uses \PharIo\Manifest\AuthorCollection
* @uses \PharIo\Manifest\AuthorCollectionIterator
* @uses \PharIo\Manifest\AuthorElement
* @uses \PharIo\Manifest\AuthorElementCollection
* @uses \PharIo\Manifest\BundledComponent
* @uses \PharIo\Manifest\BundledComponentCollection
* @uses \PharIo\Manifest\BundledComponentCollectionIterator
* @uses \PharIo\Manifest\BundlesElement
* @uses \PharIo\Manifest\ComponentElement
* @uses \PharIo\Manifest\ComponentElementCollection
* @uses \PharIo\Manifest\ContainsElement
* @uses \PharIo\Manifest\CopyrightElement
* @uses \PharIo\Manifest\CopyrightInformation
* @uses \PharIo\Manifest\ElementCollection
* @uses \PharIo\Manifest\Email
* @uses \PharIo\Manifest\ExtElement
* @uses \PharIo\Manifest\ExtElementCollection
* @uses \PharIo\Manifest\License
* @uses \PharIo\Manifest\LicenseElement
* @uses \PharIo\Manifest\Manifest
* @uses \PharIo\Manifest\ManifestDocument
* @uses \PharIo\Manifest\ManifestDocumentMapper
* @uses \PharIo\Manifest\ManifestElement
* @uses \PharIo\Manifest\ManifestLoader
* @uses \PharIo\Manifest\PhpElement
* @uses \PharIo\Manifest\PhpExtensionRequirement
* @uses \PharIo\Manifest\PhpVersionRequirement
* @uses \PharIo\Manifest\RequirementCollection
* @uses \PharIo\Manifest\RequirementCollectionIterator
* @uses \PharIo\Manifest\RequiresElement
* @uses \PharIo\Manifest\Type
* @uses \PharIo\Manifest\Url
* @uses \PharIo\Version\Version
* @uses \PharIo\Version\VersionConstraint
*/
class ManifestDocumentMapperTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider dataProvider
*
* @param $expected
*
* @uses \PharIo\Manifest\Application
* @uses \PharIo\Manifest\ApplicationName
* @uses \PharIo\Manifest\Library
* @uses \PharIo\Manifest\Extension
* @uses \PharIo\Manifest\ExtensionElement
*/
public function testCanSerializeToString($expected) {
$manifestDocument = ManifestDocument::fromFile($expected);
$mapper = new ManifestDocumentMapper();
$this->assertInstanceOf(
Manifest::class,
$mapper->map($manifestDocument)
);
}
public function dataProvider() {
return [
'application' => [__DIR__ . '/_fixture/phpunit-5.6.5.xml'],
'library' => [__DIR__ . '/_fixture/library.xml'],
'extension' => [__DIR__ . '/_fixture/extension.xml']
];
}
public function testThrowsExceptionOnUnsupportedType() {
$manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/custom.xml');
$mapper = new ManifestDocumentMapper();
$this->expectException(ManifestDocumentMapperException::class);
$mapper->map($manifestDocument);
}
public function testInvalidVersionInformationThrowsException() {
$manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/invalidversion.xml');
$mapper = new ManifestDocumentMapper();
$this->expectException(ManifestDocumentMapperException::class);
$mapper->map($manifestDocument);
}
public function testInvalidVersionConstraintThrowsException() {
$manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/invalidversionconstraint.xml');
$mapper = new ManifestDocumentMapper();
$this->expectException(ManifestDocumentMapperException::class);
$mapper->map($manifestDocument);
}
/**
* @uses \PharIo\Manifest\ExtensionElement
*/
public function testInvalidCompatibleConstraintThrowsException() {
$manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/extension-invalidcompatible.xml');
$mapper = new ManifestDocumentMapper();
$this->expectException(ManifestDocumentMapperException::class);
$mapper->map($manifestDocument);
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace PharIo\Manifest;
/**
* @covers \PharIo\Manifest\ManifestLoader
*
* @uses \PharIo\Manifest\Author
* @uses \PharIo\Manifest\AuthorCollection
* @uses \PharIo\Manifest\AuthorCollectionIterator
* @uses \PharIo\Manifest\AuthorElement
* @uses \PharIo\Manifest\AuthorElementCollection
* @uses \PharIo\Manifest\ApplicationName
* @uses \PharIo\Manifest\BundledComponent
* @uses \PharIo\Manifest\BundledComponentCollection
* @uses \PharIo\Manifest\BundledComponentCollectionIterator
* @uses \PharIo\Manifest\BundlesElement
* @uses \PharIo\Manifest\ComponentElement
* @uses \PharIo\Manifest\ComponentElementCollection
* @uses \PharIo\Manifest\ContainsElement
* @uses \PharIo\Manifest\CopyrightElement
* @uses \PharIo\Manifest\CopyrightInformation
* @uses \PharIo\Manifest\ElementCollection
* @uses \PharIo\Manifest\Email
* @uses \PharIo\Manifest\ExtElement
* @uses \PharIo\Manifest\ExtElementCollection
* @uses \PharIo\Manifest\License
* @uses \PharIo\Manifest\LicenseElement
* @uses \PharIo\Manifest\Manifest
* @uses \PharIo\Manifest\ManifestDocument
* @uses \PharIo\Manifest\ManifestDocumentMapper
* @uses \PharIo\Manifest\ManifestElement
* @uses \PharIo\Manifest\ManifestLoader
* @uses \PharIo\Manifest\PhpElement
* @uses \PharIo\Manifest\PhpExtensionRequirement
* @uses \PharIo\Manifest\PhpVersionRequirement
* @uses \PharIo\Manifest\RequirementCollection
* @uses \PharIo\Manifest\RequirementCollectionIterator
* @uses \PharIo\Manifest\RequiresElement
* @uses \PharIo\Manifest\Type
* @uses \PharIo\Manifest\Url
* @uses \PharIo\Version\Version
* @uses \PharIo\Version\VersionConstraint
*/
class ManifestLoaderTest extends \PHPUnit_Framework_TestCase {
public function testCanBeLoadedFromFile() {
$this->assertInstanceOf(
Manifest::class,
ManifestLoader::fromFile(__DIR__ . '/_fixture/library.xml')
);
}
public function testCanBeLoadedFromString() {
$this->assertInstanceOf(
Manifest::class,
ManifestLoader::fromString(
file_get_contents(__DIR__ . '/_fixture/library.xml')
)
);
}
public function testCanBeLoadedFromPhar() {
$this->assertInstanceOf(
Manifest::class,
ManifestLoader::fromPhar(__DIR__ . '/_fixture/test.phar')
);
}
public function testLoadingNonExistingFileThrowsException() {
$this->expectException(ManifestLoaderException::class);
ManifestLoader::fromFile('/not/existing');
}
/**
* @uses \PharIo\Manifest\ManifestDocumentLoadingException
*/
public function testLoadingInvalidXmlThrowsException() {
$this->expectException(ManifestLoaderException::class);
ManifestLoader::fromString('<?xml version="1.0" ?><broken>');
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace PharIo\Manifest;
use PharIo\Version\Version;
/**
* @covers \PharIo\Manifest\ManifestSerializer
*
* @uses \PharIo\Manifest\ApplicationName
* @uses \PharIo\Manifest\Author
* @uses \PharIo\Manifest\AuthorCollection
* @uses \PharIo\Manifest\AuthorCollectionIterator
* @uses \PharIo\Manifest\AuthorElement
* @uses \PharIo\Manifest\AuthorElementCollection
* @uses \PharIo\Manifest\BundledComponent
* @uses \PharIo\Manifest\BundledComponentCollection
* @uses \PharIo\Manifest\BundledComponentCollectionIterator
* @uses \PharIo\Manifest\BundlesElement
* @uses \PharIo\Manifest\ComponentElement
* @uses \PharIo\Manifest\ComponentElementCollection
* @uses \PharIo\Manifest\ContainsElement
* @uses \PharIo\Manifest\CopyrightElement
* @uses \PharIo\Manifest\CopyrightInformation
* @uses \PharIo\Manifest\ElementCollection
* @uses \PharIo\Manifest\Email
* @uses \PharIo\Manifest\ExtElement
* @uses \PharIo\Manifest\ExtElementCollection
* @uses \PharIo\Manifest\License
* @uses \PharIo\Manifest\LicenseElement
* @uses \PharIo\Manifest\Manifest
* @uses \PharIo\Manifest\ManifestDocument
* @uses \PharIo\Manifest\ManifestDocumentMapper
* @uses \PharIo\Manifest\ManifestElement
* @uses \PharIo\Manifest\ManifestLoader
* @uses \PharIo\Manifest\PhpElement
* @uses \PharIo\Manifest\PhpExtensionRequirement
* @uses \PharIo\Manifest\PhpVersionRequirement
* @uses \PharIo\Manifest\RequirementCollection
* @uses \PharIo\Manifest\RequirementCollectionIterator
* @uses \PharIo\Manifest\RequiresElement
* @uses \PharIo\Manifest\Type
* @uses \PharIo\Manifest\Url
* @uses \PharIo\Version\Version
* @uses \PharIo\Version\VersionConstraint
*/
class ManifestSerializerTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider dataProvider
*
* @param $expected
*
* @uses \PharIo\Manifest\Application
* @uses \PharIo\Manifest\Library
* @uses \PharIo\Manifest\Extension
* @uses \PharIo\Manifest\ExtensionElement
*/
public function testCanSerializeToString($expected) {
$manifest = ManifestLoader::fromString($expected);
$serializer = new ManifestSerializer();
$this->assertXmlStringEqualsXmlString(
$expected,
$serializer->serializeToString($manifest)
);
}
public function dataProvider() {
return [
'application' => [file_get_contents(__DIR__ . '/_fixture/phpunit-5.6.5.xml')],
'library' => [file_get_contents(__DIR__ . '/_fixture/library.xml')],
'extension' => [file_get_contents(__DIR__ . '/_fixture/extension.xml')]
];
}
/**
* @uses \PharIo\Manifest\Library
* @uses \PharIo\Manifest\ApplicationName
*/
public function testCanSerializeToFile() {
$src = __DIR__ . '/_fixture/library.xml';
$dest = '/tmp/' . uniqid('serializer', true);
$manifest = ManifestLoader::fromFile($src);
$serializer = new ManifestSerializer();
$serializer->serializeToFile($manifest, $dest);
$this->assertXmlFileEqualsXmlFile($src, $dest);
unlink($dest);
}
/**
* @uses \PharIo\Manifest\ApplicationName
*/
public function testCanHandleUnknownType() {
$type = $this->getMockForAbstractClass(Type::class);
$manifest = new Manifest(
new ApplicationName('testvendor/testname'),
new Version('1.0.0'),
$type,
new CopyrightInformation(
new AuthorCollection(),
new License('bsd-3', new Url('https://some/uri'))
),
new RequirementCollection(),
new BundledComponentCollection()
);
$serializer = new ManifestSerializer();
$this->assertXmlStringEqualsXmlFile(
__DIR__ . '/_fixture/custom.xml',
$serializer->serializeToString($manifest)
);
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="testvendor/testname" version="1.0.0" type="custom"/>
<copyright>
<license type="bsd-3" url="https://some/uri"/>
</copyright>
<requires>
<php version="*"/>
</requires>
</phar>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="phpunit/phpunit-example-extension" version="1.0.0" type="extension">
<extension for="phpunit/phpunit" compatible="invalid"/>
</contains>
<copyright>
<author name="Sebastian Bergmann" email="sebastian@phpunit.de"/>
<license type="BSD-3-Clause" url="https://github.com/sebastianbergmann/phpunit-example-extension/blob/master/LICENSE"/>
</copyright>
<requires>
<php version="^7.0"/>
</requires>
</phar>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="phpunit/phpunit-example-extension" version="1.0.0" type="extension">
<extension for="phpunit/phpunit" compatible="^5.7"/>
</contains>
<copyright>
<author name="Sebastian Bergmann" email="sebastian@phpunit.de"/>
<license type="BSD-3-Clause" url="https://github.com/sebastianbergmann/phpunit-example-extension/blob/master/LICENSE"/>
</copyright>
<requires>
<php version="^7.0"/>
</requires>
</phar>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="some/library" version="abc" type="library" />
<copyright>
<author name="Reiner Zufall" email="reiner@zufall.de"/>
<license type="BSD-3-Clause" url="https://domain.tld/LICENSE"/>
</copyright>
<requires>
<php version="7.0"/>
</requires>
</phar>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="some/library" version="1.0.0" type="library" />
<copyright>
<author name="Reiner Zufall" email="reiner@zufall.de"/>
<license type="BSD-3-Clause" url="https://domain.tld/LICENSE"/>
</copyright>
<requires>
<php version="invalid"/>
</requires>
</phar>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="some/library" version="1.0.0" type="library" />
<copyright>
<author name="Reiner Zufall" email="reiner@zufall.de"/>
<license type="BSD-3-Clause" url="https://domain.tld/LICENSE"/>
</copyright>
<requires>
<php version="7.0"/>
</requires>
</phar>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="some/library" version="1.0.0" type="library" />
<copyright>
<author name="Reiner Zufall" email="reiner@zufall.de"/>
<license type="BSD-3-Clause" url="https://domain.tld/LICENSE"/>
</copyright>
<requires>
<php version="7.0"/>
</requires>
</phar>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="phpunit/phpunit" version="5.6.5" type="application"/>
<copyright>
<author name="Sebastian Bergmann" email="sebastian@phpunit.de"/>
<license type="BSD-3-Clause" url="https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE"/>
</copyright>
<requires>
<!-- constraint on next line should be ^5.6 || ^7.0 -->
<php version="^7.0">
<ext name="dom"/>
<ext name="json"/>
<ext name="mbstring"/>
<ext name="xml"/>
<ext name="libxml"/>
</php>
</requires>
<bundles>
<component name="doctrine/instantiator" version="1.0.5"/>
<component name="myclabs/deep-copy" version="1.5.5"/>
<component name="phpdocumentor/reflection-common" version="1.0"/>
<component name="phpdocumentor/reflection-docblock" version="3.1.1"/>
<component name="phpdocumentor/type-resolver" version="0.2"/>
<component name="phpspec/prophecy" version="v1.6.2"/>
<component name="phpunit/dbunit" version="2.0.2"/>
<component name="phpunit/php-code-coverage" version="4.0.2"/>
<component name="phpunit/php-file-iterator" version="1.4.1"/>
<component name="phpunit/php-invoker" version="1.1.4"/>
<component name="phpunit/php-text-template" version="1.2.1"/>
<component name="phpunit/php-timer" version="1.0.8"/>
<component name="phpunit/php-token-stream" version="1.4.9"/>
<component name="phpunit/phpunit-mock-objects" version="3.4.1"/>
<component name="sebastian/code-unit-reverse-lookup" version="1.0.0"/>
<component name="sebastian/comparator" version="1.2.2"/>
<component name="sebastian/diff" version="1.4.1"/>
<component name="sebastian/environment" version="1.3.8"/>
<component name="sebastian/exporter" version="2.0.0"/>
<component name="sebastian/global-state" version="1.1.1"/>
<component name="sebastian/object-enumerator" version="2.0.0"/>
<component name="sebastian/recursion-context" version="2.0.0"/>
<component name="sebastian/resource-operations" version="1.0.0"/>
<component name="sebastian/version" version="2.0.0"/>
<component name="symfony/yaml" version="v3.1.7"/>
<component name="webmozart/assert" version="1.1.0"/>
</bundles>
</phar>

Binary file not shown.

View File

@@ -0,0 +1,19 @@
<?php
namespace PharIo\Manifest;
use DOMDocument;
use LibXMLError;
class ManifestDocumentLoadingExceptionTest extends \PHPUnit_Framework_TestCase {
public function testXMLErrorsCanBeRetrieved() {
$dom = new DOMDocument();
$prev = libxml_use_internal_errors(true);
$dom->loadXML('<?xml version="1.0" ?><broken>');
$exception = new ManifestDocumentLoadingException(libxml_get_errors());
libxml_use_internal_errors($prev);
$this->assertContainsOnlyInstancesOf(LibXMLError::class, $exception->getLibxmlErrors());
}
}

View File

@@ -0,0 +1,48 @@
<?php declare(strict_types = 1);
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
class ApplicationNameTest extends TestCase {
public function testCanBeCreatedWithValidName() {
$this->assertInstanceOf(
ApplicationName::class,
new ApplicationName('foo/bar')
);
}
public function testUsingInvalidFormatForNameThrowsException() {
$this->expectException(InvalidApplicationNameException::class);
$this->expectExceptionCode(InvalidApplicationNameException::InvalidFormat);
new ApplicationName('foo');
}
public function testUsingWrongTypeForNameThrowsException() {
$this->expectException(InvalidApplicationNameException::class);
$this->expectExceptionCode(InvalidApplicationNameException::NotAString);
new ApplicationName(123);
}
public function testReturnsTrueForEqualNamesWhenCompared() {
$app = new ApplicationName('foo/bar');
$this->assertTrue(
$app->isEqual($app)
);
}
public function testReturnsFalseForNonEqualNamesWhenCompared() {
$app1 = new ApplicationName('foo/bar');
$app2 = new ApplicationName('foo/foo');
$this->assertFalse(
$app1->isEqual($app2)
);
}
public function testCanBeConvertedToString() {
$this->assertEquals(
'foo/bar',
new ApplicationName('foo/bar')
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\Application
* @covers PharIo\Manifest\Type
*/
class ApplicationTest extends TestCase {
/**
* @var Application
*/
private $type;
protected function setUp() {
$this->type = Type::application();
}
public function testCanBeCreated() {
$this->assertInstanceOf(Application::class, $this->type);
}
public function testIsApplication() {
$this->assertTrue($this->type->isApplication());
}
public function testIsNotLibrary() {
$this->assertFalse($this->type->isLibrary());
}
public function testIsNotExtension() {
$this->assertFalse($this->type->isExtension());
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Manifest\AuthorCollection
* @covers \PharIo\Manifest\AuthorCollectionIterator
*
* @uses \PharIo\Manifest\Author
* @uses \PharIo\Manifest\Email
*/
class AuthorCollectionTest extends TestCase {
/**
* @var AuthorCollection
*/
private $collection;
/**
* @var Author
*/
private $item;
protected function setUp() {
$this->collection = new AuthorCollection;
$this->item = new Author('Joe Developer', new Email('user@example.com'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(AuthorCollection::class, $this->collection);
}
public function testCanBeCounted() {
$this->collection->add($this->item);
$this->assertCount(1, $this->collection);
}
public function testCanBeIterated() {
$this->collection->add(
new Author('Dummy First', new Email('dummy@example.com'))
);
$this->collection->add($this->item);
$this->assertContains($this->item, $this->collection);
}
public function testKeyPositionCanBeRetreived() {
$this->collection->add($this->item);
foreach($this->collection as $key => $item) {
$this->assertEquals(0, $key);
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\Author
*
* @uses PharIo\Manifest\Email
*/
class AuthorTest extends TestCase {
/**
* @var Author
*/
private $author;
protected function setUp() {
$this->author = new Author('Joe Developer', new Email('user@example.com'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(Author::class, $this->author);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('Joe Developer', $this->author->getName());
}
public function testEmailCanBeRetrieved() {
$this->assertEquals('user@example.com', $this->author->getEmail());
}
public function testCanBeUsedAsString() {
$this->assertEquals('Joe Developer <user@example.com>', $this->author);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Manifest\BundledComponentCollection
* @covers \PharIo\Manifest\BundledComponentCollectionIterator
*
* @uses \PharIo\Manifest\BundledComponent
* @uses \PharIo\Version\Version
*/
class BundledComponentCollectionTest extends TestCase {
/**
* @var BundledComponentCollection
*/
private $collection;
/**
* @var BundledComponent
*/
private $item;
protected function setUp() {
$this->collection = new BundledComponentCollection;
$this->item = new BundledComponent('phpunit/php-code-coverage', new Version('4.0.2'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(BundledComponentCollection::class, $this->collection);
}
public function testCanBeCounted() {
$this->collection->add($this->item);
$this->assertCount(1, $this->collection);
}
public function testCanBeIterated() {
$this->collection->add($this->createMock(BundledComponent::class));
$this->collection->add($this->item);
$this->assertContains($this->item, $this->collection);
}
public function testKeyPositionCanBeRetreived() {
$this->collection->add($this->item);
foreach($this->collection as $key => $item) {
$this->assertEquals(0, $key);
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\BundledComponent
*
* @uses \PharIo\Version\Version
*/
class BundledComponentTest extends TestCase {
/**
* @var BundledComponent
*/
private $bundledComponent;
protected function setUp() {
$this->bundledComponent = new BundledComponent('phpunit/php-code-coverage', new Version('4.0.2'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(BundledComponent::class, $this->bundledComponent);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('phpunit/php-code-coverage', $this->bundledComponent->getName());
}
public function testVersionCanBeRetrieved() {
$this->assertEquals('4.0.2', $this->bundledComponent->getVersion()->getVersionString());
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\CopyrightInformation
*
* @uses PharIo\Manifest\AuthorCollection
* @uses PharIo\Manifest\AuthorCollectionIterator
* @uses PharIo\Manifest\Author
* @uses PharIo\Manifest\Email
* @uses PharIo\Manifest\License
* @uses PharIo\Manifest\Url
*/
class CopyrightInformationTest extends TestCase {
/**
* @var CopyrightInformation
*/
private $copyrightInformation;
/**
* @var Author
*/
private $author;
/**
* @var License
*/
private $license;
protected function setUp() {
$this->author = new Author('Joe Developer', new Email('user@example.com'));
$this->license = new License('BSD-3-Clause', new Url('https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE'));
$authors = new AuthorCollection;
$authors->add($this->author);
$this->copyrightInformation = new CopyrightInformation($authors, $this->license);
}
public function testCanBeCreated() {
$this->assertInstanceOf(CopyrightInformation::class, $this->copyrightInformation);
}
public function testAuthorsCanBeRetrieved() {
$this->assertContains($this->author, $this->copyrightInformation->getAuthors());
}
public function testLicenseCanBeRetrieved() {
$this->assertEquals($this->license, $this->copyrightInformation->getLicense());
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\Email
*/
class EmailTest extends TestCase {
public function testCanBeCreatedForValidEmail() {
$this->assertInstanceOf(Email::class, new Email('user@example.com'));
}
public function testCanBeUsedAsString() {
$this->assertEquals('user@example.com', new Email('user@example.com'));
}
/**
* @covers PharIo\Manifest\InvalidEmailException
*/
public function testCannotBeCreatedForInvalidEmail() {
$this->expectException(InvalidEmailException::class);
new Email('invalid');
}
}

View File

@@ -0,0 +1,109 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\AnyVersionConstraint;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraint;
use PharIo\Version\VersionConstraintParser;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Manifest\Extension
* @covers \PharIo\Manifest\Type
*
* @uses \PharIo\Version\VersionConstraint
* @uses \PharIo\Manifest\ApplicationName
*/
class ExtensionTest extends TestCase {
/**
* @var Extension
*/
private $type;
/**
* @var ApplicationName|\PHPUnit_Framework_MockObject_MockObject
*/
private $name;
protected function setUp() {
$this->name = $this->createMock(ApplicationName::class);
$this->type = Type::extension($this->name, new AnyVersionConstraint);
}
public function testCanBeCreated() {
$this->assertInstanceOf(Extension::class, $this->type);
}
public function testIsNotApplication() {
$this->assertFalse($this->type->isApplication());
}
public function testIsNotLibrary() {
$this->assertFalse($this->type->isLibrary());
}
public function testIsExtension() {
$this->assertTrue($this->type->isExtension());
}
public function testApplicationCanBeRetrieved()
{
$this->assertInstanceOf(ApplicationName::class, $this->type->getApplicationName());
}
public function testVersionConstraintCanBeRetrieved() {
$this->assertInstanceOf(
VersionConstraint::class,
$this->type->getVersionConstraint()
);
}
public function testApplicationCanBeQueried()
{
$this->name->method('isEqual')->willReturn(true);
$this->assertTrue(
$this->type->isExtensionFor($this->createMock(ApplicationName::class))
);
}
public function testCompatibleWithReturnsTrueForMatchingVersionConstraintAndApplicaiton() {
$app = new ApplicationName('foo/bar');
$extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
$version = new Version('1.0.0');
$this->assertTrue(
$extension->isCompatibleWith($app, $version)
);
}
public function testCompatibleWithReturnsFalseForNotMatchingVersionConstraint() {
$app = new ApplicationName('foo/bar');
$extension = Type::extension($app, (new VersionConstraintParser)->parse('^1.0'));
$version = new Version('2.0.0');
$this->assertFalse(
$extension->isCompatibleWith($app, $version)
);
}
public function testCompatibleWithReturnsFalseForNotMatchingApplication() {
$app1 = new ApplicationName('foo/bar');
$app2 = new ApplicationName('foo/foo');
$extension = Type::extension($app1, (new VersionConstraintParser)->parse('^1.0'));
$version = new Version('1.0.0');
$this->assertFalse(
$extension->isCompatibleWith($app2, $version)
);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\Library
* @covers PharIo\Manifest\Type
*/
class LibraryTest extends TestCase {
/**
* @var Library
*/
private $type;
protected function setUp() {
$this->type = Type::library();
}
public function testCanBeCreated() {
$this->assertInstanceOf(Library::class, $this->type);
}
public function testIsNotApplication() {
$this->assertFalse($this->type->isApplication());
}
public function testIsLibrary() {
$this->assertTrue($this->type->isLibrary());
}
public function testIsNotExtension() {
$this->assertFalse($this->type->isExtension());
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\License
*
* @uses PharIo\Manifest\Url
*/
class LicenseTest extends TestCase {
/**
* @var License
*/
private $license;
protected function setUp() {
$this->license = new License('BSD-3-Clause', new Url('https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(License::class, $this->license);
}
public function testNameCanBeRetrieved() {
$this->assertEquals('BSD-3-Clause', $this->license->getName());
}
public function testUrlCanBeRetrieved() {
$this->assertEquals('https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE', $this->license->getUrl());
}
}

View File

@@ -0,0 +1,187 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\Version;
use PharIo\Version\AnyVersionConstraint;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Manifest\Manifest
*
* @uses \PharIo\Manifest\ApplicationName
* @uses \PharIo\Manifest\Author
* @uses \PharIo\Manifest\AuthorCollection
* @uses \PharIo\Manifest\BundledComponent
* @uses \PharIo\Manifest\BundledComponentCollection
* @uses \PharIo\Manifest\CopyrightInformation
* @uses \PharIo\Manifest\Email
* @uses \PharIo\Manifest\License
* @uses \PharIo\Manifest\RequirementCollection
* @uses \PharIo\Manifest\PhpVersionRequirement
* @uses \PharIo\Manifest\Type
* @uses \PharIo\Manifest\Application
* @uses \PharIo\Manifest\Url
* @uses \PharIo\Version\Version
* @uses \PharIo\Version\VersionConstraint
*/
class ManifestTest extends TestCase {
/**
* @var ApplicationName
*/
private $name;
/**
* @var Version
*/
private $version;
/**
* @var Type
*/
private $type;
/**
* @var CopyrightInformation
*/
private $copyrightInformation;
/**
* @var RequirementCollection
*/
private $requirements;
/**
* @var BundledComponentCollection
*/
private $bundledComponents;
/**
* @var Manifest
*/
private $manifest;
protected function setUp() {
$this->version = new Version('5.6.5');
$this->type = Type::application();
$author = new Author('Joe Developer', new Email('user@example.com'));
$license = new License('BSD-3-Clause', new Url('https://github.com/sebastianbergmann/phpunit/blob/master/LICENSE'));
$authors = new AuthorCollection;
$authors->add($author);
$this->copyrightInformation = new CopyrightInformation($authors, $license);
$this->requirements = new RequirementCollection;
$this->requirements->add(new PhpVersionRequirement(new AnyVersionConstraint));
$this->bundledComponents = new BundledComponentCollection;
$this->bundledComponents->add(new BundledComponent('phpunit/php-code-coverage', new Version('4.0.2')));
$this->name = new ApplicationName('phpunit/phpunit');
$this->manifest = new Manifest(
$this->name,
$this->version,
$this->type,
$this->copyrightInformation,
$this->requirements,
$this->bundledComponents
);
}
public function testCanBeCreated() {
$this->assertInstanceOf(Manifest::class, $this->manifest);
}
public function testNameCanBeRetrieved() {
$this->assertEquals($this->name, $this->manifest->getName());
}
public function testVersionCanBeRetrieved() {
$this->assertEquals($this->version, $this->manifest->getVersion());
}
public function testTypeCanBeRetrieved() {
$this->assertEquals($this->type, $this->manifest->getType());
}
public function testTypeCanBeQueried() {
$this->assertTrue($this->manifest->isApplication());
$this->assertFalse($this->manifest->isLibrary());
$this->assertFalse($this->manifest->isExtension());
}
public function testCopyrightInformationCanBeRetrieved() {
$this->assertEquals($this->copyrightInformation, $this->manifest->getCopyrightInformation());
}
public function testRequirementsCanBeRetrieved() {
$this->assertEquals($this->requirements, $this->manifest->getRequirements());
}
public function testBundledComponentsCanBeRetrieved() {
$this->assertEquals($this->bundledComponents, $this->manifest->getBundledComponents());
}
/**
* @uses \PharIo\Manifest\Extension
*/
public function testExtendedApplicationCanBeQueriedForExtension()
{
$appName = new ApplicationName('foo/bar');
$manifest = new Manifest(
new ApplicationName('foo/foo'),
new Version('1.0.0'),
Type::extension($appName, new AnyVersionConstraint),
$this->copyrightInformation,
new RequirementCollection,
new BundledComponentCollection
);
$this->assertTrue($manifest->isExtensionFor($appName));
}
public function testNonExtensionReturnsFalseWhenQueriesForExtension() {
$appName = new ApplicationName('foo/bar');
$manifest = new Manifest(
new ApplicationName('foo/foo'),
new Version('1.0.0'),
Type::library(),
$this->copyrightInformation,
new RequirementCollection,
new BundledComponentCollection
);
$this->assertFalse($manifest->isExtensionFor($appName));
}
/**
* @uses \PharIo\Manifest\Extension
*/
public function testExtendedApplicationCanBeQueriedForExtensionWithVersion()
{
$appName = new ApplicationName('foo/bar');
$manifest = new Manifest(
new ApplicationName('foo/foo'),
new Version('1.0.0'),
Type::extension($appName, new AnyVersionConstraint),
$this->copyrightInformation,
new RequirementCollection,
new BundledComponentCollection
);
$this->assertTrue($manifest->isExtensionFor($appName, new Version('1.2.3')));
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\PhpExtensionRequirement
*/
class PhpExtensionRequirementTest extends TestCase {
public function testCanBeCreated() {
$this->assertInstanceOf(PhpExtensionRequirement::class, new PhpExtensionRequirement('dom'));
}
public function testCanBeUsedAsString() {
$this->assertEquals('dom', new PhpExtensionRequirement('dom'));
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\ExactVersionConstraint;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\PhpVersionRequirement
*
* @uses \PharIo\Version\VersionConstraint
*/
class PhpVersionRequirementTest extends TestCase {
/**
* @var PhpVersionRequirement
*/
private $requirement;
protected function setUp() {
$this->requirement = new PhpVersionRequirement(new ExactVersionConstraint('7.1.0'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(PhpVersionRequirement::class, $this->requirement);
}
public function testVersionConstraintCanBeRetrieved() {
$this->assertEquals('7.1.0', $this->requirement->getVersionConstraint()->asString());
}
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PharIo\Version\ExactVersionConstraint;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Manifest\RequirementCollection
* @covers \PharIo\Manifest\RequirementCollectionIterator
*
* @uses \PharIo\Manifest\PhpVersionRequirement
* @uses \PharIo\Version\VersionConstraint
*/
class RequirementCollectionTest extends TestCase {
/**
* @var RequirementCollection
*/
private $collection;
/**
* @var Requirement
*/
private $item;
protected function setUp() {
$this->collection = new RequirementCollection;
$this->item = new PhpVersionRequirement(new ExactVersionConstraint('7.1.0'));
}
public function testCanBeCreated() {
$this->assertInstanceOf(RequirementCollection::class, $this->collection);
}
public function testCanBeCounted() {
$this->collection->add($this->item);
$this->assertCount(1, $this->collection);
}
public function testCanBeIterated() {
$this->collection->add(new PhpVersionRequirement(new ExactVersionConstraint('5.6.0')));
$this->collection->add($this->item);
$this->assertContains($this->item, $this->collection);
}
public function testKeyPositionCanBeRetreived() {
$this->collection->add($this->item);
foreach($this->collection as $key => $item) {
$this->assertEquals(0, $key);
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Manifest;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Manifest\Url
*/
class UrlTest extends TestCase {
public function testCanBeCreatedForValidUrl() {
$this->assertInstanceOf(Url::class, new Url('https://phar.io/'));
}
public function testCanBeUsedAsString() {
$this->assertEquals('https://phar.io/', new Url('https://phar.io/'));
}
/**
* @covers PharIo\Manifest\InvalidUrlException
*/
public function testCannotBeCreatedForInvalidUrl() {
$this->expectException(InvalidUrlException::class);
new Url('invalid');
}
}

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());
}
}