Drupal investigation

testCommandFileDiscovery.php 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Consolidation\AnnotatedCommand;
  3. class CommandFileDiscoveryTests extends \PHPUnit_Framework_TestCase
  4. {
  5. function testCommandDiscovery()
  6. {
  7. $discovery = new CommandFileDiscovery();
  8. $discovery
  9. ->setSearchPattern('*CommandFile.php')
  10. ->setSearchLocations(['alpha']);
  11. chdir(__DIR__);
  12. $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils');
  13. $commandFilePaths = array_keys($commandFiles);
  14. $commandFileNamespaces = array_values($commandFiles);
  15. // Ensure that the command files that we expected to
  16. // find were all found. We don't find anything in
  17. // 'beta' because only 'alpha' is in the search path.
  18. $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths);
  19. $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths);
  20. $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths);
  21. $this->assertContains('./src/alpha/Inclusive/IncludedCommandFile.php', $commandFilePaths);
  22. // Make sure that there are no additional items found.
  23. $this->assertEquals(4, count($commandFilePaths));
  24. // Ensure that the command file namespaces that we expected
  25. // to be generated all match.
  26. $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces);
  27. $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces);
  28. $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces);
  29. $this->assertContains('\Consolidation\TestUtils\alpha\Inclusive\IncludedCommandFile', $commandFileNamespaces);
  30. // We do not need to test for additional namespace items, because we
  31. // know that the length of the array_keys must be the same as the
  32. // length of the array_values.
  33. }
  34. function testDeepCommandDiscovery()
  35. {
  36. $discovery = new CommandFileDiscovery();
  37. $discovery
  38. ->setSearchPattern('*CommandFile.php')
  39. ->setSearchDepth(1)
  40. ->setSearchLocations([]);
  41. chdir(__DIR__);
  42. $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils');
  43. $commandFilePaths = array_keys($commandFiles);
  44. $commandFileNamespaces = array_values($commandFiles);
  45. // Ensure that the command files that we expected to
  46. // find were all found. We find both 'alpha' and 'beta'
  47. // items because the search locations is empty, which
  48. // causes the search at the base directory to be deep.
  49. // We do not find alpha/Inclusive, though, as the search
  50. // depth is only 2, which excludes directories that are
  51. // three levels deep.
  52. $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths);
  53. $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths);
  54. $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths);
  55. $this->assertContains('./src/beta/BetaCommandFile.php', $commandFilePaths);
  56. // Make sure that there are no additional items found.
  57. $this->assertEquals(4, count($commandFilePaths));
  58. // Ensure that the command file namespaces that we expected
  59. // to be generated all match.
  60. $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces);
  61. $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces);
  62. $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces);
  63. $this->assertContains('\Consolidation\TestUtils\beta\BetaCommandFile', $commandFileNamespaces);
  64. // We do not need to test for additional namespace items, because we
  65. // know that the length of the array_keys must be the same as the
  66. // length of the array_values.
  67. }
  68. }