forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Sylius#7 from umpirsky/entity-alias Added some specs for doctrine repos, generate human readable alias.
- Loading branch information
Showing
6 changed files
with
211 additions
and
6 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
54 changes: 54 additions & 0 deletions
54
spec/Sylius/Bundle/ResourceBundle/Doctrine/ODM/MongoDB/DocumentRepository.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,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\Sylius\Bundle\ResourceBundle\Doctrine\ODM\MongoDB; | ||
|
||
use PHPSpec2\ObjectBehavior; | ||
|
||
/** | ||
* Doctrine ODM driver document repository spec. | ||
* | ||
* @author Саша Стаменковић <umpirsky@gmail.com> | ||
*/ | ||
class DocumentRepository extends ObjectBehavior | ||
{ | ||
/** | ||
* @param Doctrine\ODM\MongoDB\DocumentManager $documentManager | ||
* @param Doctrine\ODM\MongoDB\UnitOfWork $unitOfWork | ||
* @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class | ||
* @param Doctrine\ODM\MongoDB\Query\Builder $queryBuilder | ||
*/ | ||
function let($documentManager, $unitOfWork, $class, $queryBuilder) | ||
{ | ||
$class->name = 'spec\Sylius\Bundle\ResourceBundle\Fixture\Entity\Foo'; | ||
|
||
$documentManager | ||
->createQueryBuilder($class->name) | ||
->willReturn($queryBuilder) | ||
; | ||
|
||
$this->beConstructedWith($documentManager, $unitOfWork, $class); | ||
} | ||
|
||
function it_should_be_initializable() | ||
{ | ||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\Doctrine\ODM\MongoDB\DocumentRepository'); | ||
$this->shouldHaveType('Doctrine\ODM\MongoDB\DocumentRepository'); | ||
} | ||
|
||
function it_should_create_paginator() | ||
{ | ||
$this | ||
->createPaginator() | ||
->shouldHaveType('Pagerfanta\Pagerfanta') | ||
; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
spec/Sylius/Bundle/ResourceBundle/Doctrine/ORM/EntityRepository.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,124 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\Sylius\Bundle\ResourceBundle\Doctrine\ORM; | ||
|
||
use PHPSpec2\ObjectBehavior; | ||
|
||
/** | ||
* Doctrine ORM driver entity repository spec. | ||
* | ||
* @author Саша Стаменковић <umpirsky@gmail.com> | ||
*/ | ||
class EntityRepository extends ObjectBehavior | ||
{ | ||
/** | ||
* @param Doctrine\ORM\EntityManager $entityManager | ||
* @param Doctrine\ORM\Mapping\ClassMetadata $class | ||
* @param Doctrine\ORM\QueryBuilder $queryBuilder | ||
*/ | ||
function let($entityManager, $class, $queryBuilder) | ||
{ | ||
$class->name = 'spec\Sylius\Bundle\ResourceBundle\Fixture\Entity\Foo'; | ||
|
||
$entityManager | ||
->createQueryBuilder() | ||
->willReturn($queryBuilder) | ||
; | ||
|
||
$queryBuilder | ||
->select(ANY_ARGUMENT) | ||
->willReturn($queryBuilder) | ||
; | ||
$queryBuilder | ||
->from(ANY_ARGUMENTS) | ||
->willReturn($queryBuilder) | ||
; | ||
|
||
$this->beConstructedWith($entityManager, $class); | ||
} | ||
|
||
function it_should_be_initializable() | ||
{ | ||
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository'); | ||
$this->shouldHaveType('Doctrine\ORM\EntityRepository'); | ||
} | ||
|
||
function it_should_create_new() | ||
{ | ||
$this->createNew()->shouldHaveType('spec\Sylius\Bundle\ResourceBundle\Fixture\Entity\Foo'); | ||
} | ||
|
||
function it_should_return_null_if_not_found() | ||
{ | ||
$this->find(1)->shouldReturn(null); | ||
} | ||
|
||
/** | ||
* @param Doctrine\ORM\QueryBuilder $queryBuilder | ||
*/ | ||
function it_should_apply_criteria_when_finding_one_by_criteria($queryBuilder) | ||
{ | ||
$criteria = array( | ||
'foo' => 'bar', | ||
'bar' => 'baz', | ||
); | ||
|
||
$this->it_should_apply_criteria($criteria, $queryBuilder); | ||
|
||
$this->findOneBy($criteria)->shouldReturn(null); | ||
} | ||
|
||
/** | ||
* @param Doctrine\ORM\QueryBuilder $queryBuilder | ||
*/ | ||
function it_should_apply_criteria_when_finding_by_criteria($queryBuilder) | ||
{ | ||
$criteria = array( | ||
'foo' => 'bar', | ||
'bar' => 'baz', | ||
); | ||
|
||
$this->it_should_apply_criteria($criteria, $queryBuilder); | ||
|
||
$this->findBy($criteria)->shouldReturn(null); | ||
} | ||
|
||
function it_should_return_null_if_all_not_found() | ||
{ | ||
$this->findAll()->shouldReturn(null); | ||
} | ||
|
||
function it_should_create_paginator() | ||
{ | ||
$this | ||
->createPaginator() | ||
->shouldHaveType('Pagerfanta\Pagerfanta') | ||
; | ||
} | ||
|
||
private function it_should_apply_criteria(array $criteria, $queryBuilder) | ||
{ | ||
foreach ($criteria as $property => $value) { | ||
$queryBuilder | ||
->andWhere('foo.'.$property.' = :'.$property) | ||
->shouldBeCalled() | ||
->willReturn($queryBuilder) | ||
; | ||
|
||
$queryBuilder | ||
->setParameter($property, $value) | ||
->shouldBeCalled() | ||
->willReturn($queryBuilder) | ||
; | ||
} | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace spec\Sylius\Bundle\ResourceBundle\Fixture\Entity; | ||
|
||
/** | ||
* Foo entity. | ||
* | ||
* @author Саша Стаменковић <umpirsky@gmail.com> | ||
*/ | ||
class Foo | ||
{ | ||
} |