ValidateRelationsTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @license Apache 2.0
  4. */
  5. namespace SwaggerTests;
  6. /**
  7. * Test if the nesting/parent relations are coherent.
  8. */
  9. class ValidateRelationsTest extends SwaggerTestCase
  10. {
  11. /**
  12. *
  13. * @dataProvider getAnnotations
  14. * @param string $class
  15. */
  16. public function testAncestors($class)
  17. {
  18. foreach ($class::$_parents as $parent) {
  19. $found = false;
  20. foreach (array_keys($parent::$_nested) as $nested) {
  21. if ($nested === $class) {
  22. $found = true;
  23. break;
  24. }
  25. }
  26. if ($found === false) {
  27. $this->fail($class . ' not found in ' . $parent . "::\$_nested. Found:\n " . implode("\n ", array_keys($parent::$_nested)));
  28. }
  29. }
  30. }
  31. /**
  32. *
  33. * @dataProvider getAnnotations
  34. * @param string $class
  35. */
  36. public function testNested($class)
  37. {
  38. foreach (array_keys($class::$_nested) as $nested) {
  39. $found = false;
  40. foreach ($nested::$_parents as $parent) {
  41. if ($parent === $class) {
  42. $found = true;
  43. break;
  44. }
  45. }
  46. if ($found === false) {
  47. $this->fail($class . ' not found in ' . $nested . "::\$parent. Found:\n " . implode("\n ", $nested::$_parents));
  48. }
  49. }
  50. }
  51. /**
  52. * dataProvider for testExample
  53. * @return array
  54. */
  55. public function getAnnotations()
  56. {
  57. $classes = [];
  58. $dir = new \DirectoryIterator(__DIR__ . '/../src/Annotations');
  59. foreach ($dir as $entry) {
  60. if ($entry->getFilename() === 'AbstractAnnotation.php') {
  61. continue;
  62. }
  63. if ($entry->getExtension() === 'php') {
  64. $classes[] = ['Swagger\Annotations\\' . substr($entry->getFilename(), 0, -4)];
  65. }
  66. }
  67. return $classes;
  68. }
  69. }