ContainsElementTest.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace PharIo\Manifest;
  3. use DOMDocument;
  4. use DOMElement;
  5. class ContainsElementTest extends \PHPUnit_Framework_TestCase {
  6. /**
  7. * @var DOMElement
  8. */
  9. private $domElement;
  10. /**
  11. * @var ContainsElement
  12. */
  13. private $contains;
  14. protected function setUp() {
  15. $dom = new DOMDocument();
  16. $dom->loadXML('<?xml version="1.0" ?><php xmlns="https://phar.io/xml/manifest/1.0" name="phpunit/phpunit" version="5.6.5" type="application" />');
  17. $this->domElement = $dom->documentElement;
  18. $this->contains = new ContainsElement($this->domElement);
  19. }
  20. public function testVersionCanBeRetrieved() {
  21. $this->assertEquals('5.6.5', $this->contains->getVersion());
  22. }
  23. public function testThrowsExceptionWhenVersionAttributeIsMissing() {
  24. $this->domElement->removeAttribute('version');
  25. $this->expectException(ManifestElementException::class);
  26. $this->contains->getVersion();
  27. }
  28. public function testNameCanBeRetrieved() {
  29. $this->assertEquals('phpunit/phpunit', $this->contains->getName());
  30. }
  31. public function testThrowsExceptionWhenNameAttributeIsMissing() {
  32. $this->domElement->removeAttribute('name');
  33. $this->expectException(ManifestElementException::class);
  34. $this->contains->getName();
  35. }
  36. public function testTypeCanBeRetrieved() {
  37. $this->assertEquals('application', $this->contains->getType());
  38. }
  39. public function testThrowsExceptionWhenTypeAttributeIsMissing() {
  40. $this->domElement->removeAttribute('type');
  41. $this->expectException(ManifestElementException::class);
  42. $this->contains->getType();
  43. }
  44. public function testGetExtensionElementReturnsExtensionElement() {
  45. $this->domElement->appendChild(
  46. $this->domElement->ownerDocument->createElementNS('https://phar.io/xml/manifest/1.0', 'extension')
  47. );
  48. $this->assertInstanceOf(ExtensionElement::class, $this->contains->getExtensionElement());
  49. }
  50. }