Skip to content

Commit

Permalink
support filters
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Oct 7, 2017
1 parent 4428999 commit 80b0998
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ before_install:

install:
- travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress
- if [[ $TEST_VERSION ]]; then travis_retry composer require satooshi/php-coveralls:dev-master $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi
- if [[ $TEST_VERSION ]]; then travis_retry composer require php-coveralls/php-coveralls $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi

script:
- if [[ $TEST_VERSION ]]; then composer qa && composer phpunit-clover ; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $entityManager = \Doctrine\ORM\EntityManager::create([], $config);
## Functionalities

Head to [juliangut/doctrine-base-repositories](https://github.com/juliangut/doctrine-base-repositories) for a list of new methods provided by the repository
Head to [juliangut/doctrine-base-repositories](https://github.com/juliangut/doctrine-base-repositories) for a full list of new functionalities provided by the repository

Additionally [Specification pattern](https://en.wikipedia.org/wiki/Specification_pattern) is supported thanks to [happyr/doctrine-specification](https://github.com/Happyr/Doctrine-Specification)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": "^7.0",
"doctrine/orm": "^2.4",
"juliangut/doctrine-base-repositories": "dev-master",
"juliangut/doctrine-base-repositories": "^1.0",
"happyr/doctrine-specification": "^0.7.2"
},
"require-dev": {
Expand Down
10 changes: 10 additions & 0 deletions src/RelationalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Happyr\DoctrineSpecification\EntitySpecificationRepositoryInterface;
use Happyr\DoctrineSpecification\EntitySpecificationRepositoryTrait;
use Jgut\Doctrine\Repository\EventsTrait;
use Jgut\Doctrine\Repository\FiltersTrait;
use Jgut\Doctrine\Repository\PaginatorTrait;
use Jgut\Doctrine\Repository\Repository;
use Jgut\Doctrine\Repository\RepositoryTrait;
Expand All @@ -34,6 +35,7 @@ class RelationalRepository extends EntityRepository implements Repository, Entit
{
use RepositoryTrait;
use EventsTrait;
use FiltersTrait;
use PaginatorTrait;
use EntitySpecificationRepositoryTrait;

Expand Down Expand Up @@ -77,6 +79,14 @@ public function getClassName(): string
return $this->className;
}

/**
* {@inheritdoc}
*/
protected function getFilterCollection()
{
return $this->getManager()->getFilters();
}

/**
* {@inheritdoc}
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/ORM/RelationalRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Persisters\Entity\BasicEntityPersister;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\FilterCollection;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\UnitOfWork;
use Jgut\Doctrine\Repository\ORM\RelationalRepository;
Expand All @@ -44,6 +45,26 @@ public function testEntityName()
static::assertEquals(EntityStub::class, $repository->getClassName());
}

public function testFilterCollection()
{
$filterCollection = $this->getMockBuilder(FilterCollection::class)
->disableOriginalConstructor()
->getMock();
/* @var FilterCollection $filterCollection */

$manager = $this->getMockBuilder(EntityManager::class)
->disableOriginalConstructor()
->getMock();
$manager->expects(static::any())
->method('getFilters')
->will(static::returnValue($filterCollection));
/* @var EntityManager $manager */

$repository = new RepositoryStub($manager, new ClassMetadata(EntityStub::class));

static::assertSame($filterCollection, $repository->getFilterCollection());
}

public function testEntityManager()
{
$manager = $this->getMockBuilder(EntityManager::class)
Expand Down
9 changes: 9 additions & 0 deletions tests/ORM/Stubs/RepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Jgut\Doctrine\Repository\ORM\Tests\Stubs;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query\FilterCollection;
use Jgut\Doctrine\Repository\ORM\RelationalRepository;
use Zend\Paginator\Adapter\AdapterInterface;
use Zend\Paginator\Paginator;
Expand All @@ -23,6 +24,14 @@
*/
class RepositoryStub extends RelationalRepository
{
/**
* @return FilterCollection
*/
public function getFilterCollection(): FilterCollection
{
return parent::getFilterCollection();
}

/**
* @return EntityManager
*/
Expand Down

0 comments on commit 80b0998

Please sign in to comment.