Skip to content

Commit

Permalink
fix tests for MongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
usu committed Apr 14, 2024
1 parent 06ff3c6 commit 80a982d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Post;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Serializer\Annotation\Groups;

Expand All @@ -42,6 +45,16 @@ class PropertyCollectionIriOnlyRelation
#[ODM\ReferenceOne(targetDocument: PropertyCollectionIriOnly::class)]
private ?PropertyCollectionIriOnly $propertyCollectionIriOnly = null;

#[ODM\ReferenceMany(targetDocument: PropertyCollectionIriOnlyRelationSecondLevel::class)]
#[ApiProperty(uriTemplate: '/property_collection_iri_only_relations/{parentId}/children')]
#[Groups('read')]
private Collection $children;

public function __construct()
{
$this->children = new ArrayCollection();
}

public function getId(): ?int
{
return $this->id ?? 9999;
Expand All @@ -56,4 +69,34 @@ public function setPropertyCollectionIriOnly(?PropertyCollectionIriOnly $propert
{
$this->propertyCollectionIriOnly = $propertyCollectionIriOnly;
}

/**
* @return Collection<int, PropertyCollectionIriOnlyRelationSecondLevel>
*/
public function getChildren(): Collection
{
return $this->children;
}

public function addChild(PropertyCollectionIriOnlyRelationSecondLevel $child): self
{
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}

return $this;
}

public function removeChild(PropertyCollectionIriOnlyRelationSecondLevel $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;

use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Post;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[
Post,
GetCollection(uriTemplate: '/property-collection-relation-second-levels'),
GetCollection(
uriTemplate: '/property_collection_iri_only_relations/{parentId}/children',
uriVariables: [
'parentId' => new Link(toProperty: 'parent', fromClass: PropertyCollectionIriOnlyRelation::class),
]
)
]
#[ODM\Document]
class PropertyCollectionIriOnlyRelationSecondLevel
{
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
private ?int $id = null;

#[ODM\ReferenceOne(targetDocument: PropertyCollectionIriOnlyRelation::class)]
private ?PropertyCollectionIriOnly $parent = null;

public function getId(): ?int
{
return $this->id ?? 9999;
}

public function getParent(): ?PropertyCollectionIriOnlyRelation
{
return $this->parent;

Check failure on line 47 in tests/Fixtures/TestBundle/Document/PropertyCollectionIriOnlyRelationSecondLevel.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Method ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnlyRelationSecondLevel::getParent() should return ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnlyRelation|null but returns ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnly|null.
}

public function setParent(?PropertyCollectionIriOnlyRelation $parent): void
{
$this->parent = $parent;

Check failure on line 52 in tests/Fixtures/TestBundle/Document/PropertyCollectionIriOnlyRelationSecondLevel.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Property ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnlyRelationSecondLevel::$parent (ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnly|null) does not accept ApiPlatform\Tests\Fixtures\TestBundle\Document\PropertyCollectionIriOnlyRelation|null.
}
}

0 comments on commit 80a982d

Please sign in to comment.