X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fconsolidation%2Fannotated-command%2Ftests%2FtestCommandFileDiscovery.php;fp=vendor%2Fconsolidation%2Fannotated-command%2Ftests%2FtestCommandFileDiscovery.php;h=c03c5ba6dd257c785470dfddc4ef7b87ecb8c1c5;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/consolidation/annotated-command/tests/testCommandFileDiscovery.php b/vendor/consolidation/annotated-command/tests/testCommandFileDiscovery.php new file mode 100644 index 000000000..c03c5ba6d --- /dev/null +++ b/vendor/consolidation/annotated-command/tests/testCommandFileDiscovery.php @@ -0,0 +1,82 @@ +setSearchPattern('*CommandFile.php') + ->setSearchLocations(['alpha']); + + chdir(__DIR__); + $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils'); + + $commandFilePaths = array_keys($commandFiles); + $commandFileNamespaces = array_values($commandFiles); + + // Ensure that the command files that we expected to + // find were all found. We don't find anything in + // 'beta' because only 'alpha' is in the search path. + $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths); + $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths); + $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths); + $this->assertContains('./src/alpha/Inclusive/IncludedCommandFile.php', $commandFilePaths); + + // Make sure that there are no additional items found. + $this->assertEquals(4, count($commandFilePaths)); + + // Ensure that the command file namespaces that we expected + // to be generated all match. + $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\alpha\Inclusive\IncludedCommandFile', $commandFileNamespaces); + + // We do not need to test for additional namespace items, because we + // know that the length of the array_keys must be the same as the + // length of the array_values. + } + + function testDeepCommandDiscovery() + { + $discovery = new CommandFileDiscovery(); + $discovery + ->setSearchPattern('*CommandFile.php') + ->setSearchDepth(1) + ->setSearchLocations([]); + + chdir(__DIR__); + $commandFiles = $discovery->discover('.', '\Consolidation\TestUtils'); + + $commandFilePaths = array_keys($commandFiles); + $commandFileNamespaces = array_values($commandFiles); + + // Ensure that the command files that we expected to + // find were all found. We find both 'alpha' and 'beta' + // items because the search locations is empty, which + // causes the search at the base directory to be deep. + // We do not find alpha/Inclusive, though, as the search + // depth is only 2, which excludes directories that are + // three levels deep. + $this->assertContains('./src/ExampleCommandFile.php', $commandFilePaths); + $this->assertContains('./src/ExampleHookAllCommandFile.php', $commandFilePaths); + $this->assertContains('./src/alpha/AlphaCommandFile.php', $commandFilePaths); + $this->assertContains('./src/beta/BetaCommandFile.php', $commandFilePaths); + + // Make sure that there are no additional items found. + $this->assertEquals(4, count($commandFilePaths)); + + // Ensure that the command file namespaces that we expected + // to be generated all match. + $this->assertContains('\Consolidation\TestUtils\ExampleCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\ExampleHookAllCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\alpha\AlphaCommandFile', $commandFileNamespaces); + $this->assertContains('\Consolidation\TestUtils\beta\BetaCommandFile', $commandFileNamespaces); + + // We do not need to test for additional namespace items, because we + // know that the length of the array_keys must be the same as the + // length of the array_values. + } +}