From 1bb0449112568e7e7817ebe485e21cec42c16fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 12:36:20 +0200 Subject: [PATCH 1/2] New interface for voters The use of the old interface trigger deprecation notice, handled by Chill. This should be safe for an upgrade towars sf 3, but still requires work inside bundles. --- Security/Authorization/AbstractChillVoter.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Security/Authorization/AbstractChillVoter.php b/Security/Authorization/AbstractChillVoter.php index ac291c673..842fc5ecc 100644 --- a/Security/Authorization/AbstractChillVoter.php +++ b/Security/Authorization/AbstractChillVoter.php @@ -19,7 +19,8 @@ namespace Chill\MainBundle\Security\Authorization; -use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; +use Symfony\Component\Security\Core\Authorization\Voter\Voter; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** * Voter for Chill software. @@ -29,8 +30,26 @@ use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter; * * @author Julien Fastré */ -abstract class AbstractChillVoter extends AbstractVoter implements ChillVoterInterface +abstract class AbstractChillVoter extends Voter implements ChillVoterInterface { + protected function supports($attribute, $subject) + { + @trigger_error('This voter should implements the new `supports` ' + . 'methods introduced by Symfony 3.0, and do not rely on ' + . 'getSupportedAttributes and getSupportedClasses methods.', + E_USER_DEPRECATED); + + return \in_array($attribute, $this->getSupportedAttributes($attribute)) + && \in_array(\get_class($subject), $this->getSupportedClasses()); + } + protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + { + @trigger_error('This voter should implements the new `voteOnAttribute` ' + . 'methods introduced by Symfony 3.0, and do not rely on ' + . 'isGranted method', E_USER_DEPRECATED); + + return $this->isGranted($attribute, $subject, $token->getUser()); + } } From c593c153a16a900ca1d92188b38352503703dbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 4 Apr 2018 15:47:18 +0200 Subject: [PATCH 2/2] fix error on exports test Since php 7.2, the count function does not accept NULL values. This led to error if the WHERE clause of query where empty. --- Test/Export/AbstractAggregatorTest.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Test/Export/AbstractAggregatorTest.php b/Test/Export/AbstractAggregatorTest.php index c03fecfc6..a1f0cf60a 100644 --- a/Test/Export/AbstractAggregatorTest.php +++ b/Test/Export/AbstractAggregatorTest.php @@ -210,19 +210,28 @@ abstract class AbstractAggregatorTest extends KernelTestCase public function testAlterQuery(QueryBuilder $query, $data) { // retains informations about query - $nbOfFrom = count($query->getDQLPart('from')); - $nbOfWhere = count($query->getDQLPart('where')); - $nbOfSelect = count($query->getDQLPart('select')); + $nbOfFrom = $query->getDQLPart('from') !== null ? + count($query->getDQLPart('from')) : 0; + $nbOfWhere = $query->getDQLPart('where') !== null ? + count($query->getDQLPart('where')) : 0; + $nbOfSelect = $query->getDQLPart('select') !== null ? + count($query->getDQLPart('select')) : 0; $this->getAggregator()->alterQuery($query, $data); - $this->assertGreaterThanOrEqual($nbOfFrom, count($query->getDQLPart('from')), + $this->assertGreaterThanOrEqual( + $nbOfFrom, + $query->getDQLPart('from') !== null ? count($query->getDQLPart('from')) : 0, "Test that there are equal or more 'from' clause after that the filter has altered the query"); - $this->assertGreaterThanOrEqual($nbOfWhere, count($query->getDQLPart('where')), + $this->assertGreaterThanOrEqual( + $nbOfWhere, + $query->getDQLPart('where') !== null ? count($query->getDQLPart('where')) : 0, "Test that there are equal or more 'where' clause after that the filter has" . "altered the query"); - $this->assertGreaterThanOrEqual($nbOfSelect, count($query->getDQLPart('select')), + $this->assertGreaterThanOrEqual( + $nbOfSelect, + $query->getDQLPart('select') !== null ? count($query->getDQLPart('select')) : 0, "Test that the filter has no altered the 'select' part of the query"); }