PhpElementTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PharIo\Manifest;
  3. use DOMDocument;
  4. class PhpElementTest extends \PHPUnit\Framework\TestCase {
  5. /**
  6. * @var DOMDocument
  7. */
  8. private $dom;
  9. /**
  10. * @var PhpElement
  11. */
  12. private $php;
  13. protected function setUp() {
  14. $this->dom = new DOMDocument();
  15. $this->dom->loadXML('<?xml version="1.0" ?><php xmlns="https://phar.io/xml/manifest/1.0" version="^5.6 || ^7.0" />');
  16. $this->php = new PhpElement($this->dom->documentElement);
  17. }
  18. public function testVersionConstraintCanBeRetrieved() {
  19. $this->assertEquals('^5.6 || ^7.0', $this->php->getVersion());
  20. }
  21. public function testHasExtElementsReturnsFalseWhenNoExtensionsAreRequired() {
  22. $this->assertFalse($this->php->hasExtElements());
  23. }
  24. public function testHasExtElementsReturnsTrueWhenExtensionsAreRequired() {
  25. $this->addExtElement();
  26. $this->assertTrue($this->php->hasExtElements());
  27. }
  28. public function testGetExtElementsReturnsExtElementCollection() {
  29. $this->addExtElement();
  30. $this->assertInstanceOf(ExtElementCollection::class, $this->php->getExtElements());
  31. }
  32. private function addExtElement() {
  33. $this->dom->documentElement->appendChild(
  34. $this->dom->createElementNS('https://phar.io/xml/manifest/1.0', 'ext')
  35. );
  36. }
  37. }