From b0108319a61e1d9548fa4bbcdec25bbd18974ce7 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 15 May 2024 11:54:19 -0400 Subject: [PATCH 1/4] feat: "$request_headers" replaced with "$selected_options" --- src/Codeception/Module/WPGraphQL.php | 157 ++++++++++-------- .../functional/WPGraphQLModuleTestCest.php | 47 ++++++ 2 files changed, 135 insertions(+), 69 deletions(-) diff --git a/src/Codeception/Module/WPGraphQL.php b/src/Codeception/Module/WPGraphQL.php index e6dfff5..63ac43d 100644 --- a/src/Codeception/Module/WPGraphQL.php +++ b/src/Codeception/Module/WPGraphQL.php @@ -59,17 +59,49 @@ public function _before( TestInterface $test ) { $this->logger = new \Tests\WPGraphQL\Logger\CodeceptLogger(); } + /** + * Parses the request options and return a formatted request options + * + * @param array $selected_options The request options to parse. + * @return void + */ + protected function parseRequestOptions( array $selected_options ) { + $default_options = [ 'headers' => $this->getHeaders() ]; + if ( empty( $selected_options ) ) { + return $default_options; + } + + $request_options = clone $default_options; + foreach( $selected_options as $key => $value ) { + if ( in_array( $key, [ 'headers', 'suppress_mod_token' ] ) ) { + continue; + } + + $request_options[$key] = $value; + } + + if ( ! isset( $selected_options['suppress_mod_token'] ) && true === $selected_options['suppress_mod_token'] ) { + unset( $request_options['headers']['Authorization'] ); + } + + if ( ! empty( $selected_options['headers'] ) && is_array( $selected_options['headers'] ) ) { + $request_options['headers'] = array_merge( $request_options['headers'], $selected_options['headers'] ); + } + + return $request_options; + } + /** * Sends a GET request to the GraphQL endpoint and returns a response * - * @param string $query The GraphQL query to send. - * @param array $request_headers The headers to send with the request. + * @param string $query The GraphQL query to send. + * @param array $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid endpoint | Invalid query. * * @return array */ - public function getRawRequest( $query, $request_headers = [] ) { + public function getRawRequest( string $query, array $selected_options = [] ) { $endpoint = $this->config['endpoint']; if ( empty( $endpoint ) ) { throw new ModuleException( $this, 'Invalid endpoint.' ); @@ -79,15 +111,12 @@ public function getRawRequest( $query, $request_headers = [] ) { throw new ModuleException( $this, 'Invalid query.' ); } - $headers = array_merge( - $this->getHeaders(), - $request_headers - ); + $request_options = $this->parseRequestOptions( $selected_options ); - $this->logger->logData( "GET request to {$endpoint} with query: {$query}" ); - $this->logger->logData( "Headers: " . json_encode( $headers ) ); + $this->logger->logData( "GET request to {$endpoint} with query: \n{$query}\n" ); + $this->logger->logData( "With request options: \n" . json_encode( $request_options, JSON_PRETTY_PRINT ) ."\n" ); - $response = $this->client->request( 'GET', "?query={$query}", [ 'headers' => $headers ] ); + $response = $this->client->request( 'GET', "?query={$query}", $request_options ); if ( empty( $response ) ) { throw new ModuleException( $this, 'Invalid response.' ); @@ -102,15 +131,15 @@ public function getRawRequest( $query, $request_headers = [] ) { /** * Sends a GET request to the GraphQL endpoint and returns the query results * - * @param string $query The GraphQL query to send. - * @param array $request_headers The headers to send with the request. + * @param string $query The GraphQL query to send. + * @param array $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid response | Empty response. * * @return array */ - public function getRequest( $query, $request_headers = [] ) { - $response = $this->getRawRequest( $query, $request_headers ); + public function getRequest( string $query, array $selected_options = [] ) { + $response = $this->getRawRequest( $query, $selected_options ); if ( $response->getStatusCode() !== 200 ) { throw new ModuleException( $this, 'Invalid response.' ); } @@ -127,15 +156,15 @@ public function getRequest( $query, $request_headers = [] ) { /** * Sends a POST request to the GraphQL endpoint and return a response * - * @param string $query The GraphQL query to send. - * @param array $variables The variables to send with the query. - * @param string|null $request_headers The headers to send with the request. + * @param string $query The GraphQL query to send. + * @param array $variables The variables to send with the query. + * @param string|null $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function postRawRequest( $query, $variables = [], $request_headers = [] ) { + public function postRawRequest( $query, $variables = [], $selected_options = [] ) { $endpoint = $this->config['endpoint']; if ( empty( $endpoint ) ) { throw new ModuleException( $this, 'Invalid endpoint.' ); @@ -149,22 +178,18 @@ public function postRawRequest( $query, $variables = [], $request_headers = [] ) throw new ModuleException( $this, 'Invalid variables.' ); } - $headers = array_merge( - $this->getHeaders(), - $request_headers - ); + $request_options = $this->parseRequestOptions( $selected_options ); - $this->logger->logData( "GET request to {$endpoint} with query: {$query}" ); - $this->logger->logData( "Variables: " . json_encode( $variables ) ); - $this->logger->logData( "Headers: " . json_encode( $headers ) ); + $this->logger->logData( "POST request to {$endpoint} with query: \n{$query}\n" ); + if ( ! empty( $variables ) ) { + $this->logger->logData( "With variables: \n" . json_encode( $variables, JSON_PRETTY_PRINT ) . "\n" ); + } + $this->logger->logData( "With request options: \n" . json_encode( $request_options, JSON_PRETTY_PRINT ) ."\n" ); $response = $this->client->request( 'POST', '', - [ - 'headers' => $headers, - 'body' => json_encode( [ 'query' => $query, 'variables' => $variables ] ), - ] + array_merge( $request_options, [ 'body' => json_encode( compact( 'query', 'variables' ) ) ] ) ); if ( empty( $response ) ) { @@ -180,16 +205,16 @@ public function postRawRequest( $query, $variables = [], $request_headers = [] ) /** * Sends POST request to the GraphQL endpoint and returns the query results * - * @param string $query The GraphQL query to send. - * @param array $variables The variables to send with the query. - * @param string|null $request_headers The headers to send with the request. + * @param string $query The GraphQL query to send. + * @param array $variables The variables to send with the query. + * @param string|null $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function postRequest( $query, $variables = [], $request_headers = [] ) { - $response = $this->postRawRequest( $query, $variables, $request_headers ); + public function postRequest( $query, $variables = [], $selected_options = [] ) { + $response = $this->postRawRequest( $query, $variables, $selected_options ); if ( $response->getStatusCode() !== 200 ) { throw new ModuleException( $this, 'Invalid response.' ); } @@ -206,14 +231,14 @@ public function postRequest( $query, $variables = [], $request_headers = [] ) { /** * Sends a batch query request to the GraphQL endpoint and return a response * - * @param object{'query': string, 'variables': array} $operations An array of operations to send. - * @param array $request_headers An array of headers to send with the request. + * @param object{'query': string, 'variables': array} $operations An array of operations to send. + * @param array $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function batchRawRequest( $operations, $request_headers = [] ) { + public function batchRawRequest( $operations, $selected_options = [] ) { $endpoint = $this->config['endpoint']; if ( empty( $endpoint ) ) { throw new ModuleException( $this, 'Invalid endpoint.' ); @@ -223,18 +248,16 @@ public function batchRawRequest( $operations, $request_headers = [] ) { throw new ModuleException( $this, 'Invalid query.' ); } - $headers = array_merge( - $this->getHeaders(), - $request_headers - ); + $request_options = $this->parseRequestOptions( $selected_options ); + + $this->logger->logData( "POST request to {$endpoint} with operations: \n" . json_encode( $operations, JSON_PRETTY_PRINT ) . "\n" ); + + $this->logger->logData( "With request options: \n" . json_encode( $request_options, JSON_PRETTY_PRINT ) ."\n" ); $response = $this->client->request( 'POST', '', - [ - 'headers' => $headers, - 'body' => json_encode( $operations ), - ] + array_merge( $request_options, [ 'body' => json_encode( $operations ) ] ) ); if ( empty( $response ) ) { @@ -250,15 +273,15 @@ public function batchRawRequest( $operations, $request_headers = [] ) { /** * Sends a batch query request to the GraphQL endpoint and returns the query results * - * @param object{'query': string, 'variables': array} $operations An array of operations to send. - * @param array $request_headers An array of headers to send with the request. + * @param object{'query': string, 'variables': array} $operations An array of operations to send. + * @param array $selected_options Selected options to control various aspects of a request. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function batchRequest( $operations, $request_headers = [] ) { - $response = $this->batchRawRequest( $operations, $request_headers ); + public function batchRequest( $operations, $selected_options = [] ) { + $response = $this->batchRawRequest( $operations, $selected_options ); if ( $response->getStatusCode() !== 200 ) { throw new ModuleException( $this, 'Invalid response.' ); } @@ -275,15 +298,15 @@ public function batchRequest( $operations, $request_headers = [] ) { /** * Sends a concurrent requests to the GraphQL endpoint and returns a response * - * @param {'query': string, 'variables': array} $operations An array of operations to send. - * @param array $request_headers An array of headers to send with the request. - * @param int $stagger The time in milliseconds to stagger requests. + * @param {'query': string, 'variables': array} $operations An array of operations to send. + * @param array $selected_options Selected options to control various aspects of a request. + * @param int $stagger The time in milliseconds to stagger requests. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function concurrentRawRequests( $operations, $request_headers = [], $stagger = 800 ) { + public function concurrentRawRequests( $operations, $selected_options = [], $stagger = 800 ) { $endpoint = $this->config['endpoint']; if ( empty( $endpoint ) ) { throw new ModuleException( $this, 'Invalid endpoint.' ); @@ -293,10 +316,11 @@ public function concurrentRawRequests( $operations, $request_headers = [], $stag throw new ModuleException( $this, 'Invalid query.' ); } - $headers = array_merge( - $this->getHeaders(), - $request_headers - ); + $request_options = $this->parseRequestOptions( $selected_options ); + + $this->logger->logData( "A series of POST requests to {$endpoint} with executed in the following order: \n" . json_encode( $operations, JSON_PRETTY_PRINT ) . "\n" ); + + $this->logger->logData( "With request options: \n" . json_encode( $request_options, JSON_PRETTY_PRINT ) ."\n" ); $promises = []; foreach ( $operations as $index => $operation ) { @@ -313,13 +337,8 @@ public function concurrentRawRequests( $operations, $request_headers = [], $stag } }; $promises[] = $this->client->postAsync( - '', - [ - 'body' => $body, - 'delay' => $delay, - 'progress' => $progress, - 'headers' => $headers, - ] + '', + array_merge( $request_options, compact( 'body', 'progress', 'delay' ) ), ); } @@ -332,16 +351,16 @@ public function concurrentRawRequests( $operations, $request_headers = [], $stag /** * Sends a concurrent requests to the GraphQL endpoint and returns a response * - * @param {'query': string, 'variables': array} $operations An array of operations to send. - * @param array $request_headers An array of headers to send with the request. - * @param int $stagger The time in milliseconds to stagger requests. + * @param {'query': string, 'variables': array} $operations An array of operations to send. + * @param array $selected_options Selected options to control various aspects of a request. + * @param int $stagger The time in milliseconds to stagger requests. * * @throws \Codeception\Exception\ModuleException Invalid endpoint. * * @return array */ - public function concurrentRequests( $operations, $request_headers = [], $stagger = 800 ) { - $responses = $this->concurrentRawRequests( $operations, $request_headers, $stagger ); + public function concurrentRequests( $operations, $selected_options = [], $stagger = 800 ) { + $responses = $this->concurrentRawRequests( $operations, $selected_options, $stagger ); if ( empty( $responses ) ) { throw new ModuleException( $this, 'Invalid response.' ); } diff --git a/tests/codeception/functional/WPGraphQLModuleTestCest.php b/tests/codeception/functional/WPGraphQLModuleTestCest.php index 8cca2a4..c98838d 100644 --- a/tests/codeception/functional/WPGraphQLModuleTestCest.php +++ b/tests/codeception/functional/WPGraphQLModuleTestCest.php @@ -290,4 +290,51 @@ public function testConcurrentRequests( FunctionalTester $I, $scenario ) { ] ); } + + public function testRequestOptions( FunctionalTester $I ) { + $I->wantTo( 'send a request to the GraphQL endpoint with custom options' ); + + $query = 'mutation ( $input: CreatePostInput! ) { + createPost( input: $input ) { + post { + id + title + slug + status + } + } + }'; + + $variables = [ + 'input' => [ + 'title' => 'Test Post', + 'content' => 'Test Post content', + 'slug' => 'test-post', + 'status' => 'DRAFT' + ] + ]; + + + $response = $I->postRequest( $query, $variables, [ 'suppress_mod_token' => true ] ); + + $I->assertQueryError( $response ); + + $response = $I->postRequest( $query, $variables ); + + $I->assertQuerySuccessful( $response [ $I->expectField( 'createPost.post.id', Signal::NOT_NULL ) ] ); + + $id = $I->lodashGet( $response, 'data.createPost.post.id' ); + + $query = ' + query ( $id: ID! ) { + post( id: $id ) { + id + } + } + '; + + $response = $I->postRequest( $query, [ 'id' => $id ], [ 'suppress_mod_token' => true ] ); + + $I->assertQueryError( $response ); + } } From 01ddff46e187efe546ed2eff7f462b041a626d35 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 15 May 2024 12:00:37 -0400 Subject: [PATCH 2/4] fix: "clone" modifier removed --- src/Codeception/Module/WPGraphQL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Module/WPGraphQL.php b/src/Codeception/Module/WPGraphQL.php index 63ac43d..6385cbb 100644 --- a/src/Codeception/Module/WPGraphQL.php +++ b/src/Codeception/Module/WPGraphQL.php @@ -71,7 +71,7 @@ protected function parseRequestOptions( array $selected_options ) { return $default_options; } - $request_options = clone $default_options; + $request_options = $default_options; foreach( $selected_options as $key => $value ) { if ( in_array( $key, [ 'headers', 'suppress_mod_token' ] ) ) { continue; From b1a4068ff9a5652c5536e60f6ed278f09ad49276 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 15 May 2024 12:35:52 -0400 Subject: [PATCH 3/4] fix: General bugfixes and improvements --- .github/workflows/continous-integration.yml | 2 +- codeception.dist.yml | 14 +++++----- src/Codeception/Module/QueryAsserts.php | 16 ++++++++++++ src/Codeception/Module/WPGraphQL.php | 16 +++++++----- tests/codeception/acceptance.suite.dist.yml | 8 +++--- tests/codeception/functional.suite.dist.yml | 26 +++++-------------- ...estCest.php => QueryAssertsModuleCest.php} | 2 +- ...leTestCest.php => WPGraphQLModuleCest.php} | 6 ++--- tests/codeception/wpunit.suite.dist.yml | 4 +-- 9 files changed, 50 insertions(+), 44 deletions(-) rename tests/codeception/functional/{QueryAssertsModuleTestCest.php => QueryAssertsModuleCest.php} (98%) rename tests/codeception/functional/{WPGraphQLModuleTestCest.php => WPGraphQLModuleCest.php} (97%) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 54b312f..4bef3ad 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -56,7 +56,7 @@ jobs: codeception/module-phpbrowser:* \ codeception/module-webdriver:* \ wp-cli/wp-cli-bundle \ - lucatume/wp-browser:^3.1 + lucatume/wp-browser:^4 - name: Run Codeception Tests w/ Docker. env: diff --git a/codeception.dist.yml b/codeception.dist.yml index 0b895ef..ab79232 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -18,13 +18,13 @@ extensions: enabled: - Codeception\Extension\RunFailed commands: - - Codeception\Command\GenerateWPUnit - - Codeception\Command\GenerateWPRestApi - - Codeception\Command\GenerateWPRestController - - Codeception\Command\GenerateWPRestPostTypeController - - Codeception\Command\GenerateWPAjax - - Codeception\Command\GenerateWPCanonical - - Codeception\Command\GenerateWPXMLRPC + - "lucatume\\WPBrowser\\Command\\GenerateWPUnit" + - "lucatume\\WPBrowser\\Command\\GenerateWPRestApi" + - "lucatume\\WPBrowser\\Command\\GenerateWPRestController" + - "lucatume\\WPBrowser\\Command\\GenerateWPRestPostTypeController" + - "lucatume\\WPBrowser\\Command\\GenerateWPAjax" + - "lucatume\\WPBrowser\\Command\\GenerateWPCanonical" + - "lucatume\\WPBrowser\\Command\\GenerateWPXMLRPC" params: - .env.testing - .env.docker \ No newline at end of file diff --git a/src/Codeception/Module/QueryAsserts.php b/src/Codeception/Module/QueryAsserts.php index 7ebebca..255e2d7 100644 --- a/src/Codeception/Module/QueryAsserts.php +++ b/src/Codeception/Module/QueryAsserts.php @@ -10,6 +10,7 @@ use Tests\WPGraphQL\Constraint\QueryErrorConstraint; use Tests\WPGraphQL\Constraint\QuerySuccessfulConstraint; use Tests\WPGraphQL\Logger\CodeceptLogger as Signal; +use Tests\WPGraphQL\Utils\Utils; /** * GraphQL Query Asserts Module for Codeception @@ -120,6 +121,21 @@ private function get_not() { return $prefix; } + /** + * The value returned for undefined resolved values. + * + * Clone of the "get" function from the Lodash JS libra + * + * @param array $object The object to query. + * @param string $path The path of the property to get. + * @param mixed $default The value returned for undefined resolved values. + * + * @return mixed + */ + public function lodashGet( array $data, string $string, $default = null ) { + return Utils::lodashGet( $data, $string, $default ); + } + /** * Returns an expected "location" error data object. * diff --git a/src/Codeception/Module/WPGraphQL.php b/src/Codeception/Module/WPGraphQL.php index 6385cbb..d802a27 100644 --- a/src/Codeception/Module/WPGraphQL.php +++ b/src/Codeception/Module/WPGraphQL.php @@ -77,10 +77,12 @@ protected function parseRequestOptions( array $selected_options ) { continue; } - $request_options[$key] = $value; + $request_options[ $key ] = $value; } - if ( ! isset( $selected_options['suppress_mod_token'] ) && true === $selected_options['suppress_mod_token'] ) { + if ( isset( $selected_options['suppress_mod_token'] ) + && true === $selected_options['suppress_mod_token'] + && isset( $request_options['headers']['Authorization'] ) ) { unset( $request_options['headers']['Authorization'] ); } @@ -88,6 +90,8 @@ protected function parseRequestOptions( array $selected_options ) { $request_options['headers'] = array_merge( $request_options['headers'], $selected_options['headers'] ); } + \codecept_debug( $request_options ); + return $request_options; } @@ -123,7 +127,7 @@ public function getRawRequest( string $query, array $selected_options = [] ) { } $this->logger->logData( $response->getHeaders() ); - $this->logger->logData( $response->getBody() ); + $this->logger->logData( (string) $response->getBody() ); return $response; } @@ -197,7 +201,7 @@ public function postRawRequest( $query, $variables = [], $selected_options = [] } $this->logger->logData( $response->getHeaders() ); - $this->logger->logData( $response->getBody() ); + $this->logger->logData( (string) $response->getBody() ); return $response; } @@ -265,7 +269,7 @@ public function batchRawRequest( $operations, $selected_options = [] ) { } $this->logger->logData( $response->getHeaders() ); - $this->logger->logData( json_decode( $response->getBody() ) ); + $this->logger->logData( (string) $response->getBody() ); return $response; } @@ -376,7 +380,7 @@ public function concurrentRequests( $operations, $selected_options = [], $stagge } $this->logger->logData( $response->getHeaders() ); - $this->logger->logData( json_decode( $response->getBody() ) ); + $this->logger->logData( (string) $response->getBody() ); $queryResults[] = json_decode( $response->getBody(), true ); } diff --git a/tests/codeception/acceptance.suite.dist.yml b/tests/codeception/acceptance.suite.dist.yml index 8f4f72f..36e1588 100644 --- a/tests/codeception/acceptance.suite.dist.yml +++ b/tests/codeception/acceptance.suite.dist.yml @@ -8,11 +8,11 @@ actor: AcceptanceTester modules: enabled: - - WPDb - - WPBrowser + - \lucatume\WPBrowser\Module\WPDb + - \lucatume\WPBrowser\Module\WPBrowser - \Helper\Acceptance config: - WPDb: + \lucatume\WPBrowser\Module\WPDb: dsn: '%TEST_SITE_DB_DSN%' user: '%TEST_DB_USER%' password: '%TEST_DB_PASSWORD%' @@ -24,7 +24,7 @@ modules: urlReplacement: true tablePrefix: '%TEST_TABLE_PREFIX%' - WPBrowser: + \lucatume\WPBrowser\Module\WPBrowser: url: '%TEST_SITE_WP_URL%' wpRootFolder: '%WP_ROOT_FOLDER%' adminUsername: '%TEST_SITE_ADMIN_USERNAME%' diff --git a/tests/codeception/functional.suite.dist.yml b/tests/codeception/functional.suite.dist.yml index 077a1a2..04ec111 100644 --- a/tests/codeception/functional.suite.dist.yml +++ b/tests/codeception/functional.suite.dist.yml @@ -6,10 +6,10 @@ actor: FunctionalTester modules: enabled: - - WPDb - - WPBrowser - - WPFilesystem - Asserts + - \lucatume\WPBrowser\Module\WPDb + - \lucatume\WPBrowser\Module\WPBrowser + - \lucatume\WPBrowser\Module\WPFilesystem - \Tests\WPGraphQL\Codeception\Module\QueryAsserts - \Tests\WPGraphQL\Codeception\Module\WPGraphQL - \Helper\Functional @@ -17,7 +17,7 @@ modules: \Tests\WPGraphQL\Codeception\Module\WPGraphQL: endpoint: '%TEST_SITE_WP_URL%/graphql' auth_header: 'Basic %TEST_SITE_ADMIN_APP_PASSWORD%' - WPDb: + \lucatume\WPBrowser\Module\WPDb: dsn: '%TEST_SITE_DB_DSN%' user: '%TEST_DB_USER%' password: '%TEST_DB_PASSWORD%' @@ -29,30 +29,16 @@ modules: urlReplacement: true tablePrefix: '%TEST_TABLE_PREFIX%' - WPBrowser: + \lucatume\WPBrowser\Module\WPBrowser: url: '%TEST_SITE_WP_URL%' wpRootFolder: '%WP_ROOT_FOLDER%' adminUsername: '%TEST_SITE_ADMIN_USERNAME%' adminPassword: '%TEST_SITE_ADMIN_PASSWORD%' adminPath: '/wp-admin' - WPFilesystem: + \lucatume\WPBrowser\Module\WPFilesystem: wpRootFolder: '%WP_ROOT_FOLDER%' plugins: '/wp-content/plugins' mu-plugins: '/wp-content/mu-plugins' themes: '/wp-content/themes' uploads: '/wp-content/uploads' - - WPLoader: - loadOnly: true - wpRootFolder: "%WP_ROOT_FOLDER%" - dbName: "%TEST_DB_NAME%" - dbHost: "%TEST_DB_HOST%" - dbUser: "%TEST_DB_USER%" - dbPassword: "%TEST_DB_PASSWORD%" - tablePrefix: "%TEST_TABLE_PREFIX%" - domain: "%TEST_SITE_WP_DOMAIN%" - adminEmail: "%TEST_SITE_ADMIN_EMAIL%" - title: "WPGraphQLTestcase" - plugins: ['wp-graphql/wp-graphql.php'] - activatePlugins: ['wp-graphql/wp-graphql.php'] diff --git a/tests/codeception/functional/QueryAssertsModuleTestCest.php b/tests/codeception/functional/QueryAssertsModuleCest.php similarity index 98% rename from tests/codeception/functional/QueryAssertsModuleTestCest.php rename to tests/codeception/functional/QueryAssertsModuleCest.php index cad82f5..08d5ce6 100644 --- a/tests/codeception/functional/QueryAssertsModuleTestCest.php +++ b/tests/codeception/functional/QueryAssertsModuleCest.php @@ -6,7 +6,7 @@ use \FunctionalTester; use Tests\WPGraphQL\Logger\CodeceptLogger as Signal; -class QueryAssertsModuleTestCest { +class QueryAssertsModuleCest { public function testAssertResponseIdValid( FunctionalTester $I ) { $data = [ 'data' => [ diff --git a/tests/codeception/functional/WPGraphQLModuleTestCest.php b/tests/codeception/functional/WPGraphQLModuleCest.php similarity index 97% rename from tests/codeception/functional/WPGraphQLModuleTestCest.php rename to tests/codeception/functional/WPGraphQLModuleCest.php index c98838d..2f2d183 100644 --- a/tests/codeception/functional/WPGraphQLModuleTestCest.php +++ b/tests/codeception/functional/WPGraphQLModuleCest.php @@ -6,7 +6,7 @@ use \FunctionalTester; use Tests\WPGraphQL\Logger\CodeceptLogger as Signal; -class WPGraphQLModuleTestCest { +class WPGraphQLModuleCest { public function testGetRequest( FunctionalTester $I, $scenario ) { $I->wantTo( 'send a GET request to the GraphQL endpoint and return a response' ); @@ -321,7 +321,7 @@ public function testRequestOptions( FunctionalTester $I ) { $response = $I->postRequest( $query, $variables ); - $I->assertQuerySuccessful( $response [ $I->expectField( 'createPost.post.id', Signal::NOT_NULL ) ] ); + $I->assertQuerySuccessful( $response, [ $I->expectField( 'createPost.post.id', Signal::NOT_NULL ) ] ); $id = $I->lodashGet( $response, 'data.createPost.post.id' ); @@ -335,6 +335,6 @@ public function testRequestOptions( FunctionalTester $I ) { $response = $I->postRequest( $query, [ 'id' => $id ], [ 'suppress_mod_token' => true ] ); - $I->assertQueryError( $response ); + $I->assertQuerySuccessful( $response, [ $I->expectField( 'post', Signal::IS_NULL ) ] ); } } diff --git a/tests/codeception/wpunit.suite.dist.yml b/tests/codeception/wpunit.suite.dist.yml index c93f443..f1703b5 100644 --- a/tests/codeception/wpunit.suite.dist.yml +++ b/tests/codeception/wpunit.suite.dist.yml @@ -5,10 +5,10 @@ actor: WpunitTester modules: enabled: - - WPLoader + - \lucatume\WPBrowser\Module\WPLoader - \Helper\Wpunit config: - WPLoader: + \lucatume\WPBrowser\Module\WPLoader: wpRootFolder: "%WP_ROOT_FOLDER%" dbName: "%TEST_DB_NAME%" dbHost: "%TEST_DB_HOST%" From 15c7e58ccaf7d5dccb1c20153af09793a6b524ed Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Wed, 15 May 2024 12:45:49 -0400 Subject: [PATCH 4/4] chore: Unnecessary debug logs removed --- src/Codeception/Module/WPGraphQL.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Codeception/Module/WPGraphQL.php b/src/Codeception/Module/WPGraphQL.php index d802a27..e4fc50e 100644 --- a/src/Codeception/Module/WPGraphQL.php +++ b/src/Codeception/Module/WPGraphQL.php @@ -90,8 +90,6 @@ protected function parseRequestOptions( array $selected_options ) { $request_options['headers'] = array_merge( $request_options['headers'], $selected_options['headers'] ); } - \codecept_debug( $request_options ); - return $request_options; }