Skip to content

Commit

Permalink
Add Behat tests for inheritance resource class resolving
Browse files Browse the repository at this point in the history
Co-authored-by: Vincent Chalamon <vincentchalamon@gmail.com>
Co-authored-by: "Nek (Maxime Veber)" <nek.dev@gmail.com>
  • Loading branch information
3 people committed May 20, 2019
1 parent b26fc59 commit b2b19f0
Show file tree
Hide file tree
Showing 12 changed files with 1,013 additions and 147 deletions.
61 changes: 61 additions & 0 deletions features/bootstrap/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyOffer as DummyOfferDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProduct as DummyProductDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyProperty as DummyPropertyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\DummyTableInheritanceNotApiResourceChild as DummyTableInheritanceNotApiResourceChildDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddableDummy as EmbeddableDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\EmbeddedDummy as EmbeddedDummyDocument;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\FileConfigDummy as FileConfigDummyDocument;
Expand Down Expand Up @@ -74,6 +75,7 @@
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyOffer;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProduct;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyProperty;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceNotApiResourceChild;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\EmbeddedDummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy;
Expand Down Expand Up @@ -165,6 +167,17 @@ public function thereAreDummyObjects(int $nb)
$this->manager->flush();
}

/**
* @When some dummy table inheritance data but not api resource child are created
*/
public function someDummyTableInheritanceDataButNotApiResourceChildAreCreated()
{
$dummy = $this->buildDummyTableInheritanceNotApiResourceChild();
$dummy->setName('Foobarbaz inheritance');
$this->manager->persist($dummy);
$this->manager->flush();
}

/**
* @Given there are :nb foo objects with fake names
*/
Expand Down Expand Up @@ -1272,6 +1285,14 @@ private function buildDummy()
return $this->isOrm() ? new Dummy() : new DummyDocument();
}

/**
* @return DummyTableInheritanceNotApiResourceChild|DummyTableInheritanceNotApiResourceChildDocument
*/
private function buildDummyTableInheritanceNotApiResourceChild()
{
return $this->isOrm() ? new DummyTableInheritanceNotApiResourceChild() : new DummyTableInheritanceNotApiResourceChildDocument();
}

/**
* @return DummyAggregateOffer|DummyAggregateOfferDocument
*/
Expand Down Expand Up @@ -1540,4 +1561,44 @@ public function testEagerLoadingNotDuplicateRelation()
$this->manager->flush();
$this->manager->clear();
}

/**
* @Given there are :nb sites with internal owner
*/
public function thereAreSitesWithInternalOwner(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$internalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\InternalUser();
$internalUser->setFirstname('Internal');
$internalUser->setLastname('User');
$internalUser->setEmail('john.doe@example.com');
$internalUser->setInternalId('INT');
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
$site->setTitle('title');
$site->setDescription('description');
$site->setOwner($internalUser);
$this->manager->persist($site);
}
$this->manager->flush();
}

/**
* @Given there are :nb sites with external owner
*/
public function thereAreSitesWithExternalOwner(int $nb)
{
for ($i = 1; $i <= $nb; ++$i) {
$externalUser = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ExternalUser();
$externalUser->setFirstname('External');
$externalUser->setLastname('User');
$externalUser->setEmail('john.doe@example.com');
$externalUser->setExternalId('EXT');
$site = new \ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Site();
$site->setTitle('title');
$site->setDescription('description');
$site->setOwner($externalUser);
$this->manager->persist($site);
}
$this->manager->flush();
}
}
Loading

0 comments on commit b2b19f0

Please sign in to comment.