This repository has been archived by the owner on Sep 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
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 #13 from caciobanu/master
Finished implementation of AliceODMContext:
- Loading branch information
Showing
16 changed files
with
273 additions
and
9 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
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
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,42 @@ | ||
Feature: Test Doctrine ODM context | ||
|
||
Scenario: Emptying the database | ||
Given the database is empty | ||
Given there is 10 "dummy" entities | ||
Then the database should contain 10 "dummy" entities | ||
When I empty the database | ||
Then the database should be empty | ||
|
||
Scenario: Loads a fixtures file with @Bundlename notation | ||
Given the database is empty | ||
Given the fixtures file "@TestBundle/DataFixtures/ODM/dummy.yml" is loaded | ||
Then the database should contain 10 "dummy" entities | ||
|
||
Scenario: Loads a fixture file based on basePath | ||
Given the database is empty | ||
Given the fixtures file "another_dummy.yml" is loaded | ||
Then the database should contain 10 "another_dummy" entities | ||
|
||
Scenario: Loads a fixture file with absolute path | ||
Given the database is empty | ||
Given the fixtures file "/home/travis/build/theofidry/AliceBundleExtension/tests/Features/fixtures/ODM/another_dummy.yml" is loaded | ||
Then the database should contain 10 "another_dummy" entities | ||
|
||
Scenario: Loads a fixture file with a custom persister | ||
Given the database is empty | ||
Given the fixtures file "another_dummy.yml" is loaded with the persister "doctrine_mongodb.odm.default_document_manager" | ||
Then the database should contain 10 "another_dummy" entities | ||
|
||
Scenario: Loads several fixtures files based on basePath | ||
Given the database is empty | ||
Given the following fixtures files are loaded: | ||
| another_dummy.yml | | ||
| one_another_dummy.yml | | ||
Then the database should contain 11 "another_dummy" entities | ||
|
||
Scenario: Loads several fixtures files with @Bundlename notation | ||
Given the database is empty | ||
Given the following fixtures files are loaded: | ||
| @TestBundle/DataFixtures/ODM/dummy.yml | | ||
| @TestBundle/DataFixtures/ODM/one_another_dummy.yml | | ||
Then the database should contain 11 "dummy" entities |
File renamed without changes.
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,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry\AliceBundleExtension package. | ||
* | ||
* (c) Théo FIDRY <theo.fidry@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Behat\Symfony2Extension\Context\KernelAwareContext; | ||
use Doctrine\ORM\EntityManager; | ||
use Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\AnotherDummy; | ||
use Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\Dummy; | ||
use PHPUnit_Framework_Assert as PHPUnit; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
/** | ||
* Class FeatureContext. | ||
* | ||
* @author Théo FIDRY <theo.fidry@gmail.com> | ||
*/ | ||
class ODMFeatureContext implements KernelAwareContext | ||
{ | ||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
/** | ||
* Sets Kernel instance. | ||
* | ||
* @param KernelInterface $kernel | ||
*/ | ||
public function setKernel(KernelInterface $kernel) | ||
{ | ||
$this->entityManager = $kernel->getContainer()->get('doctrine_mongodb.odm.default_document_manager'); | ||
} | ||
|
||
/** | ||
* @Then /^the database should be empty$/ | ||
*/ | ||
public function theDatabaseShouldBeEmpty() | ||
{ | ||
$entities = array_merge( | ||
$this->entityManager->getRepository('TestBundle:Dummy')->findAll(), | ||
$this->entityManager->getRepository('TestBundle:AnotherDummy')->findAll() | ||
); | ||
|
||
PHPUnit::assertCount(0, $entities); | ||
} | ||
|
||
/** | ||
* @Given /^there is (\d+) "([^"]*)" entities$/ | ||
*/ | ||
public function thereIsEntities($nbr, $class) | ||
{ | ||
for ($i = 0; $i < $nbr; $i++) { | ||
switch ($class) { | ||
case 'dummy': | ||
$entity = new Dummy(); | ||
$entity->name = sprintf('Dummy %d', $i); | ||
break; | ||
|
||
case 'another_dummy': | ||
$entity = new AnotherDummy(); | ||
$entity->name = sprintf('Dummy %d', $i); | ||
break; | ||
|
||
default: | ||
throw new \UnexpectedValueException(sprintf('Unknown %s entity', $class)); | ||
} | ||
|
||
$this->entityManager->persist($entity); | ||
} | ||
|
||
$this->entityManager->flush(); | ||
$this->entityManager->clear('Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\Dummy'); | ||
$this->entityManager->clear( | ||
'Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\AnotherDummy' | ||
); | ||
} | ||
|
||
/** | ||
* @Then /^the database should contain (\d+) "([^"]*)" entities$/ | ||
*/ | ||
public function thereShouldBeEntities($nbr, $class) | ||
{ | ||
switch ($class) { | ||
case 'dummy': | ||
$repository = $this->entityManager->getRepository('TestBundle:Dummy'); | ||
break; | ||
|
||
case 'another_dummy': | ||
$repository = $this->entityManager->getRepository('TestBundle:AnotherDummy'); | ||
break; | ||
|
||
default: | ||
throw new \UnexpectedValueException(sprintf('Unknown %s entity', $class)); | ||
} | ||
|
||
PHPUnit::assertCount((int) $nbr, $repository->findAll()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\AnotherDummy: | ||
dummy_{0..9}: | ||
name: Dummy <current()> |
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,3 @@ | ||
Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\AnotherDummy: | ||
dummy_{10}: | ||
name: Dummy <current()> |
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
3 changes: 3 additions & 0 deletions
3
tests/Functional/Bundle/TestBundle/DataFixtures/ODM/dummy.yml
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,3 @@ | ||
Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\Dummy: | ||
dummy_{0..9}: | ||
name: Dummy <current()> |
3 changes: 3 additions & 0 deletions
3
tests/Functional/Bundle/TestBundle/DataFixtures/ODM/one_another_dummy.yml
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,3 @@ | ||
Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document\Dummy: | ||
dummy_{10}: | ||
name: Dummy <current()> |
34 changes: 34 additions & 0 deletions
34
tests/Functional/Bundle/TestBundle/Document/AnotherDummy.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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry\AliceBundleExtension package. | ||
* | ||
* (c) Théo FIDRY <theo.fidry@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
|
||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class AnotherDummy | ||
{ | ||
/** | ||
* @var int | ||
* | ||
* @MongoDB\Id() | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @MongoDB\String() | ||
*/ | ||
public $name; | ||
} |
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,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry\AliceBundleExtension package. | ||
* | ||
* (c) Théo FIDRY <theo.fidry@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Fidry\AliceBundleExtension\Tests\Functional\Bundle\TestBundle\Document; | ||
|
||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; | ||
|
||
/** | ||
* @MongoDB\Document | ||
*/ | ||
class Dummy | ||
{ | ||
/** | ||
* @var int | ||
* | ||
* @MongoDB\Id() | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @MongoDB\String() | ||
*/ | ||
public $name; | ||
} |
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