Undefined property: TestName::$not on PHP 8.1.20
Closed this issue · 0 comments
Description
I'm working on adding PHPUnit tests for some WPGraphQL code that we're working on.
Thank you for setting up this project to make that task a big easier!
I encountered this error when running the sample test within our test suite. The test is called "RedirectTest" because that's the class I'm working on testing - however the code within the test currently is a copy/paste of lines 4 through 261 from here: https://github.com/wp-graphql/wp-graphql-testcase/blob/develop/tests/phpunit/unit/test-wpgraphqlunittestcase.php
When I run this test suite, I encounter the following errors:
Error Output from PHPUnit
composer test -- tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php
> php8.1 ./vendor/bin/phpunit --configuration phpunit.xml 'tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php'
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.6.6 by Sebastian Bergmann and contributors.
PHP Deprecated: Return type of GraphQL\Type\Definition\Type::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Definition/Type.php on line 311
PHP Deprecated: Return type of GraphQL\Language\SourceLocation::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Language/SourceLocation.php on line 49
PHP Deprecated: Return type of GraphQL\Language\AST\NodeList::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Language/AST/NodeList.php on line 72
PHP Deprecated: Return type of GraphQL\Executor\ExecutionResult::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ExecutionResult.php on line 118
{
"data": {
"post": {
"id": "cG9zdDo0",
"databaseId": 4
},
"posts": {
"nodes": [
{
"id": "cG9zdDo1"
},
{
"id": "cG9zdDo0"
}
]
}
},
"extensions": {
"debug": [
{
"type": "DEBUG_LOGS_INACTIVE",
"message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
}
]
}
}E
Deprecated: Return type of GraphQL\Type\Definition\Type::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Definition/Type.php on line 311
Deprecated: Return type of GraphQL\Language\SourceLocation::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Language/SourceLocation.php on line 49
Deprecated: Return type of GraphQL\Language\AST\NodeList::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Language/AST/NodeList.php on line 72
Deprecated: Return type of GraphQL\Executor\ExecutionResult::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ExecutionResult.php on line 118
PHP Deprecated: Return type of GraphQL\Error\Error::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Error/Error.php on line 370
{
"errors": [
{
"message": "testErrorQuery worked as expected",
"extensions": {
"category": "user"
},
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"testFailingType",
"try"
]
}
],
"data": {
"testFailingType": {
"try": null,
"trying": [
"No",
"fails",
"here",
"either"
]
}
},
"extensions": {
"debug": [
{
"type": "DEBUG_LOGS_INACTIVE",
"message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
}
]
}
}E
Deprecated: Return type of GraphQL\Error\Error::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /workspaces/trd-news-back-end/wordpress/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Error/Error.php on line 370
{
"data": {
"posts": {
"nodes": [
{
"databaseId": 6,
"categories": {
"nodes": [
{
"databaseId": 9
}
]
}
}
]
}
},
"extensions": {
"debug": [
{
"type": "DEBUG_LOGS_INACTIVE",
"message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
}
]
}
}E{
"data": {
"posts": {
"pageInfo": {
"hasPreviousPage": false
},
"edges": [
{
"node": {
"databaseId": 7,
"categories": {
"edges": [
{
"node": {
"databaseId": 10
}
}
]
}
}
}
]
}
},
"extensions": {
"debug": [
{
"type": "DEBUG_LOGS_INACTIVE",
"message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
}
]
}
}E 4 / 4 (100%)
Time: 00:01.375, Memory: 98.50 MB
There were 4 errors:
1) RedirectTest::test_AssertQuerySuccessful
Undefined property: RedirectTest::$not
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:144
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:86
/workspaces/trd-news-back-end/tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php:38
2) RedirectTest::test_AssertQueryError
Undefined property: RedirectTest::$not
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:144
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:86
/workspaces/trd-news-back-end/tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php:149
3) RedirectTest::test_ComplexExpectedNodes
Undefined property: RedirectTest::$not
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:144
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:86
/workspaces/trd-news-back-end/tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php:194
4) RedirectTest::test_ComplexExpectedEdges
Undefined property: RedirectTest::$not
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:144
/workspaces/trd-news-back-end/vendor/wp-graphql/wp-graphql-testcase/src/TestCase/WPGraphQLTestCommon.php:86
/workspaces/trd-news-back-end/tests/themes/trd-news/theme-setup/wpgraphql/queries/RedirectTest.php:241
ERRORS!
Tests: 4, Assertions: 0, Errors: 4.
Script php8.1 ./vendor/bin/phpunit --configuration phpunit.xml handling the test event returned with error code 2
The breaking issue here is Undefined property: RedirectTest::$not
. The other Deprecated warnings don't appear to have an affect.
To Reproduce
Because this is within a proprietary codebase, unfortunately I can't share the full setup. If necessary, I may be able to set up a minimal reproduction, however that may also be quite involved as this test is running within a VS Code dev container with many dependencies.
Please let me know if a minimal reproduction repo is required.
Expected Behavior
The test runs without errors.
Screenshots
Error output:
Desktop (please complete the following information):
- OS: Mac OS 13.5.1 (22G90)
- VS Code Version: 1.82.2 (Universal)
- Docker Desktop v4.23.0
- PHP 8.1.20 in CLI where the test is running
- PHPUnit 9.6.6
- WPGraphQL 1.14.3
Additional context
I have a potential solution that gets this working on my end, I'll open a PR shortly.