TestCase.php 865 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace DiDom\Tests;
  4. use DOMElement;
  5. use PHPUnit\Framework\TestCase as PHPUnitTestCase;
  6. use DOMDocument;
  7. use Exception;
  8. class TestCase extends PHPUnitTestCase
  9. {
  10. protected function loadFixture($filename)
  11. {
  12. $path = __DIR__.'/fixtures/'.$filename;
  13. if (file_exists($path)) {
  14. return file_get_contents($path);
  15. }
  16. throw new Exception(sprintf('Fixture "%s" does not exist', $filename));
  17. }
  18. protected function createDomElement(string $tagName, string $value = '', array $attributes = []): DOMElement
  19. {
  20. $document = new DOMDocument('1.0', 'UTF-8');
  21. $node = $document->createElement($tagName, $value);
  22. foreach ($attributes as $attrName => $attrValue) {
  23. $node->setAttribute($attrName, $attrValue);
  24. }
  25. return $node;
  26. }
  27. }