Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctl committed Sep 9, 2024
1 parent ffea029 commit ac78eb5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
30 changes: 30 additions & 0 deletions tests/_data/test-workflow-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# A test workflow run via the test suite

# Loop through all the arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--*=*) # Option in --option=value format
option="${1%%=*}" # Extract the option
value="${1#*=}" # Extract the value
echo "Option: $option, Value: $value"
shift
;;
--*) # Option in --option format (expecting a separate value)
option=$1
shift
if [[ "$1" && ! "$1" =~ ^-- ]]; then
value=$1
echo "Option: $option, Value: $value"
shift
else
echo "Option: $option, No value provided"
fi
;;
*) # Regular argument
echo "Argument: $1"
shift
;;
esac
done
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Checking for TBDs...
--------------------

./src/Plugin.php
9: * @since TBD

./src/Thing/AnotherFile.php
5: _deprecated_file( __FILE__, 'TBD' );
9: * @since TBD
Expand All @@ -14,5 +11,8 @@ Checking for TBDs...
28: * @deprecated TBD
32: _deprecated_function( __METHOD__, 'TBD' );

./src/Plugin.php
9: * @since TBD


TBDs have been found!
23 changes: 23 additions & 0 deletions tests/cli/Commands/WorkflowCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,27 @@ public function it_should_run_build_with_custom_env_vars( CliTester $I ) {
$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

/**
* @test
*/
public function it_should_pass_additional_arguments_and_options_to_workflow_script( CliTester $I ) {
$puprc = $this->get_puprc();
$puprc['workflows'] = [];
$puprc['workflows']['test-workflow'] = [];
$puprc['workflows']['test-workflow'][] = codecept_data_dir( 'test-workflow-script.sh' );
$this->write_puprc( $puprc );

chdir( $this->tests_root . '/_data/fake-project' );

$I->runShellCommand( "php {$this->pup} do test-workflow -- arg1 arg2 --option-one=one --option-two=two" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'Argument: arg1' );
$I->seeInShellOutput( 'Argument: arg2' );
$I->seeInShellOutput( 'Option: --option-one, Value: one' );
$I->seeInShellOutput( 'Option: --option-two, Value: two' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Running test-workflow workflow steps...

> /var/www/html/wp-content/plugins/pup/tests/_data/test-workflow-script.sh 'arg1' 'arg2' '--option-one=one' '--option-two=two'
------------------------------------------------------------------------------------------------------------------------------

Argument: arg1
Argument: arg2
Option: --option-one, Value: one
Option: --option-two, Value: two

Workflow complete.

0 comments on commit ac78eb5

Please sign in to comment.