diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 3bd1b99..dae72c3 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -3,7 +3,7 @@ name: continuous_integration on: workflow_dispatch: schedule: - - cron: "0 4 * * 5" + - cron: "0 4 1 * *" push: branches: - master @@ -71,7 +71,7 @@ jobs: env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - docker-compose run --rm \ + docker compose run --rm \ --user $(id -u) \ -e COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN \ codeception_testing \ diff --git a/composer.json b/composer.json index 1d62007..de0a69d 100644 --- a/composer.json +++ b/composer.json @@ -36,8 +36,8 @@ "wpackagist-plugin/wp-graphql": "^1.26" }, "scripts": { - "run_phpunit_env": "docker-compose run --rm --workdir=/var/www/html/wp-content/plugins/wp-graphql-testcase --user $(id -u) wp_phpunit_testing wait-for-it $TEST_DB -s -t 300 --", - "run_codecept_env": "docker-compose run --rm --user $(id -u) codeception_testing wait-for-it $TEST_DB -s -t 300 --", + "run_phpunit_env": "docker compose run --rm --workdir=/var/www/html/wp-content/plugins/wp-graphql-testcase --user $(id -u) wp_phpunit_testing wait-for-it $TEST_DB -s -t 300 --", + "run_codecept_env": "docker compose run --rm --user $(id -u) codeception_testing wait-for-it $TEST_DB -s -t 300 --", "codeception": "codecept run --", "phpunit": "phpunit --", "run-codeception": "env TEST_DB=codecept_db:3306 composer run_codecept_env vendor/bin/codecept run", diff --git a/src/Constraint/QueryConstraint.php b/src/Constraint/QueryConstraint.php index ae85556..675a3f3 100644 --- a/src/Constraint/QueryConstraint.php +++ b/src/Constraint/QueryConstraint.php @@ -105,6 +105,26 @@ protected function expectedDataFound( array $response, array $expected_data, str return false; } + if ( 'ONE_OF' === $expected_data['type'] ) { + $one_of_passing = false; + foreach ( $expected_data['rules'] as $one_of_rule ) { + $one_of_passing = $this->expectedDataFound( $response, $one_of_rule, $current_path ); + if ( $one_of_passing ) { + break; + } + } + + if ( ! $one_of_passing ) { + $this->error_details[] = sprintf( + 'None of the provided rules passed for path "%s"', + $current_path + ); + return false; + } + + return true; + } + // Deconstruct $expected_data. extract( $expected_data ); diff --git a/src/TestCase/WPGraphQLTestCommon.php b/src/TestCase/WPGraphQLTestCommon.php index 6bb6dc5..a5dd1d6 100644 --- a/src/TestCase/WPGraphQLTestCommon.php +++ b/src/TestCase/WPGraphQLTestCommon.php @@ -124,6 +124,11 @@ public function expectedEdge( string $path, array $expected_value, $expected_ind return compact( 'type', 'path', 'expected_value', 'expected_index' ); } + public function oneOf( $rules ) { + $type = 'ONE_OF'; + return compact( 'type', 'rules' ); + } + /** * Triggers the "not" flag for the next expect*() call. * diff --git a/tests/codeception/wpunit/QuerySuccessfulConstraintTest.php b/tests/codeception/wpunit/QuerySuccessfulConstraintTest.php index a123b25..6f07ed1 100644 --- a/tests/codeception/wpunit/QuerySuccessfulConstraintTest.php +++ b/tests/codeception/wpunit/QuerySuccessfulConstraintTest.php @@ -125,6 +125,21 @@ public function testPassingValidationRules() { 'path' => 'nullField', 'expected_value' => 'codecept_field_value_is_null', ], + [ + 'type' => 'ONE_OF', + 'rules' => [ + [ + 'type' => 'FIELD', + 'path' => 'slug', + 'expected_value' => 'test_post', + ], + [ + 'type' => 'FIELD', + 'path' => 'title', + 'expected_value' => 'hello world', + ], + ], + ], ], 'expected_index' => null, ] @@ -230,6 +245,28 @@ public function testFailingValidationRules() { 'path' => '', 'expected_value' => [], ], + [ + 'type' => 'ONE_OF', + 'rules' => [ + [ + 'type' => 'INVALID_TYPE', + 'path' => '', + 'expected_value' => [], + ], + [ + 'type' => '!NODE', + 'path' => 'posts.nodes', + 'expected_value' => [ + [ + 'type' => 'FIELD', + 'path' => 'databaseId', + 'expected_value' => 'post_id', + ], + ], + 'expected_index' => 0, + ], + ], + ], ] ); $this->assertFalse($constraint->matches($response)); diff --git a/tests/codeception/wpunit/WPGraphQLTestCaseTest.php b/tests/codeception/wpunit/WPGraphQLTestCaseTest.php index 9ccb942..8ba8088 100644 --- a/tests/codeception/wpunit/WPGraphQLTestCaseTest.php +++ b/tests/codeception/wpunit/WPGraphQLTestCaseTest.php @@ -102,7 +102,18 @@ public function testAssertQuerySuccessful() { ), ) ), - + $this->oneOf( + [ + $this->expectedNode( + 'posts.nodes', + array( 'id' => $this->toRelayId( 'post', $post_id ) ) + ), + $this->not()->expectedNode( + 'posts.nodes', + array( 'id' => $this->toRelayId( 'post', 10001 ) ) + ), + ] + ), ); // Assert query successful. diff --git a/tests/phpunit/unit/test-querysuccessfulconstraint.php b/tests/phpunit/unit/test-querysuccessfulconstraint.php index c64343d..06ba6a7 100644 --- a/tests/phpunit/unit/test-querysuccessfulconstraint.php +++ b/tests/phpunit/unit/test-querysuccessfulconstraint.php @@ -134,6 +134,21 @@ public function test_PassingValidationRules() { 'path' => 'nullField', 'expected_value' => 'phpunit_field_value_is_null', ], + [ + 'type' => 'ONE_OF', + 'rules' => [ + [ + 'type' => 'FIELD', + 'path' => 'slug', + 'expected_value' => 'test_post', + ], + [ + 'type' => 'FIELD', + 'path' => 'title', + 'expected_value' => 'hello world', + ], + ], + ], ], 'expected_index' => null, ] @@ -247,6 +262,28 @@ public function test_FailingValidationRules() { 'path' => '', 'expected_value' => [], ], + [ + 'type' => 'ONE_OF', + 'rules' => [ + [ + 'type' => 'INVALID_TYPE', + 'path' => '', + 'expected_value' => [], + ], + [ + 'type' => '!NODE', + 'path' => 'posts.nodes', + 'expected_value' => [ + [ + 'type' => 'FIELD', + 'path' => 'databaseId', + 'expected_value' => 'post_id', + ], + ], + 'expected_index' => 0, + ], + ], + ], ] ); $this->assertFalse($constraint->matches($response)); diff --git a/tests/phpunit/unit/test-wpgraphqlunittestcase.php b/tests/phpunit/unit/test-wpgraphqlunittestcase.php index d542599..d6c859c 100644 --- a/tests/phpunit/unit/test-wpgraphqlunittestcase.php +++ b/tests/phpunit/unit/test-wpgraphqlunittestcase.php @@ -97,7 +97,18 @@ public function test_AssertQuerySuccessful() { ), ) ), - + $this->oneOf( + [ + $this->expectedNode( + 'posts.nodes', + array( 'id' => $this->toRelayId( 'post', $post_id ) ) + ), + $this->not()->expectedNode( + 'posts.nodes', + array( 'id' => $this->toRelayId( 'post', 10001 ) ) + ), + ] + ), ); // Assert query successful.