-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2160 from Ludo444/bug/2157
Bug/2157 Test (and fix) Facet's aggregation pipeline with DiscriminatorMap documents
- Loading branch information
Showing
3 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2157Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\ODM\Tests\Functional\Ticket; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
use Doctrine\ODM\MongoDB\Tests\BaseTest; | ||
use function count; | ||
|
||
class GH2157Test extends BaseTest | ||
{ | ||
public function testFacetDiscriminatorMapCreation() | ||
{ | ||
$this->dm->persist(new GH2157FirstType()); | ||
$this->dm->persist(new GH2157FirstType()); | ||
$this->dm->persist(new GH2157FirstType()); | ||
$this->dm->persist(new GH2157FirstType()); | ||
$this->dm->flush(); | ||
|
||
$result = $this->dm->createAggregationBuilder(GH2157FirstType::class) | ||
->project() | ||
->includeFields(['id']) | ||
->facet() | ||
->field('count') | ||
->pipeline( | ||
$this->dm->createAggregationBuilder(GH2157FirstType::class) | ||
->count('count') | ||
) | ||
->field('limitedResults') | ||
->pipeline( | ||
$this->dm->createAggregationBuilder(GH2157FirstType::class) | ||
->limit(2) | ||
) | ||
->execute()->toArray(); | ||
|
||
$this->assertEquals(4, $result[0]['count'][0]['count']); | ||
$this->assertEquals(2, count($result[0]['limitedResults'])); | ||
} | ||
} | ||
|
||
/** | ||
* @ODM\Document(collection="documents") | ||
* @ODM\InheritanceType("SINGLE_COLLECTION") | ||
* @ODM\DiscriminatorField("type") | ||
* @ODM\DiscriminatorMap({"firsttype"=GH2157FirstType::class, "secondtype"=GH2157SecondType::class}) | ||
*/ | ||
abstract class GH2157Abstract | ||
{ | ||
/** | ||
* @ODM\Id | ||
* | ||
* @var string | ||
*/ | ||
protected $id; | ||
} | ||
|
||
/** | ||
* @ODM\Document | ||
*/ | ||
class GH2157FirstType extends GH2157Abstract | ||
{ | ||
} | ||
|
||
/** | ||
* @ODM\Document | ||
*/ | ||
class GH2157SecondType extends GH2157Abstract | ||
{ | ||
} |