ResourceMetadataCompatibilityTest fails when api-platform/elasticsearch is autoloaded
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start with src/Metadata/Tests/Extractor/ResourceMetadataCompatibilityTest.php, especially buildStateOptions() around line 731, and compare it with the extractor logic in src/Metadata/Extractor/XmlResourceExtractor.php around line 477. Run the named PHPUnit test from the monorepo root and the isolated component environment; done means both pass while the elasticsearchOptions branch is covered when available and remains null otherwise.
Written by the indexing model from the issue text.
Description
| Q | A |
|---|---|
| API Platform version | 4.3, 4.4, main |
| PHP version | 8.4 / 8.5 |
ResourceMetadataCompatibilityTest fails as soon as ApiPlatform\Elasticsearch\State\Options is autoloadable, which is the case for anyone running the component tests from the monorepo root:
$ vendor/bin/phpunit src/Metadata/Tests/Extractor/ResourceMetadataCompatibilityTest.php
There were 2 failures:
1) …::testValidMetadata#0 with data ('…XmlResourceExtractor', …XmlResourceAdapter)
Failed asserting that two objects are equal.
- 'stateOptions' => null
+ 'stateOptions' => ApiPlatform\Elasticsearch\State\Options Object (...)
Both data sets fail, and the rendered diff also shows unrelated keys such as strictQueryParameterValidation, which sends you looking in the wrong place — removing src/Elasticsearch/State/Options.php makes the whole test green again, so stateOptions is the only real difference.
Cause
The fixture declares stateOptions: {elasticsearchOptions: {index: foo_index}}, and both extractors build the real object when the component is installed:
// src/Metadata/Extractor/XmlResourceExtractor.php:477
if (isset($stateOptions->elasticsearchOptions) && class_exists(ElasticsearchOptions::class)) {
return new ElasticsearchOptions(...);
}
The expectation, on the other hand, returns null unconditionally:
// src/Metadata/Tests/Extractor/ResourceMetadataCompatibilityTest.php:731
case 'elasticsearchOptions':
return null;
So the assertion only holds when api-platform/elasticsearch is absent. CI never notices, because phpunit-components runs each component from its own directory with its own vendor/, where the class does not exist. $configuration is even read and then unused, which suggests the null was a placeholder.
Beyond the failure, this means the elasticsearchOptions branch of buildStateOptions() has no assertion on it in any environment.
Fix
Mirror the extractors: build the options when the class exists, keep returning null otherwise. The test then passes both from the monorepo root and in the isolated component job. PR follows.
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 982
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 55
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
api-platform/core#8564 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
api-platform/core#8471 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
api-platform/core#8475 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
api-platform/core#8447 ·
-
GraphQL State
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
api-platform/core#5425 · 7 comments ·
All issues in api-platform/core
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
hector-jewell/food-delivery-system-for-restaurant-using-php#1311 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Sylius/SyliusGridBundle#501 ·