Skip to content

Commit

Permalink
Merge pull request #1 from peter-gribanov/analysis-qrJVZx
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
peter-gribanov authored Mar 29, 2017
2 parents 51d66bf + 4c6ae89 commit 5fb9004
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 164 deletions.
118 changes: 59 additions & 59 deletions src/EntitySpecificationRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<?php

namespace Happyr\DoctrineSpecification;

use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\ObjectRepository;
use Happyr\DoctrineSpecification\Filter\Filter;
use Happyr\DoctrineSpecification\Query\QueryModifier;

/**
* This interface should be used by an EntityRepository implementing the Specification pattern.
*/
interface EntitySpecificationRepositoryInterface extends ObjectRepository, Selectable
{
/**
* Get results when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @return mixed[]
*/
function match($specification, Result\ResultModifier $modifier);

/**
* Get single result when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
*
* @return mixed
*/
function matchSingleResult($specification, Result\ResultModifier $modifier);

/**
* Get single result or null when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
*
* @return mixed|null
*/
function matchOneOrNullResult($specification, Result\ResultModifier $modifier);

/**
* Prepare a Query with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @return \Doctrine\ORM\Query
*/
function getQuery($specification, Result\ResultModifier $modifier);
}
<?php

namespace Happyr\DoctrineSpecification;

use Doctrine\Common\Collections\Selectable;
use Doctrine\Common\Persistence\ObjectRepository;
use Happyr\DoctrineSpecification\Filter\Filter;
use Happyr\DoctrineSpecification\Query\QueryModifier;

