Skip to content

Commit

Permalink
Merge pull request #13 from wp-graphql/hotfix/typo-in-WPGraphQLTestCo…
Browse files Browse the repository at this point in the history
…mmon.php

fix typo
  • Loading branch information
jasonbahl committed Jul 2, 2021
2 parents 249cdb0 + 8ab5d37 commit c37e7a7
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/TestCase/WPGraphQLTestCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function clearSchema() {
/**
* A simple helper for clearing a loaders cache. The is good for when
* running a query multiple times and wish to ensure that the value returned
* isn't a cached value.
* isn't a cached value.
*
* @param string $loader_name Loader slug name.
*
Expand Down Expand Up @@ -186,12 +186,12 @@ public static function isNested( array $expected_data ) {

/**
* Asserts if $expected_value matches $data.
*
*
* @param array $data Data object be evaluted.
* @param mixed $expected_value Value $data is expected to evalute to.
* @param bool $match_wanted Whether $expected_value and $data should be equal or different.
* @param string $message Error message to be display if assertion fails.
*
*
* @return bool
*/
public static function doesFieldMatch( $data, $expected_value, $match_wanted ) {
Expand All @@ -216,11 +216,11 @@ public static function doesFieldMatch( $data, $expected_value, $match_wanted ) {

/**
* Asserts if $expected_value matches one of the entries in $data.
*
*
* @param array $data Data object be evaluted.
* @param mixed $expected_value Value $data is expected to evalute to.
* @param bool $match_wanted Whether $expected_value and $data should be equal or different.
*
*
* @return bool
*/
public static function doesFieldMatchGroup( $data, $expected_value, $match_wanted ) {
Expand All @@ -245,10 +245,10 @@ public static function doesFieldMatchGroup( $data, $expected_value, $match_wante
// Pass if match found and match wanted.
if ( $field_matches && $match_wanted ) {
return true;

// Fail if match found and no matches wanted.
} elseif ( ! $field_matches && ! $match_wanted ) {
return false;
return false;
}
}

Expand All @@ -268,9 +268,9 @@ public static function doesFieldMatchGroup( $data, $expected_value, $match_wante
* @param array $response GraphQL query response object
* @param array $expected_data Expected data object to be evaluated.
* @param string $message Error message.
*
*
* @throws \Exception Invalid rule object provided for evaluation.
*
*
* @return bool
*/
public static function _assertExpectedDataFound( array $response, array $expected_data, string $current_path = null, &$message = null ) {
Expand Down Expand Up @@ -298,7 +298,7 @@ public static function _assertExpectedDataFound( array $response, array $expecte

// Get data at path for evaluation.
$actual_data = static::getPossibleDataAtPath( $response, $full_path, $is_group );

// Set actual data for final assertion
static::$actual = $actual_data;

Expand Down Expand Up @@ -358,13 +358,13 @@ public static function _assertExpectedDataFound( array $response, array $expecte
// Fail if no data found at path.
if ( is_null( $actual_data ) ) {
$message = $message ?? sprintf( 'No data found at path "%s"', $full_path );

return false;
}

// Return true because target value not null.
if ( $expected_value === static::NOT_NULL ) {
return true;
return true;
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ public static function _assertExpectedDataFound( array $response, array $expecte

// Pass if matcher passes.
return true;
case $is_object_rule:
case $is_object_rule:
case $is_node_rule:
case $is_edge_rule:
// Handle nested rules recursively.
Expand Down Expand Up @@ -474,7 +474,7 @@ function( $v ) {
// Set constraint.
static::$actual = self::getPossibleDataAtPath( $response['errors'], '.#.path' );
static::$last_constraint = static::contains( $target_path );

foreach ( $response['errors'] as $error ) {
if ( empty( $error['path'] ) ) {
continue;
Expand Down Expand Up @@ -519,7 +519,7 @@ function( $v ) {
$search_type_messages[ $search_type ],
$needle
);

return false;
default:
throw new \Exception( 'Invalid data object provided for evaluation.' );
Expand All @@ -532,15 +532,15 @@ function( $v ) {
*
* @param array $response GraphQL query response object.
* @param string $message References that outputs error message.
*
* @return bool
*
* @return bool
*/
private static function _assertIsValidQueryResponse( $response, &$message = null ) {
if ( array_keys( $response ) === range( 0, count( $response ) - 1 ) ) {
$message = $message ?? 'The GraphQL query response must be provided as an associative array.';
return false;
}
}

if ( empty( $response ) ) {
$message = $message ?? 'GraphQL query response is empty.';
return false;
Expand Down Expand Up @@ -586,7 +586,7 @@ public static function assertQuerySuccessful( array $response, array $expected,
$data_passing = null; // Create individual data rule evaluation flag for later use.
$response_valid = static::_assertIsValidQueryResponse( $response, $message ); // Validate response shape with sub assertion.
$response_successful = ! in_array( 'errors', array_keys( $response ) ); // Ensure no errors thrown.

// If errors thrown sent error message.
if ( $response_valid && ! $response_successful ) {
$message = $message ?? 'An error was thrown during the previous GraphQL requested. May need to use "--debug" flag to see contents of previous request.';
Expand All @@ -606,7 +606,7 @@ public static function assertQuerySuccessful( array $response, array $expected,
static::assertThat( true, static::isTrue(), '' );
return;
}

// Assert no failures.
static::assertThat(
! empty( static::$actual ) ? static::$actual : false,
Expand All @@ -625,11 +625,11 @@ public static function assertQuerySuccessful( array $response, array $expected,
* @return void
*/
public function assertQueryError( array $response, array $expected, $message = null ) {
$errors_passing = null; // Create individual error rule evaluation flag for later use.
$error_passing = null; // Create individual error rule evaluation flag for later use.
$data_passing = null; // Create individual data rule evaluation flag for later use.
$response_valid = static::_assertIsValidQueryResponse( $response, $message ); // Validate response shape with sub assertion.
$response_failed = in_array( 'errors', array_keys( $response ) ); // Ensure no errors thrown.

// If errors thrown sent error message.
if ( $response_valid && ! $response_failed ) {
$message = $message ?? 'No errors was thrown during the previous GraphQL requested. May need to use "--debug" flag to see contents of previous request.';
Expand All @@ -642,7 +642,7 @@ public function assertQueryError( array $response, array $expected, $message = n
static::logData( array( 'INVALID_DATA_OBJECT' => $expected_data ) );
throw new \Exception( 'Invalid data object provided for evaluation.' );
}

// If error data evaluate error rule and continue.
if ( static::startsWith( 'ERROR_', $expected_data['type'] ) ) {
$error_passing = static::_assertExpectedErrorFound( $response, $expected_data, $message );
Expand All @@ -651,7 +651,7 @@ public function assertQueryError( array $response, array $expected, $message = n
}
continue;
}

// Else assume it is an data rule and act accordingly.
$data_passing = static::_assertExpectedDataFound( $response, $expected_data, '', $message );
if ( ! $data_passing ) {
Expand Down Expand Up @@ -708,7 +708,7 @@ protected static function lodashGet( array $data, string $string, $default = nul
* @param array $data Data to be search
* @param string $path Formatted lodash path.
* @param boolean $is_group Function passback.
*
*
* @return mixed
*/
protected static function getPossibleDataAtPath( array $data, string $path, &$is_group = false ) {
Expand All @@ -717,7 +717,7 @@ protected static function getPossibleDataAtPath( array $data, string $path, &$is
if ( 1 < count( $branches ) ) {
$is_group = true;
$possible_data = self::lodashGet( $data, $branches[0] );

// Loop throw top branches and build out the possible data options.
if ( ! empty( $possible_data ) && is_array( $possible_data ) ) {
foreach ( $possible_data as &$next_data ) {
Expand Down Expand Up @@ -745,7 +745,7 @@ protected static function getPossibleDataAtPath( array $data, string $path, &$is
* @param string $needle String being searched for.
* @param string $haystack String being searched.
* @param int $search_type Search operation enumeration.
*
*
* @return boolean
*/
protected static function findSubstring( $needle, $haystack, $search_type ) {
Expand All @@ -766,7 +766,7 @@ protected static function findSubstring( $needle, $haystack, $search_type ) {
*
* @param string $needle String to search for
* @param string $haystack String being searched.
*
*
* @return bool
*/
protected static function startsWith( $needle, $haystack ) {
Expand All @@ -779,7 +779,7 @@ protected static function startsWith( $needle, $haystack ) {
*
* @param string $needle String to search for
* @param string $haystack String being searched.
*
*
* @return bool
*/
protected static function endsWith( $needle, $haystack ) {
Expand Down Expand Up @@ -812,7 +812,7 @@ public static function isEmpty(): IsEmpty {
* Wrapper for IsEqual constraint.
*
* @param mixed $value Desired contained value
*
*
* @return IsEqual
*/
public static function isEqual( $value ): IsEqual {
Expand All @@ -823,7 +823,7 @@ public static function isEqual( $value ): IsEqual {
* Wrapper for TraversableContainsIdentical constraint.
*
* @param mixed $value Desired contained value
*
*
* @return TraversableContains
*/
public static function contains( $value, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false ): TraversableContains {
Expand All @@ -847,4 +847,4 @@ public static function isNull(): IsNull {
public static function logicalNot( Constraint $last_constraint ): LogicalNot {
return new LogicalNot( $last_constraint );
}
}
}

0 comments on commit c37e7a7

Please sign in to comment.