pax_global_header00006660000000000000000000000064130570526030014513gustar00rootroot0000000000000052 comment=2df402786ab5368a0169091f61a7c1e0eb6852d0 manifest-1.0.1/000077500000000000000000000000001305705260300133205ustar00rootroot00000000000000manifest-1.0.1/.gitignore000066400000000000000000000001161305705260300153060ustar00rootroot00000000000000/.idea /.php_cs.cache /composer.lock /src/autoload.php /tools /vendor /build manifest-1.0.1/.php_cs000066400000000000000000000036251305705260300146030ustar00rootroot00000000000000files() ->in('src') ->in('tests') ->name('*.php'); return Symfony\CS\Config\Config::create() ->setUsingCache(true) ->level(\Symfony\CS\FixerInterface::NONE_LEVEL) ->fixers( array( 'align_double_arrow', 'align_equals', 'concat_with_spaces', 'duplicate_semicolon', 'elseif', 'empty_return', 'encoding', 'eof_ending', 'extra_empty_lines', 'function_call_space', 'function_declaration', 'indentation', 'join_function', 'line_after_namespace', 'linefeed', 'list_commas', 'lowercase_constants', 'lowercase_keywords', 'method_argument_space', 'multiple_use', 'namespace_no_leading_whitespace', 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'parenthesis', 'php_closing_tag', 'phpdoc_indent', 'phpdoc_no_access', 'phpdoc_no_empty_return', 'phpdoc_no_package', 'phpdoc_params', 'phpdoc_scalar', 'phpdoc_separation', 'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_types', 'phpdoc_var_without_name', 'remove_lines_between_uses', 'return', 'self_accessor', 'short_array_syntax', 'short_tag', 'single_line_after_imports', 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'ternary_spaces', 'trailing_spaces', 'trim_array_spaces', 'unused_use', 'visibility', 'whitespacy_lines' ) ) ->finder($finder); manifest-1.0.1/.travis.yml000066400000000000000000000010251305705260300154270ustar00rootroot00000000000000os: - linux language: php before_install: - wget https://phar.io/releases/phive.phar - wget https://phar.io/releases/phive.phar.asc - gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0x9B2D5D79 - gpg --verify phive.phar.asc phive.phar - chmod +x phive.phar - sudo mv phive.phar /usr/bin/phive install: - ant setup script: ./tools/phpunit php: - 5.6 - 7.0 - 7.1 - 7.0snapshot - 7.1snapshot - master matrix: allow_failures: - php: master fast_finish: true notifications: email: false manifest-1.0.1/LICENSE000066400000000000000000000031211305705260300143220ustar00rootroot00000000000000manifest Copyright (c) 2016 Arne Blankerts , Sebastian Heuer , Sebastian Bergmann , and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Arne Blankerts nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. manifest-1.0.1/README.md000066400000000000000000000023111305705260300145740ustar00rootroot00000000000000# Manifest Component for reading [phar.io](https://phar.io/) manifest information from a [PHP Archive (PHAR)](http://php.net/phar). [![Build Status](https://travis-ci.org/phar-io/manifest.svg?branch=master)](https://travis-ci.org/phar-io/manifest) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phar-io/manifest/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phar-io/manifest/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7/mini.png)](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7) ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): composer require phar-io/manifest If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: composer require --dev phar-io/manifest ## Usage ```php use PharIo\Manifest\ManifestLoader; use PharIo\Manifest\ManifestSerializer; $manifest = ManifestLoader::fromFile('manifest.xml'); var_dump($manifest); echo (new ManifestSerializer)->serializeToString($manifest); ``` manifest-1.0.1/build.xml000066400000000000000000000037601305705260300151470ustar00rootroot00000000000000 manifest-1.0.1/composer.json000066400000000000000000000015211305705260300160410ustar00rootroot00000000000000{ "name": "phar-io/manifest", "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "license": "BSD-3-Clause", "authors": [ { "name": "Arne Blankerts", "email": "arne@blankerts.de", "role": "Developer" }, { "name": "Sebastian Heuer", "email": "sebastian@phpeople.de", "role": "Developer" }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "Developer" } ], "support": { "issues": "https://github.com/phar-io/manifest/issues" }, "require": { "php": "^5.6 || ^7.0", "ext-dom": "*", "ext-phar": "*", "phar-io/version": "^1.0.1" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } } } manifest-1.0.1/examples/000077500000000000000000000000001305705260300151365ustar00rootroot00000000000000manifest-1.0.1/examples/example-01.php000066400000000000000000000013071305705260300175210ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PharIo\Manifest\ManifestLoader; use PharIo\Manifest\ManifestSerializer; require __DIR__ . '/../vendor/autoload.php'; $manifest = ManifestLoader::fromFile(__DIR__ . '/../tests/_fixture/phpunit-5.6.5.xml'); echo sprintf( "Manifest for %s (%s):\n\n", $manifest->getName(), $manifest->getVersion()->getVersionString() ); echo (new ManifestSerializer)->serializeToString($manifest); manifest-1.0.1/phive.xml000066400000000000000000000002541305705260300151560ustar00rootroot00000000000000 manifest-1.0.1/phpunit.xml000066400000000000000000000013461305705260300155350ustar00rootroot00000000000000 tests src manifest-1.0.1/src/000077500000000000000000000000001305705260300141075ustar00rootroot00000000000000manifest-1.0.1/src/ManifestDocumentMapper.php000066400000000000000000000132251305705260300212350ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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\Exception as VersionException; use PharIo\Version\VersionConstraintParser; class ManifestDocumentMapper { /** * @param ManifestDocument $document * * @returns Manifest * * @throws ManifestDocumentMapperException */ public function map(ManifestDocument $document) { try { $contains = $document->getContainsElement(); $type = $this->mapType($contains); $copyright = $this->mapCopyright($document->getCopyrightElement()); $requirements = $this->mapRequirements($document->getRequiresElement()); $bundledComponents = $this->mapBundledComponents($document); return new Manifest( new ApplicationName($contains->getName()), new Version($contains->getVersion()), $type, $copyright, $requirements, $bundledComponents ); } catch (VersionException $e) { throw new ManifestDocumentMapperException($e->getMessage(), $e->getCode(), $e); } catch (Exception $e) { throw new ManifestDocumentMapperException($e->getMessage(), $e->getCode(), $e); } } /** * @param ContainsElement $contains * * @return Type * * @throws ManifestDocumentMapperException */ private function mapType(ContainsElement $contains) { switch ($contains->getType()) { case 'application': return Type::application(); case 'library': return Type::library(); case 'extension': return $this->mapExtension($contains->getExtensionElement()); } throw new ManifestDocumentMapperException( sprintf('Unsupported type %s', $contains->getType()) ); } /** * @param CopyrightElement $copyright * * @return CopyrightInformation * * @throws InvalidUrlException * @throws InvalidEmailException */ private function mapCopyright(CopyrightElement $copyright) { $authors = new AuthorCollection(); foreach($copyright->getAuthorElements() as $authorElement) { $authors->add( new Author( $authorElement->getName(), new Email($authorElement->getEmail()) ) ); } $licenseElement = $copyright->getLicenseElement(); $license = new License( $licenseElement->getType(), new Url($licenseElement->getUrl()) ); return new CopyrightInformation( $authors, $license ); } /** * @param RequiresElement $requires * * @return RequirementCollection * * @throws ManifestDocumentMapperException */ private function mapRequirements(RequiresElement $requires) { $collection = new RequirementCollection(); $phpElement = $requires->getPHPElement(); $parser = new VersionConstraintParser; try { $versionConstraint = $parser->parse($phpElement->getVersion()); } catch (VersionException $e) { throw new ManifestDocumentMapperException( sprintf('Unsupported version constraint - %s', $e->getMessage()), $e->getCode(), $e ); } $collection->add( new PhpVersionRequirement( $versionConstraint ) ); if (!$phpElement->hasExtElements()) { return $collection; } foreach($phpElement->getExtElements() as $extElement) { $collection->add( new PhpExtensionRequirement($extElement->getName()) ); } return $collection; } /** * @param ManifestDocument $document * * @return BundledComponentCollection */ private function mapBundledComponents(ManifestDocument $document) { $collection = new BundledComponentCollection(); if (!$document->hasBundlesElement()) { return $collection; } foreach($document->getBundlesElement()->getComponentElements() as $componentElement) { $collection->add( new BundledComponent( $componentElement->getName(), new Version( $componentElement->getVersion() ) ) ); } return $collection; } /** * @param ExtensionElement $extension * * @return Extension * * @throws ManifestDocumentMapperException */ private function mapExtension(ExtensionElement $extension) { try { $parser = new VersionConstraintParser; $versionConstraint = $parser->parse($extension->getCompatible()); return Type::extension( new ApplicationName($extension->getFor()), $versionConstraint ); } catch (VersionException $e) { throw new ManifestDocumentMapperException( sprintf('Unsupported version constraint - %s', $e->getMessage()), $e->getCode(), $e ); } } } manifest-1.0.1/src/ManifestLoader.php000066400000000000000000000032101305705260300175110ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ManifestLoader { /** * @param string $filename * * @return Manifest * * @throws ManifestLoaderException */ public static function fromFile($filename) { try { return (new ManifestDocumentMapper())->map( ManifestDocument::fromFile($filename) ); } catch (Exception $e) { throw new ManifestLoaderException( sprintf('Loading %s failed.', $filename), $e->getCode(), $e ); } } /** * @param string $filename * * @return Manifest * * @throws ManifestLoaderException */ public static function fromPhar($filename) { return self::fromFile('phar://' . $filename . '/manifest.xml'); } /** * @param string $manifest * * @return Manifest * * @throws ManifestLoaderException */ public static function fromString($manifest) { try { return (new ManifestDocumentMapper())->map( ManifestDocument::fromString($manifest) ); } catch (Exception $e) { throw new ManifestLoaderException( 'Processing string failed', $e->getCode(), $e ); } } } manifest-1.0.1/src/ManifestSerializer.php000066400000000000000000000130171305705260300204220ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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 XMLWriter; class ManifestSerializer { /** * @var XMLWriter */ private $xmlWriter; public function serializeToFile(Manifest $manifest, $filename) { file_put_contents( $filename, $this->serializeToString($manifest) ); } public function serializeToString(Manifest $manifest) { $this->startDocument(); $this->addContains($manifest->getName(), $manifest->getVersion(), $manifest->getType()); $this->addCopyright($manifest->getCopyrightInformation()); $this->addRequirements($manifest->getRequirements()); $this->addBundles($manifest->getBundledComponents()); return $this->finishDocument(); } private function startDocument() { $xmlWriter = new XMLWriter(); $xmlWriter->openMemory(); $xmlWriter->setIndent(true); $xmlWriter->setIndentString(str_repeat(' ', 4)); $xmlWriter->startDocument('1.0', 'UTF-8'); $xmlWriter->startElement('phar'); $xmlWriter->writeAttribute('xmlns', 'https://phar.io/xml/manifest/1.0'); $this->xmlWriter = $xmlWriter; } private function finishDocument() { $this->xmlWriter->endElement(); $this->xmlWriter->endDocument(); return $this->xmlWriter->outputMemory(); } private function addContains($name, Version $version, Type $type) { $this->xmlWriter->startElement('contains'); $this->xmlWriter->writeAttribute('name', $name); $this->xmlWriter->writeAttribute('version', $version->getVersionString()); switch (true) { case $type->isApplication(): { $this->xmlWriter->writeAttribute('type', 'application'); break; } case $type->isLibrary(): { $this->xmlWriter->writeAttribute('type', 'library'); break; } case $type->isExtension(): { /* @var $type Extension */ $this->xmlWriter->writeAttribute('type', 'extension'); $this->addExtension($type->getApplicationName(), $type->getVersionConstraint()); break; } default: { $this->xmlWriter->writeAttribute('type', 'custom'); } } $this->xmlWriter->endElement(); } private function addCopyright(CopyrightInformation $copyrightInformation) { $this->xmlWriter->startElement('copyright'); foreach($copyrightInformation->getAuthors() as $author) { $this->xmlWriter->startElement('author'); $this->xmlWriter->writeAttribute('name', $author->getName()); $this->xmlWriter->writeAttribute('email', (string) $author->getEmail()); $this->xmlWriter->endElement(); } $license = $copyrightInformation->getLicense(); $this->xmlWriter->startElement('license'); $this->xmlWriter->writeAttribute('type', $license->getName()); $this->xmlWriter->writeAttribute('url', $license->getUrl()); $this->xmlWriter->endElement(); $this->xmlWriter->endElement(); } private function addRequirements(RequirementCollection $requirementCollection) { $phpRequirement = new AnyVersionConstraint(); $extensions = []; foreach($requirementCollection as $requirement) { if ($requirement instanceof PhpVersionRequirement) { $phpRequirement = $requirement->getVersionConstraint(); continue; } if ($requirement instanceof PhpExtensionRequirement) { $extensions[] = (string) $requirement; } } $this->xmlWriter->startElement('requires'); $this->xmlWriter->startElement('php'); $this->xmlWriter->writeAttribute('version', $phpRequirement->asString()); foreach($extensions as $extension) { $this->xmlWriter->startElement('ext'); $this->xmlWriter->writeAttribute('name', $extension); $this->xmlWriter->endElement(); } $this->xmlWriter->endElement(); $this->xmlWriter->endElement(); } private function addBundles(BundledComponentCollection $bundledComponentCollection) { if (count($bundledComponentCollection) === 0) { return; } $this->xmlWriter->startElement('bundles'); foreach($bundledComponentCollection as $bundledComponent) { $this->xmlWriter->startElement('component'); $this->xmlWriter->writeAttribute('name', $bundledComponent->getName()); $this->xmlWriter->writeAttribute('version', $bundledComponent->getVersion()->getVersionString()); $this->xmlWriter->endElement(); } $this->xmlWriter->endElement(); } private function addExtension($application, VersionConstraint $versionConstraint) { $this->xmlWriter->startElement('extension'); $this->xmlWriter->writeAttribute('for', $application); $this->xmlWriter->writeAttribute('compatible', $versionConstraint->asString()); $this->xmlWriter->endElement(); } } manifest-1.0.1/src/exceptions/000077500000000000000000000000001305705260300162705ustar00rootroot00000000000000manifest-1.0.1/src/exceptions/Exception.php000066400000000000000000000005561305705260300207450ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; interface Exception { } manifest-1.0.1/src/exceptions/InvalidApplicationNameException.php000066400000000000000000000007611305705260300252370ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class InvalidApplicationNameException extends \InvalidArgumentException implements Exception { const NotAString = 1; const InvalidFormat = 2; } manifest-1.0.1/src/exceptions/InvalidEmailException.php000066400000000000000000000006551305705260300232240ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class InvalidEmailException extends \InvalidArgumentException implements Exception { } manifest-1.0.1/src/exceptions/InvalidUrlException.php000066400000000000000000000006531305705260300227350ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class InvalidUrlException extends \InvalidArgumentException implements Exception { } manifest-1.0.1/src/exceptions/ManifestDocumentException.php000066400000000000000000000001661305705260300241300ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class Application extends Type { /** * @return bool */ public function isApplication() { return true; } } manifest-1.0.1/src/values/ApplicationName.php000066400000000000000000000031431305705260300211640ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ApplicationName { /** * @var string */ private $name; /** * ApplicationName constructor. * * @param string $name * * @throws InvalidApplicationNameException */ public function __construct($name) { $this->ensureIsString($name); $this->ensureValidFormat($name); $this->name = $name; } /** * @return string */ public function __toString() { return $this->name; } public function isEqual(ApplicationName $name) { return $this->name === $name->name; } /** * @param string $name * * @throws InvalidApplicationNameException */ private function ensureValidFormat($name) { if (!preg_match('#\w/\w#', $name)) { throw new InvalidApplicationNameException( sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name), InvalidApplicationNameException::InvalidFormat ); } } private function ensureIsString($name) { if (!is_string($name)) { throw new InvalidApplicationNameException( 'Name must be a string', InvalidApplicationNameException::NotAString ); } } } manifest-1.0.1/src/values/Author.php000066400000000000000000000020451305705260300173620ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class Author { /** * @var string */ private $name; /** * @var Email */ private $email; /** * @param string $name * @param Email $email */ public function __construct($name, Email $email) { $this->name = $name; $this->email = $email; } /** * @return string */ public function getName() { return $this->name; } /** * @return Email */ public function getEmail() { return $this->email; } /** * @return string */ public function __toString() { return sprintf( '%s <%s>', $this->name, $this->email ); } } manifest-1.0.1/src/values/AuthorCollection.php000066400000000000000000000016461305705260300214040ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class AuthorCollection implements \Countable, \IteratorAggregate { /** * @var Author[] */ private $authors = []; public function add(Author $author) { $this->authors[] = $author; } /** * @return Author[] */ public function getAuthors() { return $this->authors; } /** * @return int */ public function count() { return count($this->authors); } /** * @return AuthorCollectionIterator */ public function getIterator() { return new AuthorCollectionIterator($this); } } manifest-1.0.1/src/values/AuthorCollectionIterator.php000066400000000000000000000021411305705260300231050ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class AuthorCollectionIterator implements \Iterator { /** * @var Author[] */ private $authors = []; /** * @var int */ private $position; public function __construct(AuthorCollection $authors) { $this->authors = $authors->getAuthors(); } public function rewind() { $this->position = 0; } /** * @return bool */ public function valid() { return $this->position < count($this->authors); } /** * @return int */ public function key() { return $this->position; } /** * @return Author */ public function current() { return $this->authors[$this->position]; } public function next() { $this->position++; } } manifest-1.0.1/src/values/BundledComponent.php000066400000000000000000000016501305705260300213610ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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; class BundledComponent { /** * @var string */ private $name; /** * @var Version */ private $version; /** * @param string $name * @param Version $version */ public function __construct($name, Version $version) { $this->name = $name; $this->version = $version; } /** * @return string */ public function getName() { return $this->name; } /** * @return Version */ public function getVersion() { return $this->version; } } manifest-1.0.1/src/values/BundledComponentCollection.php000066400000000000000000000020501305705260300233700ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class BundledComponentCollection implements \Countable, \IteratorAggregate { /** * @var BundledComponent[] */ private $bundledComponents = []; public function add(BundledComponent $bundledComponent) { $this->bundledComponents[] = $bundledComponent; } /** * @return BundledComponent[] */ public function getBundledComponents() { return $this->bundledComponents; } /** * @return int */ public function count() { return count($this->bundledComponents); } /** * @return BundledComponentCollectionIterator */ public function getIterator() { return new BundledComponentCollectionIterator($this); } } manifest-1.0.1/src/values/BundledComponentCollectionIterator.php000066400000000000000000000023171305705260300251100ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class BundledComponentCollectionIterator implements \Iterator { /** * @var BundledComponent[] */ private $bundledComponents = []; /** * @var int */ private $position; public function __construct(BundledComponentCollection $bundledComponents) { $this->bundledComponents = $bundledComponents->getBundledComponents(); } public function rewind() { $this->position = 0; } /** * @return bool */ public function valid() { return $this->position < count($this->bundledComponents); } /** * @return int */ public function key() { return $this->position; } /** * @return BundledComponent */ public function current() { return $this->bundledComponents[$this->position]; } public function next() { $this->position++; } } manifest-1.0.1/src/values/CopyrightInformation.php000066400000000000000000000015701305705260300223000ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class CopyrightInformation { /** * @var AuthorCollection */ private $authors; /** * @var License */ private $license; public function __construct(AuthorCollection $authors, License $license) { $this->authors = $authors; $this->license = $license; } /** * @return AuthorCollection */ public function getAuthors() { return $this->authors; } /** * @return License */ public function getLicense() { return $this->license; } } manifest-1.0.1/src/values/Email.php000066400000000000000000000017441305705260300171540ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class Email { /** * @var string */ private $email; /** * @param string $email * * @throws InvalidEmailException */ public function __construct($email) { $this->ensureEmailIsValid($email); $this->email = $email; } /** * @return string */ public function __toString() { return $this->email; } /** * @param string $url * * @throws InvalidEmailException */ private function ensureEmailIsValid($url) { if (filter_var($url, \FILTER_VALIDATE_EMAIL) === false) { throw new InvalidEmailException; } } } manifest-1.0.1/src/values/Extension.php000066400000000000000000000033711305705260300200770ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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\VersionConstraint; class Extension extends Type { /** * @var ApplicationName */ private $application; /** * @var VersionConstraint */ private $versionConstraint; /** * @param ApplicationName $application * @param VersionConstraint $versionConstraint */ public function __construct(ApplicationName $application, VersionConstraint $versionConstraint) { $this->application = $application; $this->versionConstraint = $versionConstraint; } /** * @return ApplicationName */ public function getApplicationName() { return $this->application; } /** * @return VersionConstraint */ public function getVersionConstraint() { return $this->versionConstraint; } /** * @return bool */ public function isExtension() { return true; } /** * @param ApplicationName $name * * @return bool */ public function isExtensionFor(ApplicationName $name) { return $this->application->isEqual($name); } /** * @param ApplicationName $name * @param Version $version * * @return bool */ public function isCompatibleWith(ApplicationName $name, Version $version) { return $this->isExtensionFor($name) && $this->versionConstraint->complies($version); } } manifest-1.0.1/src/values/Library.php000066400000000000000000000007261305705260300175300ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class Library extends Type { /** * @return bool */ public function isLibrary() { return true; } } manifest-1.0.1/src/values/License.php000066400000000000000000000014211305705260300174770ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class License { /** * @var string */ private $name; /** * @var Url */ private $url; public function __construct($name, Url $url) { $this->name = $name; $this->url = $url; } /** * @return string */ public function getName() { return $this->name; } /** * @return Url */ public function getUrl() { return $this->url; } } manifest-1.0.1/src/values/Manifest.php000066400000000000000000000057011305705260300176700ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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; class Manifest { /** * @var ApplicationName */ private $name; /** * @var Version */ private $version; /** * @var Type */ private $type; /** * @var CopyrightInformation */ private $copyrightInformation; /** * @var RequirementCollection */ private $requirements; /** * @var BundledComponentCollection */ private $bundledComponents; public function __construct(ApplicationName $name, Version $version, Type $type, CopyrightInformation $copyrightInformation, RequirementCollection $requirements, BundledComponentCollection $bundledComponents) { $this->name = $name; $this->version = $version; $this->type = $type; $this->copyrightInformation = $copyrightInformation; $this->requirements = $requirements; $this->bundledComponents = $bundledComponents; } /** * @return ApplicationName */ public function getName() { return $this->name; } /** * @return Version */ public function getVersion() { return $this->version; } /** * @return Type */ public function getType() { return $this->type; } /** * @return CopyrightInformation */ public function getCopyrightInformation() { return $this->copyrightInformation; } /** * @return RequirementCollection */ public function getRequirements() { return $this->requirements; } /** * @return BundledComponentCollection */ public function getBundledComponents() { return $this->bundledComponents; } /** * @return bool */ public function isApplication() { return $this->type->isApplication(); } /** * @return bool */ public function isLibrary() { return $this->type->isLibrary(); } /** * @return bool */ public function isExtension() { return $this->type->isExtension(); } /** * @param ApplicationName $application * @param Version|null $version * * @return bool */ public function isExtensionFor(ApplicationName $application, Version $version = null) { if (!$this->isExtension()) { return false; } /** @var Extension $type */ $type = $this->type; if ($version !== null) { return $type->isCompatibleWith($application, $version); } return $type->isExtensionFor($application); } } manifest-1.0.1/src/values/PhpExtensionRequirement.php000066400000000000000000000013071305705260300227650ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class PhpExtensionRequirement implements Requirement { /** * @var string */ private $extension; /** * @param string $extension */ public function __construct($extension) { $this->extension = $extension; } /** * @return string */ public function __toString() { return $this->extension; } } manifest-1.0.1/src/values/PhpVersionRequirement.php000066400000000000000000000014261305705260300224400ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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\VersionConstraint; class PhpVersionRequirement implements Requirement { /** * @var VersionConstraint */ private $versionConstraint; public function __construct(VersionConstraint $versionConstraint) { $this->versionConstraint = $versionConstraint; } /** * @return VersionConstraint */ public function getVersionConstraint() { return $this->versionConstraint; } } manifest-1.0.1/src/values/Requirement.php000066400000000000000000000005601305705260300204200ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; interface Requirement { } manifest-1.0.1/src/values/RequirementCollection.php000066400000000000000000000017471305705260300224440ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class RequirementCollection implements \Countable, \IteratorAggregate { /** * @var Requirement[] */ private $requirements = []; public function add(Requirement $requirement) { $this->requirements[] = $requirement; } /** * @return Requirement[] */ public function getRequirements() { return $this->requirements; } /** * @return int */ public function count() { return count($this->requirements); } /** * @return RequirementCollectionIterator */ public function getIterator() { return new RequirementCollectionIterator($this); } } manifest-1.0.1/src/values/RequirementCollectionIterator.php000066400000000000000000000022301305705260300241420ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class RequirementCollectionIterator implements \Iterator { /** * @var Requirement[] */ private $requirements = []; /** * @var int */ private $position; public function __construct(RequirementCollection $requirements) { $this->requirements = $requirements->getRequirements(); } public function rewind() { $this->position = 0; } /** * @return bool */ public function valid() { return $this->position < count($this->requirements); } /** * @return int */ public function key() { return $this->position; } /** * @return Requirement */ public function current() { return $this->requirements[$this->position]; } public function next() { $this->position++; } } manifest-1.0.1/src/values/Type.php000066400000000000000000000023631305705260300170440ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * 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\VersionConstraint; abstract class Type { /** * @return Application */ public static function application() { return new Application; } /** * @return Library */ public static function library() { return new Library; } /** * @param ApplicationName $application * @param VersionConstraint $versionConstraint * * @return Extension */ public static function extension(ApplicationName $application, VersionConstraint $versionConstraint) { return new Extension($application, $versionConstraint); } /** * @return bool */ public function isApplication() { return false; } /** * @return bool */ public function isLibrary() { return false; } /** * @return bool */ public function isExtension() { return false; } } manifest-1.0.1/src/values/Url.php000066400000000000000000000017101305705260300166600ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class Url { /** * @var string */ private $url; /** * @param string $url * * @throws InvalidUrlException */ public function __construct($url) { $this->ensureUrlIsValid($url); $this->url = $url; } /** * @return string */ public function __toString() { return $this->url; } /** * @param string $url * * @throws InvalidUrlException */ private function ensureUrlIsValid($url) { if (filter_var($url, \FILTER_VALIDATE_URL) === false) { throw new InvalidUrlException; } } } manifest-1.0.1/src/xml/000077500000000000000000000000001305705260300147075ustar00rootroot00000000000000manifest-1.0.1/src/xml/AuthorElement.php000066400000000000000000000010671305705260300202000ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class AuthorElement extends ManifestElement { public function getName() { return $this->getAttributeValue('name'); } public function getEmail() { return $this->getAttributeValue('email'); } } manifest-1.0.1/src/xml/AuthorElementCollection.php000066400000000000000000000010141305705260300222040ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class AuthorElementCollection extends ElementCollection { public function current() { return new AuthorElement( $this->getCurrentElement() ); } } manifest-1.0.1/src/xml/BundlesElement.php000066400000000000000000000010461305705260300203270ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class BundlesElement extends ManifestElement { public function getComponentElements() { return new ComponentElementCollection( $this->getChildrenByName('component') ); } } manifest-1.0.1/src/xml/ComponentElement.php000066400000000000000000000010761305705260300207000ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ComponentElement extends ManifestElement { public function getName() { return $this->getAttributeValue('name'); } public function getVersion() { return $this->getAttributeValue('version'); } } manifest-1.0.1/src/xml/ComponentElementCollection.php000066400000000000000000000010221305705260300227030ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ComponentElementCollection extends ElementCollection { public function current() { return new ComponentElement( $this->getCurrentElement() ); } } manifest-1.0.1/src/xml/ContainsElement.php000066400000000000000000000014471305705260300205160ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ContainsElement extends ManifestElement { public function getName() { return $this->getAttributeValue('name'); } public function getVersion() { return $this->getAttributeValue('version'); } public function getType() { return $this->getAttributeValue('type'); } public function getExtensionElement() { return new ExtensionElement( $this->getChildByName('extension') ); } } manifest-1.0.1/src/xml/CopyrightElement.php000066400000000000000000000012531305705260300207030ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class CopyrightElement extends ManifestElement { public function getAuthorElements() { return new AuthorElementCollection( $this->getChildrenByName('author') ); } public function getLicenseElement() { return new LicenseElement( $this->getChildByName('license') ); } } manifest-1.0.1/src/xml/ElementCollection.php000066400000000000000000000023161305705260300210270ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; use DOMElement; use DOMNodeList; abstract class ElementCollection implements \Iterator { /** * @var DOMNodeList */ private $nodeList; private $position; /** * ElementCollection constructor. * * @param DOMNodeList $nodeList */ public function __construct(DOMNodeList $nodeList) { $this->nodeList = $nodeList; $this->position = 0; } abstract public function current(); /** * @return DOMElement */ protected function getCurrentElement() { return $this->nodeList->item($this->position); } public function next() { $this->position++; } public function key() { return $this->position; } public function valid() { return $this->position < $this->nodeList->length; } public function rewind() { $this->position = 0; } } manifest-1.0.1/src/xml/ExtElement.php000066400000000000000000000007321305705260300174740ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ExtElement extends ManifestElement { public function getName() { return $this->getAttributeValue('name'); } } manifest-1.0.1/src/xml/ExtElementCollection.php000066400000000000000000000010071305705260300215040ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ExtElementCollection extends ElementCollection { public function current() { return new ExtElement( $this->getCurrentElement() ); } } manifest-1.0.1/src/xml/ExtensionElement.php000066400000000000000000000011021305705260300207000ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class ExtensionElement extends ManifestElement { public function getFor() { return $this->getAttributeValue('for'); } public function getCompatible() { return $this->getAttributeValue('compatible'); } } manifest-1.0.1/src/xml/LicenseElement.php000066400000000000000000000010641305705260300203150ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class LicenseElement extends ManifestElement { public function getType() { return $this->getAttributeValue('type'); } public function getUrl() { return $this->getAttributeValue('url'); } } manifest-1.0.1/src/xml/ManifestDocument.php000066400000000000000000000056631305705260300206770ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; use DOMDocument; use DOMElement; class ManifestDocument { const XMLNS = 'https://phar.io/xml/manifest/1.0'; /** * @var DOMDocument */ private $dom; /** * ManifestDocument constructor. * * @param DOMDocument $dom */ private function __construct(DOMDocument $dom) { $this->ensureCorrectDocumentType($dom); $this->dom = $dom; } public static function fromFile($filename) { if (!file_exists($filename)) { throw new ManifestDocumentException( sprintf('File "%s" not found', $filename) ); } return self::fromString( file_get_contents($filename) ); } public static function fromString($xmlString) { $prev = libxml_use_internal_errors(true); libxml_clear_errors(); $dom = new DOMDocument(); $dom->loadXML($xmlString); $errors = libxml_get_errors(); libxml_use_internal_errors($prev); if (count($errors) !== 0) { throw new ManifestDocumentLoadingException($errors); } return new self($dom); } public function getContainsElement() { return new ContainsElement( $this->fetchElementByName('contains') ); } public function getCopyrightElement() { return new CopyrightElement( $this->fetchElementByName('copyright') ); } public function getRequiresElement() { return new RequiresElement( $this->fetchElementByName('requires') ); } public function hasBundlesElement() { return $this->dom->getElementsByTagNameNS(self::XMLNS, 'bundles')->length === 1; } public function getBundlesElement() { return new BundlesElement( $this->fetchElementByName('bundles') ); } private function ensureCorrectDocumentType(DOMDocument $dom) { $root = $dom->documentElement; if ($root->localName !== 'phar' || $root->namespaceURI !== self::XMLNS) { throw new ManifestDocumentException('Not a phar.io manifest document'); } } /** * @param $elementName * * @return DOMElement * * @throws ManifestDocumentException */ private function fetchElementByName($elementName) { $element = $this->dom->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0); if (!$element instanceof DOMElement) { throw new ManifestDocumentException( sprintf('Element %s missing', $elementName) ); } return $element; } } manifest-1.0.1/src/xml/ManifestDocumentLoadingException.php000066400000000000000000000022621305705260300240440ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; use LibXMLError; class ManifestDocumentLoadingException extends \Exception implements Exception { /** * @var LibXMLError[] */ private $libxmlErrors; /** * ManifestDocumentLoadingException constructor. * * @param LibXMLError[] $libxmlErrors */ public function __construct(array $libxmlErrors) { $this->libxmlErrors = $libxmlErrors; $first = $this->libxmlErrors[0]; parent::__construct( sprintf( '%s (Line: %d / Column: %d / File: %s)', $first->message, $first->line, $first->column, $first->file ), $first->code ); } /** * @return LibXMLError[] */ public function getLibxmlErrors() { return $this->libxmlErrors; } } manifest-1.0.1/src/xml/ManifestElement.php000066400000000000000000000046051305705260300205050ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; use DOMElement; use DOMNodeList; class ManifestElement { const XMLNS = 'https://phar.io/xml/manifest/1.0'; /** * @var DOMElement */ private $element; /** * ContainsElement constructor. * * @param DOMElement $element */ public function __construct(DOMElement $element) { $this->element = $element; } /** * @param string $name * * @return string * * @throws ManifestElementException */ protected function getAttributeValue($name) { if (!$this->element->hasAttribute($name)) { throw new ManifestElementException( sprintf( 'Attribute %s not set on element %s', $name, $this->element->localName ) ); } return $this->element->getAttribute($name); } /** * @param $elementName * * @return DOMElement * * @throws ManifestElementException */ protected function getChildByName($elementName) { $element = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0); if (!$element instanceof DOMElement) { throw new ManifestElementException( sprintf('Element %s missing', $elementName) ); } return $element; } /** * @param $elementName * * @return DOMNodeList * * @throws ManifestElementException */ protected function getChildrenByName($elementName) { $elementList = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName); if ($elementList->length === 0) { throw new ManifestElementException( sprintf('Element(s) %s missing', $elementName) ); } return $elementList; } /** * @param string $elementName * * @return bool */ protected function hasChild($elementName) { return $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->length !== 0; } } manifest-1.0.1/src/xml/PhpElement.php000066400000000000000000000013031305705260300174560ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class PhpElement extends ManifestElement { public function getVersion() { return $this->getAttributeValue('version'); } public function hasExtElements() { return $this->hasChild('ext'); } public function getExtElements() { return new ExtElementCollection( $this->getChildrenByName('ext') ); } } manifest-1.0.1/src/xml/RequiresElement.php000066400000000000000000000010071305705260300205270ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; class RequiresElement extends ManifestElement { public function getPHPElement() { return new PhpElement( $this->getChildByName('php') ); } } manifest-1.0.1/tests/000077500000000000000000000000001305705260300144625ustar00rootroot00000000000000manifest-1.0.1/tests/ManifestDocumentMapperTest.php000066400000000000000000000100031305705260300224370ustar00rootroot00000000000000assertInstanceOf( 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); } } manifest-1.0.1/tests/ManifestLoaderTest.php000066400000000000000000000054071305705260300207360ustar00rootroot00000000000000assertInstanceOf( 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(''); } } manifest-1.0.1/tests/ManifestSerializerTest.php000066400000000000000000000075331305705260300216430ustar00rootroot00000000000000assertXmlStringEqualsXmlString( $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) ); } } manifest-1.0.1/tests/_fixture/000077500000000000000000000000001305705260300163075ustar00rootroot00000000000000manifest-1.0.1/tests/_fixture/custom.xml000066400000000000000000000004721305705260300203460ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/extension-invalidcompatible.xml000066400000000000000000000010571305705260300245340ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/extension.xml000066400000000000000000000010541305705260300210450ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/invalidversion.xml000066400000000000000000000006061305705260300220670ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/invalidversionconstraint.xml000066400000000000000000000006141305705260300241730ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/library.xml000066400000000000000000000006101305705260300204720ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/manifest.xml000066400000000000000000000006101305705260300206340ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/phpunit-5.6.5.xml000066400000000000000000000046331305705260300211770ustar00rootroot00000000000000 manifest-1.0.1/tests/_fixture/test.phar000066400000000000000000000157751305705260300201610ustar00rootroot00000000000000 2, 'c' => 'text/plain', 'cc' => 'text/plain', 'cpp' => 'text/plain', 'c++' => 'text/plain', 'dtd' => 'text/plain', 'h' => 'text/plain', 'log' => 'text/plain', 'rng' => 'text/plain', 'txt' => 'text/plain', 'xsd' => 'text/plain', 'php' => 1, 'inc' => 1, 'avi' => 'video/avi', 'bmp' => 'image/bmp', 'css' => 'text/css', 'gif' => 'image/gif', 'htm' => 'text/html', 'html' => 'text/html', 'htmls' => 'text/html', 'ico' => 'image/x-ico', 'jpe' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'js' => 'application/x-javascript', 'midi' => 'audio/midi', 'mid' => 'audio/midi', 'mod' => 'audio/mod', 'mov' => 'movie/quicktime', 'mp3' => 'audio/mp3', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'pdf' => 'application/pdf', 'png' => 'image/png', 'swf' => 'application/shockwave-flash', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'wav' => 'audio/wav', 'xbm' => 'image/xbm', 'xml' => 'text/xml', ); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); $basename = basename(__FILE__); if (!strpos($_SERVER['REQUEST_URI'], $basename)) { chdir(Extract_Phar::$temp); include $web; return; } $pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename)); if (!$pt || $pt == '/') { $pt = $web; header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt); exit; } $a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt); if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) { header('HTTP/1.0 404 Not Found'); echo "\n \n File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>"; exit; } $b = pathinfo($a); if (!isset($b['extension'])) { header('Content-Type: text/plain'); header('Content-Length: ' . filesize($a)); readfile($a); exit; } if (isset($mimes[$b['extension']])) { if ($mimes[$b['extension']] === 1) { include $a; exit; } if ($mimes[$b['extension']] === 2) { highlight_file($a); exit; } header('Content-Type: ' .$mimes[$b['extension']]); header('Content-Length: ' . filesize($a)); readfile($a); exit; } } class Extract_Phar { static $temp; static $origdir; const GZ = 0x1000; const BZ2 = 0x2000; const MASK = 0x3000; const START = 'index.php'; const LEN = 6685; static function go($return = false) { $fp = fopen(__FILE__, 'rb'); fseek($fp, self::LEN); $L = unpack('V', $a = (binary)fread($fp, 4)); $m = (binary)''; do { $read = 8192; if ($L[1] - strlen($m) < 8192) { $read = $L[1] - strlen($m); } $last = (binary)fread($fp, $read); $m .= $last; } while (strlen($last) && strlen($m) < $L[1]); if (strlen($m) < $L[1]) { die('ERROR: manifest length read was "' . strlen($m) .'" should be "' . $L[1] . '"'); } $info = self::_unpack($m); $f = $info['c']; if ($f & self::GZ) { if (!function_exists('gzinflate')) { die('Error: zlib extension is not enabled -' . ' gzinflate() function needed for zlib-compressed .phars'); } } if ($f & self::BZ2) { if (!function_exists('bzdecompress')) { die('Error: bzip2 extension is not enabled -' . ' bzdecompress() function needed for bz2-compressed .phars'); } } $temp = self::tmpdir(); if (!$temp || !is_writable($temp)) { $sessionpath = session_save_path(); if (strpos ($sessionpath, ";") !== false) $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); if (!file_exists($sessionpath) || !is_dir($sessionpath)) { die('Could not locate temporary directory to extract phar'); } $temp = $sessionpath; } $temp .= '/pharextract/'.basename(__FILE__, '.phar'); self::$temp = $temp; self::$origdir = getcwd(); @mkdir($temp, 0777, true); $temp = realpath($temp); if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) { self::_removeTmpFiles($temp, getcwd()); @mkdir($temp, 0777, true); @file_put_contents($temp . '/' . md5_file(__FILE__), ''); foreach ($info['m'] as $path => $file) { $a = !file_exists(dirname($temp . '/' . $path)); @mkdir(dirname($temp . '/' . $path), 0777, true); clearstatcache(); if ($path[strlen($path) - 1] == '/') { @mkdir($temp . '/' . $path, 0777); } else { file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); @chmod($temp . '/' . $path, 0666); } } } chdir($temp); if (!$return) { include self::START; } } static function tmpdir() { if (strpos(PHP_OS, 'WIN') !== false) { if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) { return $var; } if (is_dir('/temp') || mkdir('/temp')) { return realpath('/temp'); } return false; } if ($var = getenv('TMPDIR')) { return $var; } return realpath('/tmp'); } static function _unpack($m) { $info = unpack('V', substr($m, 0, 4)); $l = unpack('V', substr($m, 10, 4)); $m = substr($m, 14 + $l[1]); $s = unpack('V', substr($m, 0, 4)); $o = 0; $start = 4 + $s[1]; $ret['c'] = 0; for ($i = 0; $i < $info[1]; $i++) { $len = unpack('V', substr($m, $start, 4)); $start += 4; $savepath = substr($m, $start, $len[1]); $start += $len[1]; $ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24))); $ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3] & 0xffffffff); $ret['m'][$savepath][7] = $o; $o += $ret['m'][$savepath][2]; $start += 24 + $ret['m'][$savepath][5]; $ret['c'] |= $ret['m'][$savepath][4] & self::MASK; } return $ret; } static function extractFile($path, $entry, $fp) { $data = ''; $c = $entry[2]; while ($c) { if ($c < 8192) { $data .= @fread($fp, $c); $c = 0; } else { $c -= 8192; $data .= @fread($fp, 8192); } } if ($entry[4] & self::GZ) { $data = gzinflate($data); } elseif ($entry[4] & self::BZ2) { $data = bzdecompress($data); } if (strlen($data) != $entry[0]) { die("Invalid internal .phar file (size error " . strlen($data) . " != " . $stat[7] . ")"); } if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) { die("Invalid internal .phar file (checksum error)"); } return $data; } static function _removeTmpFiles($temp, $origdir) { chdir($temp); foreach (glob('*') as $f) { if (file_exists($f)) { is_dir($f) ? @rmdir($f) : @unlink($f); if (file_exists($f) && is_dir($f)) { self::_removeTmpFiles($f, getcwd()); } } } @rmdir($temp); clearstatcache(); chdir($origdir); } } Extract_Phar::go(); __HALT_COMPILER(); ?>:������������������ ���manifest.xmlˆ��'…;Xˆ��vyP§¶������<?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> !7]O>èaá~^ÐïY¸àÞy³���GBMB���manifest-1.0.1/tests/exceptions/��������������������������������������������������������������������0000775�0000000�0000000�00000000000�13057052603�0016643�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/exceptions/ManifestDocumentLoadingExceptionTest.php����������������������������0000664�0000000�0000000�00000001077�13057052603�0026643�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/������������������������������������������������������������������������0000775�0000000�0000000�00000000000�13057052603�0015761�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/ApplicationNameTest.php�������������������������������������������������0000664�0000000�0000000�00000002652�13057052603�0022403�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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') ); } } ��������������������������������������������������������������������������������������manifest-1.0.1/tests/values/ApplicationTest.php�����������������������������������������������������0000664�0000000�0000000�00000002053�13057052603�0021575�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/AuthorCollectionTest.php������������������������������������������������0000664�0000000�0000000�00000003163�13057052603�0022613�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/AuthorTest.php����������������������������������������������������������0000664�0000000�0000000�00000002222�13057052603�0020572�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/BundledComponentCollectionTest.php��������������������������������������0000664�0000000�0000000�00000003312�13057052603�0024605�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/BundledComponentTest.php������������������������������������������������0000664�0000000�0000000�00000002253�13057052603�0022574�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/CopyrightInformationTest.php��������������������������������������������0000664�0000000�0000000�00000003340�13057052603�0023510�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/EmailTest.php�����������������������������������������������������������0000664�0000000�0000000�00000001670�13057052603�0020365�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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'); } } ������������������������������������������������������������������������manifest-1.0.1/tests/values/ExtensionTest.php�������������������������������������������������������0000664�0000000�0000000�00000006274�13057052603�0021317�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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) ); } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/LibraryTest.php���������������������������������������������������������0000664�0000000�0000000�00000002027�13057052603�0020737�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/LicenseTest.php���������������������������������������������������������0000664�0000000�0000000�00000002155�13057052603�0020717�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/ManifestTest.php��������������������������������������������������������0000664�0000000�0000000�00000012730�13057052603�0021103�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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'))); } } ����������������������������������������manifest-1.0.1/tests/values/PhpExtensionRequirementTest.php�����������������������������������������0000664�0000000�0000000�00000001372�13057052603�0024202�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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')); } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/PhpVersionRequirementTest.php�������������������������������������������0000664�0000000�0000000�00000002063�13057052603�0023651�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/RequirementCollectionTest.php�������������������������������������������0000664�0000000�0000000�00000003320�13057052603�0023644�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/values/UrlTest.php�������������������������������������������������������������0000664�0000000�0000000�00000001644�13057052603�0020101�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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'); } } ��������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/���������������������������������������������������������������������������0000775�0000000�0000000�00000000000�13057052603�0015262�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/AuthorElementCollectionTest.php��������������������������������������������0000664�0000000�0000000�00000001114�13057052603�0023420�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/AuthorElementTest.php������������������������������������������������������0000664�0000000�0000000�00000001303�13057052603�0021404�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/BundlesElementTest.php�����������������������������������������������������0000664�0000000�0000000�00000002212�13057052603�0021536�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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') ); } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ComponentElementCollectionTest.php�����������������������������������������0000664�0000000�0000000�00000001063�13057052603�0024123�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ComponentElementTest.php���������������������������������������������������0000664�0000000�0000000�00000001311�13057052603�0022103�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ContainsElementTest.php����������������������������������������������������0000664�0000000�0000000�00000003763�13057052603�0021734�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �������������manifest-1.0.1/tests/xml/CopyrightElementTest.php���������������������������������������������������0000664�0000000�0000000�00000003135�13057052603�0022117�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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() ); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ExtElementCollectionTest.php�����������������������������������������������0000664�0000000�0000000�00000001113�13057052603�0022715�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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); } } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ExtElementTest.php���������������������������������������������������������0000664�0000000�0000000�00000000776�13057052603�0020717�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } ��manifest-1.0.1/tests/xml/ExtensionElementTest.php���������������������������������������������������0000664�0000000�0000000�00000001341�13057052603�0022120�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/LicenseElementTest.php�����������������������������������������������������0000664�0000000�0000000�00000001305�13057052603�0021526�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/ManifestDocumentTest.php���������������������������������������������������0000664�0000000�0000000�00000007200�13057052603�0022077�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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" />' ); } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/PhpElementTest.php���������������������������������������������������������0000664�0000000�0000000�00000002512�13057052603�0020674�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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') ); } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������manifest-1.0.1/tests/xml/RequiresElementTest.php����������������������������������������������������0000664�0000000�0000000�00000002005�13057052603�0021741�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<?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()); } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������