Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added a Method to Set Custom Runner for Testing #25

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
* 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 @@

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;

Check warning on line 141 in webfiori/cli/CommandTestCase.php

View check run for this annotation

Codecov / codecov/patch

webfiori/cli/CommandTestCase.php#L140-L141

Added lines #L140 - L141 were not covered by tests
}
private function exec(array $argv, array $userInputs, CLICommand $command = null) {
if ($command !== null) {
$key = array_search($command->getName(), $argv);
Expand Down
Loading