Skip to content

Commit d65a42f

Browse files
committed
fix(metadata): issue reproduction tests
1 parent 4009120 commit d65a42f

9 files changed

Lines changed: 592 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7916;
15+
16+
use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
17+
use ApiPlatform\Doctrine\Orm\State\Options;
18+
use ApiPlatform\Metadata\ApiResource;
19+
use ApiPlatform\Metadata\GetCollection;
20+
use ApiPlatform\Metadata\QueryParameter;
21+
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7916\UserAction;
22+
23+
/**
24+
* API Resource DTO for UserAction using stateOptions pattern.
25+
* This is a separate API Resource for the UserAction entity which is NOT itself marked #[ApiResource].
26+
*
27+
* Tests that nested property filters work on relations to non-ApiResource entities (User).
28+
*
29+
* @see https://github.com/api-platform/core/issues/7916
30+
*/
31+
#[ApiResource(
32+
operations: [
33+
new GetCollection(
34+
uriTemplate: '/user-actions',
35+
parameters: [
36+
'name' => new QueryParameter(
37+
filter: new PartialSearchFilter(),
38+
property: 'user.name',
39+
),
40+
'email' => new QueryParameter(
41+
filter: new PartialSearchFilter(),
42+
property: 'user.email',
43+
),
44+
],
45+
),
46+
],
47+
stateOptions: new Options(entityClass: UserAction::class),
48+
)]
49+
class UserActionResource
50+
{
51+
public ?int $id = null;
52+
public ?string $action = null;
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7916;
15+
16+
use ApiPlatform\Doctrine\Odm\Filter\PartialSearchFilter;
17+
use ApiPlatform\Doctrine\Odm\State\Options;
18+
use ApiPlatform\Metadata\ApiResource;
19+
use ApiPlatform\Metadata\GetCollection;
20+
use ApiPlatform\Metadata\QueryParameter;
21+
use ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7916\UserAction;
22+
23+
/**
24+
* API Resource DTO for MongoDB UserAction using stateOptions pattern.
25+
* This is a separate API Resource for the UserAction document which is NOT itself marked #[ApiResource].
26+
*
27+
* @see https://github.com/api-platform/core/issues/7916
28+
*/
29+
#[ApiResource(
30+
operations: [
31+
new GetCollection(
32+
uriTemplate: '/user-actions',
33+
parameters: [
34+
'name' => new QueryParameter(
35+
filter: new PartialSearchFilter(),
36+
property: 'user.name',
37+
),
38+
'email' => new QueryParameter(
39+
filter: new PartialSearchFilter(),
40+
property: 'user.email',
41+
),
42+
],
43+
),
44+
],
45+
stateOptions: new Options(documentClass: UserAction::class),
46+
)]
47+
class UserActionResourceOdm
48+
{
49+
public ?int $id = null;
50+
public ?string $action = null;
51+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7916;
15+
16+
use ApiPlatform\Doctrine\Orm\State\Options;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7916\User;
19+
20+
/**
21+
* API Resource DTO for User using stateOptions pattern.
22+
* This is a separate API Resource for the User entity which is NOT itself marked #[ApiResource].
23+
*
24+
* @see https://github.com/api-platform/core/issues/7916
25+
*/
26+
#[ApiResource(
27+
stateOptions: new Options(entityClass: User::class),
28+
)]
29+
class UserResource
30+
{
31+
public ?int $id = null;
32+
public ?string $name = null;
33+
public ?string $email = null;
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue7916;
15+
16+
use ApiPlatform\Doctrine\Odm\State\Options;
17+
use ApiPlatform\Metadata\ApiResource;
18+
use ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7916\User;
19+
20+
/**
21+
* API Resource DTO for MongoDB User using stateOptions pattern.
22+
* This is a separate API Resource for the User document which is NOT itself marked #[ApiResource].
23+
*
24+
* @see https://github.com/api-platform/core/issues/7916
25+
*/
26+
#[ApiResource(
27+
stateOptions: new Options(documentClass: User::class),
28+
)]
29+
class UserResourceOdm
30+
{
31+
public ?int $id = null;
32+
public ?string $name = null;
33+
public ?string $email = null;
34+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7916;
15+
16+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17+
18+
/**
19+
* User document for issue #7916.
20+
*
21+
* This document is NOT marked with #[ApiResource] to test nested property filtering
22+
* on relations to non-API-Resource entities.
23+
*
24+
* @see https://github.com/api-platform/core/issues/7916
25+
*/
26+
#[ODM\Document(collection: 'issue_7916_user')]
27+
class User
28+
{
29+
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
30+
private ?int $id = null;
31+
32+
#[ODM\Field(type: 'string')]
33+
private ?string $name = null;
34+
35+
#[ODM\Field(type: 'string')]
36+
private ?string $email = null;
37+
38+
public function getId(): ?int
39+
{
40+
return $this->id;
41+
}
42+
43+
public function getName(): ?string
44+
{
45+
return $this->name;
46+
}
47+
48+
public function setName(?string $name): self
49+
{
50+
$this->name = $name;
51+
52+
return $this;
53+
}
54+
55+
public function getEmail(): ?string
56+
{
57+
return $this->email;
58+
}
59+
60+
public function setEmail(?string $email): self
61+
{
62+
$this->email = $email;
63+
64+
return $this;
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document\Issue7916;
15+
16+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
17+
18+
/**
19+
* MongoDB version of UserAction for issue #7916.
20+
*
21+
* This document has a reference to User (which is NOT an ApiResource).
22+
* Used to test nested property filtering on non-ApiResource relations with PartialSearchFilter.
23+
*
24+
* @see https://github.com/api-platform/core/issues/7916
25+
*/
26+
#[ODM\Document(collection: 'issue_7916_user_action')]
27+
class UserAction
28+
{
29+
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
30+
private ?int $id = null;
31+
32+
#[ODM\Field(type: 'string')]
33+
private string $action = '';
34+
35+
#[ODM\ReferenceOne(targetDocument: User::class, storeAs: 'id')]
36+
private ?User $user = null;
37+
38+
public function getId(): ?int
39+
{
40+
return $this->id;
41+
}
42+
43+
public function getAction(): string
44+
{
45+
return $this->action;
46+
}
47+
48+
public function setAction(string $action): self
49+
{
50+
$this->action = $action;
51+
52+
return $this;
53+
}
54+
55+
public function getUser(): ?User
56+
{
57+
return $this->user;
58+
}
59+
60+
public function setUser(?User $user): self
61+
{
62+
$this->user = $user;
63+
64+
return $this;
65+
}
66+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7916;
15+
16+
use Doctrine\ORM\Mapping as ORM;
17+
18+
/**
19+
* Plain Doctrine ORM entity (NOT marked #[ApiResource]).
20+
* Used to test that nested property filters work on relations to non-ApiResource entities.
21+
*
22+
* @see https://github.com/api-platform/core/issues/7916
23+
*/
24+
#[ORM\Entity]
25+
#[ORM\Table(name: 'issue_7916_user')]
26+
class User
27+
{
28+
#[ORM\Id]
29+
#[ORM\GeneratedValue]
30+
#[ORM\Column(type: 'integer')]
31+
private ?int $id = null;
32+
33+
#[ORM\Column(type: 'string', length: 255)]
34+
private ?string $name = null;
35+
36+
#[ORM\Column(type: 'string', length: 255)]
37+
private ?string $email = null;
38+
39+
public function getId(): ?int
40+
{
41+
return $this->id;
42+
}
43+
44+
public function getName(): ?string
45+
{
46+
return $this->name;
47+
}
48+
49+
public function setName(?string $name): self
50+
{
51+
$this->name = $name;
52+
53+
return $this;
54+
}
55+
56+
public function getEmail(): ?string
57+
{
58+
return $this->email;
59+
}
60+
61+
public function setEmail(?string $email): self
62+
{
63+
$this->email = $email;
64+
65+
return $this;
66+
}
67+
}

0 commit comments

Comments
 (0)