Skip to content

Commit f5cf934

Browse files
committed
mongodb
1 parent a24c5ea commit f5cf934

2 files changed

Lines changed: 90 additions & 4 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
use ApiPlatform\Metadata\Get;
18+
use ApiPlatform\Metadata\GetCollection;
19+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
20+
21+
#[ODM\Document]
22+
#[ApiResource(
23+
uriTemplate: 'parameter_on_properties',
24+
operations: [
25+
new GetCollection(),
26+
new Get(),
27+
]
28+
)]
29+
class ParameterOnProperties
30+
{
31+
#[ODM\Id]
32+
private ?string $id = null;
33+
34+
#[ODM\Field(type: 'string')]
35+
private string $name = '';
36+
37+
#[ODM\Field(type: 'string', nullable: true)]
38+
private ?string $description = null;
39+
40+
public function __construct(string $name = '', ?string $description = null)
41+
{
42+
$this->name = $name;
43+
$this->description = $description;
44+
}
45+
46+
public function getId(): ?string
47+
{
48+
return $this->id;
49+
}
50+
51+
public function getName(): string
52+
{
53+
return $this->name;
54+
}
55+
56+
public function setName(string $name): self
57+
{
58+
$this->name = $name;
59+
60+
return $this;
61+
}
62+
63+
public function getDescription(): ?string
64+
{
65+
return $this->description;
66+
}
67+
68+
public function setDescription(?string $description): self
69+
{
70+
$this->description = $description;
71+
72+
return $this;
73+
}
74+
}

tests/Functional/Parameters/ParameterOnPropertiesTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
namespace ApiPlatform\Tests\Functional\Parameters;
1515

1616
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
17+
use ApiPlatform\Tests\Fixtures\TestBundle\Document\ParameterOnProperties as DocumentParameterOnProperties;
1718
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ParameterOnProperties;
1819
use ApiPlatform\Tests\RecreateSchemaTrait;
1920
use ApiPlatform\Tests\SetupClassResourcesTrait;
21+
use Doctrine\ODM\MongoDB\MongoDBException;
2022

2123
final class ParameterOnPropertiesTest extends ApiTestCase
2224
{
@@ -38,7 +40,11 @@ public static function getResources(): array
3840
*/
3941
protected function setUp(): void
4042
{
41-
$this->recreateSchema([ParameterOnProperties::class]);
43+
$entities = $this->isMongoDB()
44+
? [DocumentParameterOnProperties::class]
45+
: [ParameterOnProperties::class];
46+
47+
$this->recreateSchema($entities);
4248
$this->loadFixtures();
4349
}
4450

@@ -57,13 +63,19 @@ public function testQueryParameterOnProperty(): void
5763
$this->assertSame('qoox', $members[1]['name']);
5864
}
5965

66+
/**
67+
* @throws \Throwable
68+
* @throws MongoDBException
69+
*/
6070
private function loadFixtures(): void
6171
{
6272
$manager = $this->getManager();
6373

64-
$manager->persist(new ParameterOnProperties('foo', 'bar'));
65-
$manager->persist(new ParameterOnProperties('baz', 'qux'));
66-
$manager->persist(new ParameterOnProperties('qoox', 'corge'));
74+
$entityClass = $this->isMongoDB() ? DocumentParameterOnProperties::class : ParameterOnProperties::class;
75+
76+
$manager->persist(new $entityClass('foo', 'bar'));
77+
$manager->persist(new $entityClass('baz', 'qux'));
78+
$manager->persist(new $entityClass('qoox', 'corge'));
6779

6880
$manager->flush();
6981
}

0 commit comments

Comments
 (0)