From 64b628862415e827bc9c1487592d3c53439ef6b3 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 25 May 2022 09:27:28 -0400 Subject: [PATCH 1/4] fix: TraversableContains replaced with TraversableContainsIdentical --- src/TestCase/WPGraphQLTestCommon.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestCase/WPGraphQLTestCommon.php b/src/TestCase/WPGraphQLTestCommon.php index 89f4f9f..36dfe25 100644 --- a/src/TestCase/WPGraphQLTestCommon.php +++ b/src/TestCase/WPGraphQLTestCommon.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\Constraint\IsEmpty; use PHPUnit\Framework\Constraint\IsTrue; -use PHPUnit\Framework\Constraint\TraversableContains; +use PHPUnit\Framework\Constraint\TraversableContainsIdentical; /** * Trait WPGraphQLTestCommon @@ -828,10 +828,10 @@ public static function isEqual( $value ): IsEqual { * * @param mixed $value Desired contained value * - * @return TraversableContains + * @return TraversableContainsIdentical */ - public static function contains( $value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false ): TraversableContains { - return new TraversableContains( $value, $checkForObjectIdentity, $checkForNonObjectIdentity ); + public static function contains( $value ): TraversableContainsIdentical { + return new TraversableContainsIdentical( $value ); } /** From 2f0dfdb6188065f700bb83e3e10602f819873673 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 25 May 2022 09:37:44 -0400 Subject: [PATCH 2/4] ci workflow updated --- .github/workflows/continous-integration.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 64e1a14..63f0630 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -33,7 +33,8 @@ jobs: if: ${{ matrix.php != '8.0' }} run: | composer require wp-phpunit/wp-phpunit \ - phpunit/phpunit:~7.5 + yoast/phpunit-polyfills \ + phpunit/phpunit composer install - name: Run PHPUnit Tests w/ Docker. From 130f05d99663d2461d69e7bb4a6661a2854b7946 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 25 May 2022 10:43:00 -0400 Subject: [PATCH 3/4] fix: class constant<->not() bug fixed --- .gitignore | 1 + docker-compose.yml | 2 -- src/TestCase/WPGraphQLTestCommon.php | 52 ++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index ba5bb2c..b033d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ cache/* src/Codeception/Module/patchwork.json src/includes/patchwork.json composer.lock +.phpunit.result.cache # Some local vim files tags diff --git a/docker-compose.yml b/docker-compose.yml index 8d36c97..1360e6a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,6 @@ services: mysql: image: mysql - platform: linux/amd64 command: --default-authentication-plugin=mysql_native_password environment: MYSQL_ROOT_PASSWORD: password @@ -34,7 +33,6 @@ services: mysql_phpunit: image: mysql:5.7 - platform: linux/amd64 restart: always environment: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" diff --git a/src/TestCase/WPGraphQLTestCommon.php b/src/TestCase/WPGraphQLTestCommon.php index 36dfe25..7c736ac 100644 --- a/src/TestCase/WPGraphQLTestCommon.php +++ b/src/TestCase/WPGraphQLTestCommon.php @@ -307,7 +307,9 @@ public static function _assertExpectedDataFound( array $response, array $expecte static::$actual = $actual_data; // Handle if "$expected_value" set to field value constants. - switch( is_array( $expected_value ) ? $expected_value : "{$expected_value}" ) { + $reverse = static::startsWith( '!', $type ); + $possible_constraint = is_array( $expected_value ) ? $expected_value : "{$expected_value}"; + switch( $possible_constraint ) { case static::IS_NULL: // Set IS_NULL constraint. static::$last_constraint = static::isNull(); @@ -318,10 +320,14 @@ public static function _assertExpectedDataFound( array $response, array $expecte case static::NOT_FALSY: // Set NOT_FALSY constraint. - static::$last_constraint = static::logicalNot( static::isEmpty() ); + if ( $reverse ) { + static::$last_constraint = static::isEmpty(); + } else { + static::$last_constraint = static::logicalNot( static::isEmpty() ); + } // Fail if data found at path is a falsy value (null, false, []). - if ( empty( $actual_data ) ) { + if ( empty( $actual_data ) && ! $reverse ) { $message = $message ?? sprintf( 'Expected data at path "%s" not to be falsy value. "%s" Given', @@ -329,6 +335,15 @@ public static function _assertExpectedDataFound( array $response, array $expecte is_array( $actual_data ) ? '[]' : (string) $actual_data ); + return false; + } elseif ( ! empty( $actual_data ) && $reverse ) { + $message = $message + ?? sprintf( + 'Expected data at path "%s" to be falsy value. "%s" Given', + $full_path, + is_array( $actual_data ) ? json_encode( $actual_data, JSON_PRETTY_PRINT ) : $actual_data + ); + return false; } @@ -336,11 +351,16 @@ public static function _assertExpectedDataFound( array $response, array $expecte return true; case static::IS_FALSY: + // Set IS_FALSY constraint. - static::$last_constraint = static::isEmpty(); + if ( $reverse ) { + static::$last_constraint = static::logicalNot( static::isEmpty() ); + } else { + static::$last_constraint = static::isEmpty(); + } // Fail if data found at path is not falsy value (null, false, 0, []). - if ( ! empty( $actual_data ) ) { + if ( ! empty( $actual_data ) && ! $reverse ) { $message = $message ?? sprintf( 'Expected data at path "%s" to be falsy value. "%s" Given', @@ -348,6 +368,15 @@ public static function _assertExpectedDataFound( array $response, array $expecte is_array( $actual_data ) ? json_encode( $actual_data, JSON_PRETTY_PRINT ) : $actual_data ); + return false; + } elseif ( empty( $actual_data ) && $reverse ) { + $message = $message + ?? sprintf( + 'Expected data at path "%s" not to be falsy value. "%s" Given', + $full_path, + is_array( $actual_data ) ? json_encode( $actual_data, JSON_PRETTY_PRINT ) : $actual_data + ); + return false; } @@ -360,9 +389,18 @@ public static function _assertExpectedDataFound( array $response, array $expecte static::$last_constraint = static::logicalNot( static::isNull() ); // Fail if no data found at path. - if ( is_null( $actual_data ) ) { + if ( is_null( $actual_data ) && ! $reverse ) { $message = $message ?? sprintf( 'No data found at path "%s"', $full_path ); + return false; + } elseif ( + ! is_null( $actual_data ) + && $reverse + && $expected_value === static::NOT_NULL + ) { + $message = $message ?? sprintf( 'Unexpected data found at path "%s"', $full_path ); + + static::$last_constraint = static::isNull(); return false; } @@ -437,7 +475,7 @@ public static function _assertExpectedDataFound( array $response, array $expecte $message = $message ?? sprintf( '%1$s found in %2$s list at path "%3$s"', - $match_wanted ? 'Undesired data ' : 'Expected data not ', + $match_wanted ? 'Unexpected data ' : 'Expected data not ', strtolower( $type ), $full_path ); From 3e6ebe648af4060ebb4cbfe4b5205fa3f9855e26 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 25 May 2022 10:47:08 -0400 Subject: [PATCH 4/4] ci workflow updated --- .github/workflows/continous-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 63f0630..4414a6e 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -44,9 +44,9 @@ jobs: - name: Install Codeception dependencies run: | composer install --ignore-platform-reqs - composer require codeception/module-asserts \ - codeception/util-universalframework \ - codeception/module-rest \ + composer require codeception/module-asserts:* \ + codeception/util-universalframework:* \ + codeception/module-rest:* \ lucatume/wp-browser:3.1.0 --ignore-platform-reqs - name: Run Codeception Tests w/ Docker.