Skip to content

Commit

Permalink
Merge aa61122 into 94863cd
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoulain committed Mar 1, 2021
2 parents 94863cd + aa61122 commit 543aa90
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 106 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Expand Up @@ -8,7 +8,6 @@
/features export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/phpunit_mongodb.xml export-ignore
/tests export-ignore
/update-js.sh export-ignore
/yarn.lock export-ignore
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Expand Up @@ -485,7 +485,7 @@ jobs:
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction

mongodb:
name: Behat (PHP ${{ matrix.php }}) (MongoDB)
name: PHPUnit + Behat (PHP ${{ matrix.php }}) (MongoDB)
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
Expand Down Expand Up @@ -528,8 +528,8 @@ jobs:
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run PHPUnit
run: vendor/bin/simple-phpunit
- name: Run PHPUnit tests
run: vendor/bin/simple-phpunit --group mongodb
- name: Run Behat tests
run: vendor/bin/behat -vv --out=std --format=progress --profile=mongodb --no-interaction

Expand Down Expand Up @@ -584,8 +584,6 @@ jobs:
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run PHPUnit tests
run: vendor/bin/simple-phpunit
- name: Run Behat tests
run: vendor/bin/behat --out=std --format=progress --profile=elasticsearch --no-interaction

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@
* OpenAPI: Fix error when schema is empty (#4051)
* OpenAPI: Do not set scheme to oauth2 when generating securitySchemes (#4073)
* OpenAPI: Fix missing `$ref` when no `type` is used in context (#4076)
* GraphQL: Fix "Resource class cannot be determined." error when a null iterable field is returned (#4092)

## 2.6.2

Expand Down
17 changes: 17 additions & 0 deletions features/graphql/query.feature
Expand Up @@ -59,6 +59,23 @@ Feature: GraphQL query support
And the JSON node "data.dummy.jsonData.bar" should be equal to 5
And the JSON node "data.dummy.arrayData[2]" should be equal to baz

Scenario: Retrieve an item with an iterable null field
Given there are 2 dummy with null JSON objects
When I send the following GraphQL request:
"""
{
withJsonDummy(id: "/with_json_dummies/2") {
id
json
}
}
"""
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json"
And the JSON node "data.withJsonDummy.id" should be equal to "/with_json_dummies/2"
And the JSON node "data.withJsonDummy.json" should be null

Scenario: Retrieve an item through a GraphQL query with variables
When I have the following GraphQL request:
"""
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -16,7 +16,7 @@
<server name="SYMFONY_PHPUNIT_REMOVE" value="symfony/yaml" />
<server name="KERNEL_DIR" value="tests/Fixtures/app/" />
<server name="KERNEL_CLASS" value="AppKernel" />
<server name="APP_ENV" value="test" />
<env name="APP_ENV" value="test" />
</php>

<testsuites>
Expand Down
41 changes: 0 additions & 41 deletions phpunit_mongodb.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/GraphQl/Resolver/Factory/ItemResolverFactory.php
Expand Up @@ -59,7 +59,7 @@ public function __invoke(?string $resourceClass = null, ?string $rootClass = nul
{
return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operationName) {
// Data already fetched and normalized (field or nested resource)
if (isset($source[$info->fieldName])) {
if ($source && \array_key_exists($info->fieldName, $source)) {
return $source[$info->fieldName];
}

Expand Down
25 changes: 25 additions & 0 deletions tests/Behat/DoctrineContext.php
Expand Up @@ -81,6 +81,7 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\ThirdLevel as ThirdLevelDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\UrlEncodedId as UrlEncodedIdDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\User as UserDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\WithJsonDummy as WithJsonDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\AbsoluteUrlDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\AbsoluteUrlRelationDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Address;
Expand Down Expand Up @@ -155,6 +156,7 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UrlEncodedId;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\User;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UuidIdentifierDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\WithJsonDummy;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Doctrine\ODM\MongoDB\DocumentManager;
Expand Down Expand Up @@ -574,6 +576,21 @@ public function thereAreDummyObjectsWithJsonData(int $nb)
$this->manager->flush();
}

/**
* @Given there are :nb dummy with null JSON objects
*/
public function thereAreDummyWithNullJsonObjects(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$dummy = $this->buildWithJsonDummy();
$dummy->json = null;

$this->manager->persist($dummy);
}

$this->manager->flush();
}

/**
* @Given there are :nb dummy objects with relatedDummy and its thirdLevel
* @Given there is :nb dummy object with relatedDummy and its thirdLevel
Expand Down Expand Up @@ -2199,4 +2216,12 @@ private function buildCustomMultipleIdentifierDummy()
{
return $this->isOrm() ? new CustomMultipleIdentifierDummy() : new CustomMultipleIdentifierDummyDocument();
}

/**
* @return WithJsonDummy|WithJsonDummyDocument
*/
private function buildWithJsonDummy()
{
return $this->isOrm() ? new WithJsonDummy() : new WithJsonDummyDocument();
}
}
120 changes: 120 additions & 0 deletions tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php
Expand Up @@ -395,6 +395,36 @@ public function provideApplyTestData(): array
],
$filterFactory,
],
'partial (multiple values)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('CaSE'),
new Regex('SENSitive'),
],
],
],
],
],
$filterFactory,
],
'partial (multiple values; case insensitive)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('CaSE', 'i'),
new Regex('inSENSitive', 'i'),
],
],
],
],
],
$filterFactory,
],
'start' => [
[
[
Expand Down Expand Up @@ -423,6 +453,36 @@ public function provideApplyTestData(): array
],
$filterFactory,
],
'start (multiple values)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('^CaSE'),
new Regex('^SENSitive'),
],
],
],
],
],
$filterFactory,
],
'start (multiple values; case insensitive)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('^CaSE', 'i'),
new Regex('^inSENSitive', 'i'),
],
],
],
],
],
$filterFactory,
],
'end' => [
[
[
Expand Down Expand Up @@ -451,6 +511,36 @@ public function provideApplyTestData(): array
],
$filterFactory,
],
'end (multiple values)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('CaSE$'),
new Regex('SENSitive$'),
],
],
],
],
],
$filterFactory,
],
'end (multiple values; case insensitive)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('CaSE$', 'i'),
new Regex('inSENSitive$', 'i'),
],
],
],
],
],
$filterFactory,
],
'word_start' => [
[
[
Expand Down Expand Up @@ -479,6 +569,36 @@ public function provideApplyTestData(): array
],
$filterFactory,
],
'word_start (multiple values)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('(^CaSE.*|.*\sCaSE.*)'),
new Regex('(^SENSitive.*|.*\sSENSitive.*)'),
],
],
],
],
],
$filterFactory,
],
'word_start (multiple values; case insensitive)' => [
[
[
'$match' => [
'name' => [
'$in' => [
new Regex('(^CaSE.*|.*\sCaSE.*)', 'i'),
new Regex('(^inSENSitive.*|.*\sinSENSitive.*)', 'i'),
],
],
],
],
],
$filterFactory,
],
'invalid value for relation' => [
[],
$filterFactory,
Expand Down

0 comments on commit 543aa90

Please sign in to comment.