Skip to content

Commit

Permalink
Merge pull request #224 from woocommerce/24-11/sync-950-beta-2
Browse files Browse the repository at this point in the history
9.5.0-beta.2
  • Loading branch information
Luc45 authored Dec 2, 2024
2 parents 9b834e0 + ac349dd commit c211c5e
Show file tree
Hide file tree
Showing 30 changed files with 46,653 additions and 50 deletions.
1 change: 1 addition & 0 deletions _tests/managed_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tests/*
!tests/__snapshots__
!tests/self_test
!tests/QITE2ETestCase.php
7 changes: 6 additions & 1 deletion _tests/managed_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ To run only a single test type, run `php QitSelfTests.php run TEST_TYPE`. For ex
- Create a new `env.php` file with the parameters for the test, eg: `performance/test-1/env.php`. Copy the file format from existing tests.
- Create the SUT plugin directory with the plugin files to test, eg: `performance/test-1/{SLUG}`, where `{SLUG}` follows the same convention as existing tests.

That's it, now you can run `php QitSelfTests.php run performance` to run the test. Validate that the snapshot is correct, and commit the snapshot.
That's it, now you can run `php QitSelfTests.php run performance` to run the test. Validate that the snapshot is correct, and commit the snapshot.

## Running the self-tests

- `./vendor/bin/phpunit ./tests/self_test`
- Or `./vendor/bin/phpunit -d --update-snapshots ./tests/self_test`
27 changes: 26 additions & 1 deletion _tests/managed_tests/tests/QITE2ETestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,36 @@ public function validate_and_normalize( string $file_path, ?callable $callback =
return true;
}

// Check if $value is a JSON string
if ( is_string( $value ) ) {
$decoded_value = json_decode( $value, true );
if ( json_last_error() === JSON_ERROR_NONE ) {
$value = $decoded_value;
} else {
// If it's not valid JSON, return false
echo "json_decode error: " . json_last_error_msg() . "\n";
return false;
}
}

// Now, $value should be an array
if ( is_array( $value ) ) {
// Encode the array to JSON with proper options
$value = json_encode( $value );
if ( $value === false ) {
echo "json_encode error: " . json_last_error_msg() . "\n";
return false;
}
} else {
// If $value is neither an array nor a valid JSON string
echo "Value is neither an array nor a valid JSON string.\n";
return false;
}

return ! is_null( json_decode( $value ) );
// Validate the JSON
$is_valid = json_decode( $value ) !== null && json_last_error() === JSON_ERROR_NONE;

return $is_valid;
},
],
'test_result_aws_expiration' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,12 +2953,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,12 +2953,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,12 +2953,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2953,12 +2953,7 @@
},
{
"debug_log": {
"generic": [
{
"count": "10000",
"message": "PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-mail-logging domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in \\/var\\/www\\/html\\/wp-includes\\/functions.php on line 6114"
}
]
"generic": []
}
}
]
Expand Down
3 changes: 3 additions & 0 deletions _tests/managed_tests/tests/self_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory is just a set of self-tests for the parsing of the results, useful to debug the parser without having to wait for one hour for a test to run. There's nothing running this automatically, you can consider it a development tool.

Check the self-tests readme for more information on how to run them.
20 changes: 20 additions & 0 deletions _tests/managed_tests/tests/self_test/ResultParsingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace QITE2E\self_test;

use QITE2E\QITE2ETestCase;
use Spatie\Snapshots\MatchesSnapshots;

class ResultParsingTest extends QITE2ETestCase {
use MatchesSnapshots;

/*
* For each file in __DIR__ . 'result_jsons' directory, assert that the result of validate_and_normalize is equal to the snapshot.
*/
public function test_result_parsing() {
$files = glob( __DIR__ . '/result_jsons/*.json' );
foreach ( $files as $file ) {
$this->assertMatchesSnapshot( $this->validate_and_normalize( $file ) );
}
}
}
Loading

0 comments on commit c211c5e

Please sign in to comment.