Skip to content

Commit

Permalink
Reproduce internal error unsuccessfully
Browse files Browse the repository at this point in the history
Ref #425
  • Loading branch information
ondrejmirtes committed Feb 6, 2023
1 parent 44e77f0 commit 148fd32
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class QueryBuilderGetQueryDynamicReturnTypeExtensionTest extends TypeInferenceTe
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/../data/QueryResult/queryBuilderGetQuery.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../data/QueryResult/bug-245.php');
}

/**
Expand Down
36 changes: 36 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/Entities/Many.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinColumns;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping as ORM;

/**
* @Entity
Expand Down Expand Up @@ -102,3 +103,38 @@ class Many
*/
public $compoundPkAssoc;
}

/**
* @Entity
*/
class Bug245Episode
{
/**
* @var \Doctrine\Common\Collections\Collection<Bug245Segment>
* @ORM\OneToMany(
* targetEntity="App\VideoBundle\Entity\Segment",
* mappedBy="episode",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @ORM\OrderBy({"position" = "ASC"})
*/
private $segments;
}

/**
* @ORM\Entity
*/
class Bug245Segment
{
/**
* @ORM\ManyToOne(
* targetEntity="App\VideoBundle\Entity\Episode",
* inversedBy="segments",
* cascade={"persist"}
* )
* @ORM\JoinColumn(name="episode_id", referencedColumnName="id", nullable=false)
* @var Bug245Episode
*/
private $episode;
}
34 changes: 34 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/bug-245.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace QueryResult\CreateQuery;

use Doctrine\ORM\EntityManager;
use QueryResult\Entities\Bug245Episode;
use QueryResult\Entities\Bug245Segment;
use function PHPStan\Testing\assertType;

class Foo
{

/** @var EntityManager */
private $em;

public function doFoo(): void
{
$result = $this->em->createQueryBuilder()
->select('episode.id')
->from(Bug245Episode::class, 'episode', 'episode.id')
->where('episode.segmentsComplete = false')
->andWhere('0 != SIZE(episode.segments)')
->andWhere(
'0 < (SELECT COUNT(last_segment.id) FROM ' . Bug245Segment::class . ' as last_segment
WHERE last_segment.episode = episode.id AND last_segment.isLastSegment = true)'
)
->andWhere(
"0 = (SELECT COUNT(segment.id) FROM " . Bug245Segment::class . " as segment
WHERE segment.episode = episode.id AND segment.state != 'distributed')"
)->getQuery()->getResult();
assertType('mixed', $result);
}

}

1 comment on commit 148fd32

@kalimatas
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I have the same issue as in #425. I managed to "fix" it by switching to class reference "ClassName::class" instead of "BundleName:Entity" syntax in the from clause.

I see that the bug reported in 425 uses the "BundleName:Entity" syntax, but here you're using "ClassName::class". Could it be the reason why it's not reproducible?

Best,
Alex

Please sign in to comment.