Created
July 8, 2015 11:42
-
-
Save arnolanglade/3447e85d5e49e22f1066 to your computer and use it in GitHub Desktop.
PhpSpec doctrine repository template
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
// Doctrine ORM | |
use Doctrine\ORM\Mapping\ClassMetadata; | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\AbstractQuery; | |
use Doctrine\ORM\QueryBuilder; | |
class RepositorySpec extends ObjectBehavior | |
{ | |
function let(EntityManager $em, ClassMetadata $classMetadata) | |
{ | |
$this->beConstructedWith($em, $classMetadata); | |
} | |
function it_is_filterable($em, QueryBuilder $builder, AbstractQuery $query) | |
{ | |
$em->createQueryBuilder()->shouldBeCalled()->willReturn($builder); | |
$builder->select('o')->shouldBeCalled()->willReturn($builder); | |
$builder->from(Argument::any(), 'o', null)->shouldBeCalled()->willReturn($builder); | |
$builder->getQuery()->shouldBeCalled()->willReturn($query); | |
} | |
} | |
// Doctrine MongoODM | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; | |
use Doctrine\ODM\MongoDB\Persisters\DocumentPersister; | |
use Doctrine\ODM\MongoDB\Query\Builder; | |
class RepositorySpec extends ObjectBehavior | |
{ | |
function let(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $class) | |
{ | |
$uow->getDocumentPersister(null)->willReturn($documentPersister); | |
$this->beConstructedWith($dm, $uow, $class); | |
} | |
function it_find_something($dm, Builder $queryBuilder) | |
{ | |
$dm->createQueryBuilder(null)->willReturn($queryBuilder); | |
// ... | |
} | |
function it_finds_one_by($documentPersister) | |
{ | |
$documentPersister->load(['attribute' => 'value'], null, null, null) | |
->shouldBeCalled() | |
->willReturn(...); | |
$this->findOneBy(['attribute' => 'value'])->shouldReturn(...); | |
} | |
function it_finds_by($documentPersister) | |
{ | |
$documentPersister->load(['attribute' => 'value'], null, null, null) | |
->shouldBeCalled() | |
->willReturn(...); | |
$this->findBy(['attribute' => 'value'])->shouldReturn(...); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment