Skip to content

Provide tests to validate issue #2310 #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2310Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Documents74\GH2310Container;

class GH2310Test extends BaseTest
{
public function setUp(): void
{
if (\version_compare((string) \phpversion(), '7.4.0', '<')) {
self::markTestSkipped('PHP 7.4 is required to run this test');
}

parent::setUp();
}

public function testFindWithNullableEmbedded(): void
{
$document = new GH2310Container(10, null);
$this->dm->persist($document);
$this->dm->flush();
$this->dm->clear();

$repository = $this->dm->getRepository(GH2310Container::class);
$result = $repository->find($document->id);

self::assertInstanceOf(GH2310Container::class, $result);
self::assertSame($document->id, $result->id);
self::assertNull($result->embedded);
}

public function testAggregatorBuilderWithNullableEmbedded(): void
{
$document = new GH2310Container(10, null);
$this->dm->persist($document);
$this->dm->flush();
$this->dm->clear();

$aggBuilder = $this->dm->createAggregationBuilder(GH2310Container::class);
$aggBuilder->match()->field('id')->equals($document->id);
$result = $aggBuilder->hydrate(GH2310Container::class)->getAggregation()->getIterator()->current();

self::assertInstanceOf(GH2310Container::class, $result);
self::assertSame($document->id, $result->id);
self::assertNull($result->embedded);
}
}
31 changes: 31 additions & 0 deletions tests/Documents74/GH2310Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Documents74;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document()
*/
class GH2310Container
{
/** @ODM\Id(strategy="none") */
public int $id;

/** @ODM\EmbedOne(targetDocument=GH2310Embedded::class, nullable=true) */
public ?GH2310Embedded $embedded;

public function __construct(int $id, ?GH2310Embedded $embedded)
{
$this->id = $id;
$this->embedded = $embedded;
}
}

class GH2310Embedded
{
/** @ODM\Field(type="integer") */
public int $value;
}