/**
* This interface should be used by an EntityRepository implementing the Specification pattern.
*/
interface EntitySpecificationRepositoryInterface extends ObjectRepository, Selectable
{
/**
* Get results when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @return mixed[]
*/
public function match($specification, Result\ResultModifier $modifier);

/**
* Get single result when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
*
* @return mixed
*/
public function matchSingleResult($specification, Result\ResultModifier $modifier);

/**
* Get single result or null when you match with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
*
* @return mixed|null
*/
public function matchOneOrNullResult($specification, Result\ResultModifier $modifier);

/**
* Prepare a Query with a Specification.
*
* @param Filter|QueryModifier $specification
* @param Result\ResultModifier $modifier
*
* @return \Doctrine\ORM\Query
*/
public function getQuery($specification, Result\ResultModifier $modifier);
}
2 changes: 1 addition & 1 deletion src/Query/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GroupBy implements QueryModifier
* @param string $field
* @param string $dqlAlias
*/
public function __construct($field, $dqlAlias = null)
public function __construct($field, $dqlAlias = null)
{
$this->field = $field;
$this->dqlAlias = $dqlAlias;
Expand Down
4 changes: 2 additions & 2 deletions src/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class RepositoryFactory implements \Doctrine\ORM\Repository\RepositoryFactory
/**
* Gets the repository for an entity class.
*
* @param EntityManagerInterface $entityManager The EntityManager instance.
* @param string $entityName The name of the entity.
* @param EntityManagerInterface $entityManager the EntityManager instance
* @param string $entityName the name of the entity
*
* @return EntityRepository
*/
Expand Down
60 changes: 25 additions & 35 deletions tests/EntitySpecificationRepositorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\EntitySpecificationRepository;
use Happyr\DoctrineSpecification\Filter\Filter;
Expand All @@ -26,12 +25,12 @@ class EntitySpecificationRepositorySpec extends ObjectBehavior
private $expression = 'expression';
private $result = 'result';

function let(EntityManager $entityManager, ClassMetadata $classMetadata)
public function let(EntityManager $entityManager, ClassMetadata $classMetadata)
{
$this->beConstructedWith($entityManager, $classMetadata);
}

function it_should_modify_query(
public function it_should_modify_query(
QueryModifier $specification,
EntityManager $entityManager,
QueryBuilder $qb,
Expand All @@ -46,7 +45,7 @@ function it_should_modify_query(
$this->match($specification);
}

function it_should_apply_filter(
public function it_should_apply_filter(
Filter $specification,
EntityManager $entityManager,
QueryBuilder $qb,
Expand All @@ -62,7 +61,7 @@ function it_should_apply_filter(
$this->match($specification);
}

function it_should_skip_apply_empty_specification(
public function it_should_skip_apply_empty_specification(
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
Expand All @@ -76,20 +75,20 @@ function it_should_skip_apply_empty_specification(
$this->match(null);
}

function it_should_throw_exception_when_apply_not_specification(
public function it_should_throw_exception_when_apply_not_specification(
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
) {
$this->prepareEntityManagerStub($entityManager, $qb);
$this->prepareQueryBuilderStub($qb, $query);

$this->shouldThrow('\InvalidArgumentException')->duringMatch(new \stdClass);
$this->shouldThrow('\InvalidArgumentException')->duringMatch(new \stdClass());
$this->shouldThrow('\InvalidArgumentException')->duringMatch(['fake', 'array']);
$this->shouldThrow('\InvalidArgumentException')->duringMatch('fake');
}

function it_matches_a_specification_with_empty_filter(
public function it_matches_a_specification_with_empty_filter(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
Expand All @@ -105,13 +104,12 @@ function it_matches_a_specification_with_empty_filter(
$this->match($specification)->shouldReturn($this->result);
}

function it_matches_a_specification_without_result_modifier(
public function it_matches_a_specification_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);
$query->execute()->willReturn($this->result);

Expand All @@ -120,14 +118,13 @@ function it_matches_a_specification_without_result_modifier(
$this->match($specification)->shouldReturn($this->result);
}

function it_matches_a_single_result_without_result_modifier(
public function it_matches_a_single_result_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
$singleResult = new \stdClass;
) {
$singleResult = new \stdClass();

$this->prepareStubs($specification, $entityManager, $qb, $query);

Expand All @@ -138,13 +135,12 @@ function it_matches_a_single_result_without_result_modifier(
$this->matchSingleResult($specification)->shouldReturn($singleResult);
}

function it_throws_exception_when_expecting_single_result_finding_none_without_result_modifier(
public function it_throws_exception_when_expecting_single_result_finding_none_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);

$specification->modify($qb, $this->alias)->shouldBeCalled();
Expand All @@ -154,13 +150,12 @@ function it_throws_exception_when_expecting_single_result_finding_none_without_r
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\NoResultException')->duringMatchSingleResult($specification);
}

function it_throws_exception_when_expecting_single_result_finding_multiple_without_result_modifier(
public function it_throws_exception_when_expecting_single_result_finding_multiple_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);

$specification->modify($qb, $this->alias)->shouldBeCalled();
Expand All @@ -170,14 +165,13 @@ function it_throws_exception_when_expecting_single_result_finding_multiple_witho
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\NonUniqueResultException')->duringMatchSingleResult($specification);
}

function it_matches_a_single_result_when_expecting_one_or_null_without_result_modifier(
public function it_matches_a_single_result_when_expecting_one_or_null_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
$singleResult = new \stdClass;
) {
$singleResult = new \stdClass();

$this->prepareStubs($specification, $entityManager, $qb, $query);

Expand All @@ -188,13 +182,12 @@ function it_matches_a_single_result_when_expecting_one_or_null_without_result_mo
$this->matchOneOrNullResult($specification)->shouldReturn($singleResult);
}

function it_matches_null_when_expecting_one_or_null_without_result_modifier(
public function it_matches_null_when_expecting_one_or_null_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);

$specification->modify($qb, $this->alias)->shouldBeCalled();
Expand All @@ -204,13 +197,12 @@ function it_matches_null_when_expecting_one_or_null_without_result_modifier(
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\NonUniqueResultException')->duringMatchOneOrNullResult($specification);
}

function it_throws_exception_when_expecting_one_or_null_finding_multiple_without_result_modifier(
public function it_throws_exception_when_expecting_one_or_null_finding_multiple_without_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);

$specification->modify($qb, $this->alias)->shouldBeCalled();
Expand All @@ -220,15 +212,13 @@ function it_throws_exception_when_expecting_one_or_null_finding_multiple_without
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\UnexpectedResultException')->duringMatchOneOrNullResult($specification);
}


function it_matches_a_specification_with_result_modifier(
public function it_matches_a_specification_with_result_modifier(
Specification $specification,
EntityManager $entityManager,
QueryBuilder $qb,
AbstractQuery $query,
ResultModifier $modifier
)
{
) {
$this->prepareStubs($specification, $entityManager, $qb, $query);
$query->execute()->willReturn($this->result);

Expand Down
13 changes: 6 additions & 7 deletions tests/Filter/ComparisonSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\Filter\Comparison;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
* @mixin Comparison
*/
class ComparisonSpec extends ObjectBehavior
{
function let()
public function let()
{
$this->beConstructedWith(Comparison::GT, 'age', 18, 'a');
}

function it_is_an_expression()
public function it_is_an_expression()
{
$this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Filter\Filter');
}
function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $parameters)

public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $parameters)
{
$qb->getParameters()->willReturn($parameters);
$parameters->count()->willReturn(10);
Expand All @@ -35,7 +34,7 @@ function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $paramet
$comparison->shouldReturn('a.age > :comparison_10');
}

function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, ArrayCollection $parameters)
public function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, ArrayCollection $parameters)
{
$this->beConstructedWith(Comparison::GT, 'age', 18, null);

Expand All @@ -47,7 +46,7 @@ function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, Array
$this->getFilter($qb, 'x')->shouldReturn('x.age > :comparison_10');
}

function it_validates_operator()
public function it_validates_operator()
{
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\InvalidArgumentException')->during('__construct', array('==', 'age', 18, null));
}
Expand Down
Loading

0 comments on commit 5fb9004

Please sign in to comment.