annotate vendor/phar-io/manifest/tests/xml/ManifestDocumentTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents 5311817fb629
children
rev   line source
Chris@2 1 <?php
Chris@2 2
Chris@2 3 namespace PharIo\Manifest;
Chris@2 4
Chris@2 5 class ManifestDocumentTest extends \PHPUnit_Framework_TestCase {
Chris@2 6 public function testThrowsExceptionWhenFileDoesNotExist() {
Chris@2 7 $this->expectException(ManifestDocumentException::class);
Chris@2 8 ManifestDocument::fromFile('/does/not/exist');
Chris@2 9 }
Chris@2 10
Chris@2 11 public function testCanBeCreatedFromFile() {
Chris@2 12 $this->assertInstanceOf(
Chris@2 13 ManifestDocument::class,
Chris@2 14 ManifestDocument::fromFile(__DIR__ . '/../_fixture/phpunit-5.6.5.xml')
Chris@2 15 );
Chris@2 16 }
Chris@2 17
Chris@2 18 public function testCaneBeConstructedFromString() {
Chris@2 19 $content = file_get_contents(__DIR__ . '/../_fixture/phpunit-5.6.5.xml');
Chris@2 20 $this->assertInstanceOf(
Chris@2 21 ManifestDocument::class,
Chris@2 22 ManifestDocument::fromString($content)
Chris@2 23 );
Chris@2 24 }
Chris@2 25
Chris@2 26 public function testThrowsExceptionOnInvalidXML() {
Chris@2 27 $this->expectException(ManifestDocumentLoadingException::class);
Chris@2 28 ManifestDocument::fromString('<?xml version="1.0" ?><root>');
Chris@2 29 }
Chris@2 30
Chris@2 31 public function testLoadingDocumentWithWrongRootNameThrowsException() {
Chris@2 32 $this->expectException(ManifestDocumentException::class);
Chris@2 33 ManifestDocument::fromString('<?xml version="1.0" ?><root />');
Chris@2 34 }
Chris@2 35
Chris@2 36 public function testLoadingDocumentWithWrongNamespaceThrowsException() {
Chris@2 37 $this->expectException(ManifestDocumentException::class);
Chris@2 38 ManifestDocument::fromString('<?xml version="1.0" ?><phar xmlns="foo:bar" />');
Chris@2 39 }
Chris@2 40
Chris@2 41 public function testContainsElementCanBeRetrieved() {
Chris@2 42 $this->assertInstanceOf(
Chris@2 43 ContainsElement::class,
Chris@2 44 $this->loadFixture()->getContainsElement()
Chris@2 45 );
Chris@2 46 }
Chris@2 47
Chris@2 48 public function testRequiresElementCanBeRetrieved() {
Chris@2 49 $this->assertInstanceOf(
Chris@2 50 RequiresElement::class,
Chris@2 51 $this->loadFixture()->getRequiresElement()
Chris@2 52 );
Chris@2 53 }
Chris@2 54
Chris@2 55 public function testCopyrightElementCanBeRetrieved() {
Chris@2 56 $this->assertInstanceOf(
Chris@2 57 CopyrightElement::class,
Chris@2 58 $this->loadFixture()->getCopyrightElement()
Chris@2 59 );
Chris@2 60 }
Chris@2 61
Chris@2 62 public function testBundlesElementCanBeRetrieved() {
Chris@2 63 $this->assertInstanceOf(
Chris@2 64 BundlesElement::class,
Chris@2 65 $this->loadFixture()->getBundlesElement()
Chris@2 66 );
Chris@2 67 }
Chris@2 68
Chris@2 69 public function testThrowsExceptionWhenContainsIsMissing() {
Chris@2 70 $this->expectException(ManifestDocumentException::class);
Chris@2 71 $this->loadEmptyFixture()->getContainsElement();
Chris@2 72 }
Chris@2 73
Chris@2 74 public function testThrowsExceptionWhenCopyirhgtIsMissing() {
Chris@2 75 $this->expectException(ManifestDocumentException::class);
Chris@2 76 $this->loadEmptyFixture()->getCopyrightElement();
Chris@2 77 }
Chris@2 78
Chris@2 79 public function testThrowsExceptionWhenRequiresIsMissing() {
Chris@2 80 $this->expectException(ManifestDocumentException::class);
Chris@2 81 $this->loadEmptyFixture()->getRequiresElement();
Chris@2 82 }
Chris@2 83
Chris@2 84 public function testThrowsExceptionWhenBundlesIsMissing() {
Chris@2 85 $this->expectException(ManifestDocumentException::class);
Chris@2 86 $this->loadEmptyFixture()->getBundlesElement();
Chris@2 87 }
Chris@2 88
Chris@2 89 public function testHasBundlesReturnsTrueWhenBundlesNodeIsPresent() {
Chris@2 90 $this->assertTrue(
Chris@2 91 $this->loadFixture()->hasBundlesElement()
Chris@2 92 );
Chris@2 93 }
Chris@2 94
Chris@2 95 public function testHasBundlesReturnsFalseWhenBundlesNoNodeIsPresent() {
Chris@2 96 $this->assertFalse(
Chris@2 97 $this->loadEmptyFixture()->hasBundlesElement()
Chris@2 98 );
Chris@2 99 }
Chris@2 100
Chris@2 101 private function loadFixture() {
Chris@2 102 return ManifestDocument::fromFile(__DIR__ . '/../_fixture/phpunit-5.6.5.xml');
Chris@2 103 }
Chris@2 104
Chris@2 105 private function loadEmptyFixture() {
Chris@2 106 return ManifestDocument::fromString(
Chris@2 107 '<?xml version="1.0" ?><phar xmlns="https://phar.io/xml/manifest/1.0" />'
Chris@2 108 );
Chris@2 109 }
Chris@2 110 }