XMLSchemaTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection;
  3. class XMLSchemaTest extends \PHPUnit_Framework_TestCase
  4. {
  5. static public function dataValidateSchemaFiles()
  6. {
  7. $schemaFiles = array();
  8. $di = new \DirectoryIterator(__DIR__ . "/Fixtures/config/xml");
  9. foreach ($di as $element) {
  10. if ($element->isFile() && strpos($element->getFilename(), ".xml") !== false) {
  11. $schemaFiles[] = array($element->getPathname());
  12. }
  13. }
  14. return $schemaFiles;
  15. }
  16. /**
  17. * @dataProvider dataValidateSchemaFiles
  18. * @param string $file
  19. */
  20. public function testValidateSchema($file)
  21. {
  22. $found = false;
  23. $dom = new \DOMDocument('1.0', 'UTF-8');
  24. $dom->load($file);
  25. $dbalElements = $dom->getElementsByTagNameNS("http://www.symfony-project.org/schema/dic/doctrine", "config");
  26. if ($dbalElements->length) {
  27. $dbalDom = new \DOMDocument('1.0', 'UTF-8');
  28. $dbalNode = $dbalDom->importNode($dbalElements->item(0));
  29. $dbalDom->appendChild($dbalNode);
  30. $ret = $dbalDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd");
  31. $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
  32. $found = true;
  33. }
  34. $ormElements = $dom->getElementsByTagNameNS("http://www.symfony-project.org/schema/dic/doctrine", "config");
  35. if ($ormElements->length) {
  36. $ormDom = new \DOMDocument('1.0', 'UTF-8');
  37. $ormNode = $ormDom->importNode($ormElements->item(0));
  38. $ormDom->appendChild($ormNode);
  39. $ret = $ormDom->schemaValidate(__DIR__ . "/../../Resources/config/schema/doctrine-1.0.xsd");
  40. $this->assertTrue($ret, "DoctrineBundle Dependency Injection XMLSchema did not validate this XML instance.");
  41. $found = true;
  42. }
  43. $this->assertTrue($found, "Neither <doctrine:orm> nor <doctrine:dbal> elements found in given XML. Are namespaces configured correctly?");
  44. }
  45. }