X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Fsite-alias%2Ftests%2FSiteAliasCommandsTest.php;fp=vendor%2Fconsolidation%2Fsite-alias%2Ftests%2FSiteAliasCommandsTest.php;h=0d9fb0198301b329ceb7a4d158267bfa24f06043;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/vendor/consolidation/site-alias/tests/SiteAliasCommandsTest.php b/vendor/consolidation/site-alias/tests/SiteAliasCommandsTest.php new file mode 100644 index 000000000..0d9fb0198 --- /dev/null +++ b/vendor/consolidation/site-alias/tests/SiteAliasCommandsTest.php @@ -0,0 +1,109 @@ +commandClasses = [ \Consolidation\SiteAlias\Cli\SiteAliasCommands::class ]; + + // Define our invariants for our test + $this->appName = 'TestFixtureApp'; + $this->appVersion = '1.0.1'; + } + + /** + * Data provider for testExample. + * + * Return an array of arrays, each of which contains the parameter + * values to be used in one invocation of the testExample test function. + */ + public function exampleTestCommandParameters() + { + return [ + + [ + 'Add search location: /fixtures/sitealiases/sites', self::STATUS_ERROR, + 'site:list', '/fixtures/sitealiases/sites', + ], + + [ + 'List available site aliases', self::STATUS_OK, + 'list', + ], + + ]; + } + + /** + * Test our example class. Each time this function is called, it will + * be passed data from the data provider function idendified by the + * dataProvider annotation. + * + * @dataProvider exampleTestCommandParameters + */ + public function testExampleCommands($expectedOutput, $expectedStatus, $variable_args) + { + // Create our argv array and run the command + $argv = $this->argv(func_get_args()); + list($actualOutput, $statusCode) = $this->execute($argv); + + // Confirm that our output and status code match expectations + $this->assertContains($expectedOutput, $actualOutput); + $this->assertEquals($expectedStatus, $statusCode); + } + + /** + * Prepare our $argv array; put the app name in $argv[0] followed by + * the command name and all command arguments and options. + */ + protected function argv($functionParameters) + { + $argv = $functionParameters; + array_shift($argv); + array_shift($argv); + array_unshift($argv, $this->appName); + + // TODO: replace paths beginning with '/fixtures' with actual path to fixture data + + return $argv; + } + + /** + * Simulated front controller + */ + protected function execute($argv) + { + // Define a global output object to capture the test results + $output = new BufferedOutput(); + + // We can only call `Runner::execute()` once; then we need to tear down. + $runner = new \Robo\Runner($this->commandClasses); + $statusCode = $runner->execute($argv, $this->appName, $this->appVersion, $output); + \Robo\Robo::unsetContainer(); + + // Return the output and status code. + $actualOutput = trim($output->fetch()); + return [$actualOutput, $statusCode]; + } +}