Skip to content

Commit 79c3a65

Browse files
teohhanhuivincentchalamonNek-
committed
Add Behat tests for inheritance resource class resolving
Co-authored-by: Vincent Chalamon <[email protected]> Co-authored-by: "Nek (Maxime Veber)" <[email protected]>
1 parent 3a3b059 commit 79c3a65

11 files changed

+1010
-145
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyOffer as DummyOfferDocument;
3232
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProduct as DummyProductDocument;
3333
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProperty as DummyPropertyDocument;
34+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyTableInheritanceNotApiResourceChild as DummyTableInheritanceNotApiResourceChildDocument;
3435
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddableDummy as EmbeddableDummyDocument;
3536
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddedDummy as EmbeddedDummyDocument;
3637
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FileConfigDummy as FileConfigDummyDocument;
@@ -74,6 +75,7 @@
7475
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyOffer;
7576
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProduct;
7677
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProperty;
78+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
7779
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
7880
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
7981
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
@@ -165,6 +167,17 @@ public function thereAreDummyObjects(int $nb)
165167
$this->manager->flush();
166168
}
167169

170+
/**
171+
* @When some dummy table inheritance data but not api resource child are created
172+
*/
173+
public function someDummyTableInheritanceDataButNotApiResourceChildAreCreated()
174+
{
175+
$dummy = $this->buildDummyTableInheritanceNotApiResourceChild();
176+
$dummy->setName('Foobarbaz inheritance');
177+
$this->manager->persist($dummy);
178+
$this->manager->flush();
179+
}
180+
168181
/**
169182
* @Given there are :nb foo objects with fake names
170183
*/
@@ -1272,6 +1285,14 @@ private function buildDummy()
12721285
return $this->isOrm() ? new Dummy() : new DummyDocument();
12731286
}
12741287

1288+
/**
1289+
* @return DummyTableInheritanceNotApiResourceChild|DummyTableInheritanceNotApiResourceChildDocument
1290+
*/
1291+
private function buildDummyTableInheritanceNotApiResourceChild()
1292+
{
1293+
return $this->isOrm() ? new DummyTableInheritanceNotApiResourceChild() : new DummyTableInheritanceNotApiResourceChildDocument();
1294+
}
1295+
12751296
/**
12761297
* @return DummyAggregateOffer|DummyAggregateOfferDocument
12771298
*/
@@ -1540,4 +1561,44 @@ public function testEagerLoadingNotDuplicateRelation()
15401561
$this->manager->flush();
15411562
$this->manager->clear();
15421563
}
1564+
1565+
/**
1566+
* @Given there are :nb sites with internal owner
1567+
*/
1568+
public function thereAreSitesWithInternalOwner(int $nb)
1569+
{
1570+
for ($i = 1; $i <= $nb; ++$i) {
1571+
$internalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser();
1572+
$internalUser->setFirstname('Internal');
1573+
$internalUser->setLastname('User');
1574+
$internalUser->setEmail('[email protected]');
1575+
$internalUser->setInternalId('INT');
1576+
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
1577+
$site->setTitle('title');
1578+
$site->setDescription('description');
1579+
$site->setOwner($internalUser);
1580+
$this->manager->persist($site);
1581+
}
1582+
$this->manager->flush();
1583+
}
1584+
1585+
/**
1586+
* @Given there are :nb sites with external owner
1587+
*/
1588+
public function thereAreSitesWithExternalOwner(int $nb)
1589+
{
1590+
for ($i = 1; $i <= $nb; ++$i) {
1591+
$externalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser();
1592+
$externalUser->setFirstname('External');
1593+
$externalUser->setLastname('User');
1594+
$externalUser->setEmail('[email protected]');
1595+
$externalUser->setExternalId('EXT');
1596+
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
1597+
$site->setTitle('title');
1598+
$site->setDescription('description');
1599+
$site->setOwner($externalUser);
1600+
$this->manager->persist($site);
1601+
}
1602+
$this->manager->flush();
1603+
}
15431604
}

0 commit comments

Comments
 (0)