2 namespace Consolidation\AnnotatedCommand;
4 class CommandFileDiscoveryTests extends \PHPUnit_Framework_TestCase
6 function testCommandDiscovery()
8 $discovery = new CommandFileDiscovery();
10 ->setSearchPattern('*CommandFile.php')
11 ->setSearchLocations(['alpha']);
14 $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils');
16 $commandFilePaths = array_keys($commandFiles);
17 $commandFileNamespaces = array_values($commandFiles);
19 // Ensure that the command files that we expected to
20 // find were all found. We don't find anything in
21 // 'beta' because only 'alpha' is in the search path.
22 $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths);
23 $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths);
24 $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths);
25 $this->assertContains('./src/alpha/Inclusive/IncludedCommandFile.php', $commandFilePaths);
27 // Make sure that there are no additional items found.
28 $this->assertEquals(4, count($commandFilePaths));
30 // Ensure that the command file namespaces that we expected
31 // to be generated all match.
32 $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces);
33 $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces);
34 $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces);
35 $this->assertContains('\Consolidation\TestUtils\alpha\Inclusive\IncludedCommandFile', $commandFileNamespaces);
37 // We do not need to test for additional namespace items, because we
38 // know that the length of the array_keys must be the same as the
39 // length of the array_values.
42 function testDeepCommandDiscovery()
44 $discovery = new CommandFileDiscovery();
46 ->setSearchPattern('*CommandFile.php')
48 ->setSearchLocations([]);
51 $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils');
53 $commandFilePaths = array_keys($commandFiles);
54 $commandFileNamespaces = array_values($commandFiles);
56 // Ensure that the command files that we expected to
57 // find were all found. We find both 'alpha' and 'beta'
58 // items because the search locations is empty, which
59 // causes the search at the base directory to be deep.
60 // We do not find alpha/Inclusive, though, as the search
61 // depth is only 2, which excludes directories that are
63 $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths);
64 $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths);
65 $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths);
66 $this->assertContains('./src/beta/BetaCommandFile.php', $commandFilePaths);
68 // Make sure that there are no additional items found.
69 $this->assertEquals(4, count($commandFilePaths));
71 // Ensure that the command file namespaces that we expected
72 // to be generated all match.
73 $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces);
74 $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces);
75 $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces);
76 $this->assertContains('\Consolidation\TestUtils\beta\BetaCommandFile', $commandFileNamespaces);
78 // We do not need to test for additional namespace items, because we
79 // know that the length of the array_keys must be the same as the
80 // length of the array_values.