1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Manifest.
*
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PharIo\Manifest;
use function file_get_contents;
class ManifestDocumentTest extends \PHPUnit\Framework\TestCase {
public function testThrowsExceptionWhenFileDoesNotExist(): void {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromFile('/does/not/exist');
}
public function testCanBeCreatedFromFile(): void {
$this->assertInstanceOf(
ManifestDocument::class,
ManifestDocument::fromFile(__DIR__ . '/../_fixture/phpunit-5.6.5.xml')
);
}
public function testFromStringThrowsExceptionOnEmptyString(): void {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromString('');
}
public function testCanBeConstructedFromString(): void {
$content = file_get_contents(__DIR__ . '/../_fixture/phpunit-5.6.5.xml');
$this->assertInstanceOf(
ManifestDocument::class,
ManifestDocument::fromString($content)
);
}
public function testThrowsExceptionOnInvalidXML(): void {
$this->expectException(ManifestDocumentLoadingException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><root>');
}
public function testLoadingDocumentWithWrongRootNameThrowsException(): void {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><root />');
}
public function testLoadingDocumentWithWrongNamespaceThrowsException(): void {
$this->expectException(ManifestDocumentException::class);
ManifestDocument::fromString('<?xml version="1.0" ?><phar xmlns="foo:bar" />');
}
public function testContainsElementCanBeRetrieved(): void {
$this->assertInstanceOf(
ContainsElement::class,
$this->loadFixture()->getContainsElement()
);
}
public function testRequiresElementCanBeRetrieved(): void {
$this->assertInstanceOf(
RequiresElement::class,
$this->loadFixture()->getRequiresElement()
);
}
public function testCopyrightElementCanBeRetrieved(): void {
$this->assertInstanceOf(
CopyrightElement::class,
$this->loadFixture()->getCopyrightElement()
);
}
public function testBundlesElementCanBeRetrieved(): void {
$this->assertInstanceOf(
BundlesElement::class,
$this->loadFixture()->getBundlesElement()
);
}
public function testThrowsExceptionWhenContainsIsMissing(): void {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getContainsElement();
}
public function testThrowsExceptionWhenCopyirhgtIsMissing(): void {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getCopyrightElement();
}
public function testThrowsExceptionWhenRequiresIsMissing(): void {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getRequiresElement();
}
public function testThrowsExceptionWhenBundlesIsMissing(): void {
$this->expectException(ManifestDocumentException::class);
$this->loadEmptyFixture()->getBundlesElement();
}
public function testHasBundlesReturnsTrueWhenBundlesNodeIsPresent(): void {
$this->assertTrue(
$this->loadFixture()->hasBundlesElement()
);
}
public function testHasBundlesReturnsFalseWhenBundlesNoNodeIsPresent(): void {
$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" />'
);
}
}
|