Skip to content

Commit

Permalink
Merge pull request #25 from WebFiori/dev
Browse files Browse the repository at this point in the history
feat: Added a Method to Set Custom `Runner` for Testing
  • Loading branch information
usernane authored Apr 29, 2024
2 parents d9e8358 + 918e9d8 commit a8448dc
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 28 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/php70.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/php71.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/php72.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,6 +65,8 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}


6 changes: 4 additions & 2 deletions .github/workflows/php73.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,7 +65,9 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: SonarCloud
uses: SonarSource/sonarcloud-github-action@master
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/php74.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,7 +65,9 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}



6 changes: 4 additions & 2 deletions .github/workflows/php80.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/php81.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/php82.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/php83.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

steps:
- name: Clone Repo
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -65,4 +65,6 @@ jobs:
run: phpunit

- name: CodeCov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion tests/webfiori/tests/cli/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testRunner06() {
"Available Commands:\n",
" super-hero: A command to display hero's name.\n",
" help: Display CLI Help. To display help for specific command, use the argument \"--command-name\" with this command.\n"
], $this->executeMultiCommand([
], $this->executeMultiCommand([], [], [
new Command00(),
new HelpCommand()
], 'help'));
Expand Down
30 changes: 21 additions & 9 deletions webfiori/cli/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,26 @@ class CommandTestCase extends TestCase {
* Register multiple commands and simulate the process of executing the app
* as if in production environment.
*
* @param array $argv An array that represents arguments vector. The array
* can be indexed or associative. If associative, the key will represent
* an option and the value of the key will represent its value. First
* index should contain the name of the command that will be executed from
* the registered commands.
*
* @param array $userInputs An array that holds user inputs. Each index
* should hold one line that represent an input to specific prompt.
*
* @param array $commands An array that holds objects of type 'CLICommand'.
* Each object represents the registered command.
*
* @param string $default A string that represents the name of the command
* that will get executed by default if no command name is provided
* in arguments victor.
*
* @param array $argv An array that represents arguments vector. The array
* can be indexed or associative. If associative, the key will represent
* an option and the value of the key will represent its value.
*
* @param array $userInputs An array that holds user inputs. Each index
* should hold one line that represent an input to specific prompt.
*
* @return array The method will return an array of strings that represents
* the output of execution.
*/
public function executeMultiCommand(array $commands, string $default = '', array $argv = [], array $userInputs = []) : array {
public function executeMultiCommand(array $argv = [], array $userInputs = [], array $commands = [], string $default = '') : array {
$runner = $this->getRunner(true);

foreach ($commands as $command) {
Expand Down Expand Up @@ -127,7 +129,17 @@ public function getRunner(bool $reset = false) : Runner {

return $this->runner;
}

/**
* Sets a custom runner to use in test execution.
*
* @param Runner $runner
*
* @return CommandTestCase The method will return same instance at which
* the method is called from.
*/
public function setRunner(Runner $runner) : CommandTestCase {
$this->runner = $runner;
}
private function exec(array $argv, array $userInputs, CLICommand $command = null) {
if ($command !== null) {
$key = array_search($command->getName(), $argv);
Expand Down

0 comments on commit a8448dc

Please sign in to comment.