From 8984426b52784a619a7805dce04266a96088f7c7 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 30 Apr 2024 00:06:15 +0300 Subject: [PATCH 1/2] feat: Added a Method to Set Custom `Runner` for Testing --- tests/webfiori/tests/cli/RunnerTest.php | 2 +- webfiori/cli/CommandTestCase.php | 30 +++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/webfiori/tests/cli/RunnerTest.php b/tests/webfiori/tests/cli/RunnerTest.php index 5f10cdd..3773640 100644 --- a/tests/webfiori/tests/cli/RunnerTest.php +++ b/tests/webfiori/tests/cli/RunnerTest.php @@ -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')); diff --git a/webfiori/cli/CommandTestCase.php b/webfiori/cli/CommandTestCase.php index 51f1d21..7d0417f 100644 --- a/webfiori/cli/CommandTestCase.php +++ b/webfiori/cli/CommandTestCase.php @@ -33,6 +33,15 @@ 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. * @@ -40,17 +49,10 @@ class CommandTestCase extends TestCase { * 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) { @@ -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); From 918e9d8cac3e994e87e01fbe48ffd8f066f0cbdb Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 30 Apr 2024 00:22:11 +0300 Subject: [PATCH 2/2] chore: Updated CI Config --- .github/workflows/php70.yml | 6 ++++-- .github/workflows/php71.yml | 6 ++++-- .github/workflows/php72.yml | 6 ++++-- .github/workflows/php73.yml | 6 ++++-- .github/workflows/php74.yml | 6 ++++-- .github/workflows/php80.yml | 6 ++++-- .github/workflows/php81.yml | 6 ++++-- .github/workflows/php82.yml | 6 ++++-- .github/workflows/php83.yml | 6 ++++-- 9 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.github/workflows/php70.yml b/.github/workflows/php70.yml index 03acde1..be849aa 100644 --- a/.github/workflows/php70.yml +++ b/.github/workflows/php70.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php71.yml b/.github/workflows/php71.yml index e8704c1..a6a1045 100644 --- a/.github/workflows/php71.yml +++ b/.github/workflows/php71.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php72.yml b/.github/workflows/php72.yml index 8225cc6..cdc89a8 100644 --- a/.github/workflows/php72.yml +++ b/.github/workflows/php72.yml @@ -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 @@ -65,6 +65,8 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php73.yml b/.github/workflows/php73.yml index 5963922..a6f3632 100644 --- a/.github/workflows/php73.yml +++ b/.github/workflows/php73.yml @@ -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 @@ -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 diff --git a/.github/workflows/php74.yml b/.github/workflows/php74.yml index 63cff77..c5b00e8 100644 --- a/.github/workflows/php74.yml +++ b/.github/workflows/php74.yml @@ -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 @@ -65,7 +65,9 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php80.yml b/.github/workflows/php80.yml index 96b7b3c..00ac42b 100644 --- a/.github/workflows/php80.yml +++ b/.github/workflows/php80.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php81.yml b/.github/workflows/php81.yml index 10c8768..545669e 100644 --- a/.github/workflows/php81.yml +++ b/.github/workflows/php81.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php82.yml b/.github/workflows/php82.yml index 809ed6b..dc84ee9 100644 --- a/.github/workflows/php82.yml +++ b/.github/workflows/php82.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 \ No newline at end of file + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/php83.yml b/.github/workflows/php83.yml index b4d8217..b64e366 100644 --- a/.github/workflows/php83.yml +++ b/.github/workflows/php83.yml @@ -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 @@ -65,4 +65,6 @@ jobs: run: phpunit - name: CodeCov - uses: codecov/codecov-action@v1 \ No newline at end of file + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file