File: DDC812Test.php

package info (click to toggle)
doctrine 2.14.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,612 kB
  • sloc: php: 113,660; xml: 4,630; makefile: 28; sh: 14
file content (50 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsComment;
use Doctrine\Tests\OrmFunctionalTestCase;

use function get_class;

class DDC812Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        $this->useModelSet('cms');

        parent::setUp();
    }

    /** @group DDC-812 */
    public function testFetchJoinInitializesPreviouslyUninitializedCollectionOfManagedEntity(): void
    {
        $article        = new CmsArticle();
        $article->topic = 'hello';
        $article->text  = 'talk talk talk';

        $comment          = new CmsComment();
        $comment->topic   = 'good!';
        $comment->text    = 'stuff!';
        $comment->article = $article;

        $this->_em->persist($article);
        $this->_em->persist($comment);
        $this->_em->flush();
        $this->_em->clear();

        $article2 = $this->_em->find(get_class($article), $article->id);

        $article2Again = $this->_em->createQuery(
            'select a, c from Doctrine\Tests\Models\CMS\CmsArticle a join a.comments c where a.id = ?1'
        )
            ->setParameter(1, $article->id)
            ->getSingleResult();

        self::assertSame($article2Again, $article2);
        self::assertTrue($article2Again->comments->isInitialized());
    }
}