Skip to content

Commit

Permalink
Merge pull request #108 from Inventis/jan/incomplete_rule_identifier
Browse files Browse the repository at this point in the history
ensure different executors are used for different query builders
  • Loading branch information
K-Phoen authored Sep 18, 2018
2 parents 08c1ece + 43a5309 commit ff32ec1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Target/DoctrineORM/DoctrineORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace RulerZ\Target\DoctrineORM;

use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;

use RulerZ\Compiler\Context;
Expand Down Expand Up @@ -43,8 +44,16 @@ public function getRuleIdentifierHint(string $rule, Context $context): string
{
$aliases = implode('', $context['root_aliases']);
$entities = implode('', $context['root_entities']);
$joined = '';

return $aliases.$entities;
/** @var Expr\Join[] $joins */
foreach ($context['joins'] as $rootEntity => $joins) {
foreach ($joins as $join) {
$joined .= $join->getAlias().$join->getJoin();
}
}

return $aliases.$entities.$joined;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions tests/spec/RulerZ/Target/DoctrineORM/DoctrineORMSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace spec\RulerZ\Target\DoctrineORM;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;

Expand Down Expand Up @@ -125,6 +126,19 @@ public function it_does_not_duplicate_join_tables()
]);
}

public function it_generates_a_different_identifier_for_contexts_with_joins(Expr\Join $join)
{
$rule = 'group.name = "ADMIN" or group.name = "OWNER"';
$joinLessContext = $this->createContext();
$join->getJoin()->willReturn('test.group');
$join->getAlias()->willReturn('grp');
$contextWithJoins = $this->createContext();
$contextWithJoins['joins'] = ['some_root' => [$join->getWrappedObject()]];

$joinLessIdentifier = $this->getRuleIdentifierHint($rule, $joinLessContext)->getWrappedObject();
$this->getRuleIdentifierHint($rule, $contextWithJoins)->shouldNotReturn($joinLessIdentifier);
}

public function it_uses_the_metadata_to_detect_invalid_attribute_access()
{
$context = $this->createContext();
Expand Down

0 comments on commit ff32ec1

Please sign in to comment.