This repository has been archived by the owner on Jan 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from wp-graphql/feature/unit-test-setup
Adding Unit Tests
- Loading branch information
Showing
10 changed files
with
155 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# WPGraphQL Insights | ||
|
||
This adds tracing to WPGraphQL, per this spec: https://github.com/apollographql/apollo-tracing | ||
[![Build Status](https://travis-ci.org/wp-graphql/wp-graphql-insights.svg?branch=master)](https://travis-ci.org/wp-graphql/wp-graphql-insights) | ||
[![Coverage Status](https://coveralls.io/repos/github/wp-graphql/wp-graphql-insights/badge.svg?branch=master)](https://coveralls.io/github/wp-graphql/wp-graphql-insights?branch=master) | ||
|
||
This adds tracing to WPGraphQL, per the proposed Apollo Tracing Spec: https://github.com/apollographql/apollo-tracing | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
class Test_WPGraphQL_Integration extends WP_UnitTestCase { | ||
|
||
/** | ||
* Let's ensure that Tracing is output as expected in the extensions of the GraphQL Response | ||
*/ | ||
function testGraphQLQueryTracingInResponse() { | ||
\WPGraphQL\Extensions\Insights\Tracing::$include_in_response = true; | ||
$query = '{posts{edges{node{id}}}}'; | ||
$results = do_graphql_request( $query ); | ||
$this->assertArrayNotHasKey( 'errors', $results ); | ||
$this->assertArrayHasKey( 'tracing', $results['extensions'] ); | ||
} | ||
|
||
function testGraphQLQueryTracingNotInResponseWhenDisabled() { | ||
|
||
// Disable including tracing in the response | ||
\WPGraphQL\Extensions\Insights\Tracing::$include_in_response = false; | ||
|
||
// Run a query | ||
$query = '{posts{edges{node{id}}}}'; | ||
$results = do_graphql_request( $query ); | ||
|
||
// Make sure the query didn't respond with any errors | ||
$this->assertArrayNotHasKey( 'errors', $results ); | ||
|
||
// There's a chance there might be other extensions at some point, so let's not be | ||
// too strict on the assertion here. We want to make sure that if tracing is disabled that | ||
// either no extensions are present in the results OR tracing _at least_ is not present | ||
if ( ! empty( $results['extensions'] ) ) { | ||
$this->assertArrayNotHasKey( 'tracing', $results['extensions'] ); | ||
} else { | ||
$this->assertArrayNotHasKey( 'extensions', $results ); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
class Test_WPGraphQLInsights extends WP_UnitTestCase { | ||
|
||
/** | ||
* Ensure that the function that instantiates the plugin properly returns the class instance | ||
*/ | ||
function testGraphQLInsightsInit() { | ||
$actual = \WPGraphQL\Extensions\graphql_insights_init(); | ||
$this->assertEquals( \WPGraphQL\Extensions\Insights::instance(), $actual ); | ||
} | ||
|
||
} |