summaryrefslogtreecommitdiffstats
path: root/Core/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Core/Tests')
-rw-r--r--Core/Tests/Authorization/Voter/AbstractVoterTest.php38
-rw-r--r--Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php9
2 files changed, 39 insertions, 8 deletions
diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
index 44da147..ea72e75 100644
--- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php
+++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php
@@ -19,17 +19,10 @@ use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
*/
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
{
- /**
- * @var AbstractVoter
- */
- private $voter;
-
private $token;
protected function setUp()
{
- $this->voter = new VoterFixture();
-
$tokenMock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
$tokenMock
->expects($this->any())
@@ -44,7 +37,9 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
*/
public function testVote($expectedVote, $object, $attributes, $message)
{
- $this->assertEquals($expectedVote, $this->voter->vote($this->token, $object, $attributes), $message);
+ $voter = new VoterFixture();
+
+ $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}
/**
@@ -58,6 +53,16 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
}
+ /**
+ * @group legacy
+ * @expectedException \BadMethodCallException
+ */
+ public function testNoOverriddenMethodsThrowsException()
+ {
+ $voter = new DeprecatedVoterNothingImplementedFixture();
+ $voter->vote($this->token, new ObjectFixture(), array('foo'));
+ }
+
public function getData()
{
return array(
@@ -113,6 +118,23 @@ class DeprecatedVoterFixture extends AbstractVoter
}
}
+class DeprecatedVoterNothingImplementedFixture extends AbstractVoter
+{
+ protected function getSupportedClasses()
+ {
+ return array(
+ 'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
+ );
+ }
+
+ protected function getSupportedAttributes()
+ {
+ return array('foo', 'bar', 'baz');
+ }
+
+ // this is a bad voter that hasn't overridden isGranted or voteOnAttribute
+}
+
class ObjectFixture
{
}
diff --git a/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php b/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php
index 3a0cf1e..b49f23f 100644
--- a/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php
+++ b/Core/Tests/Authorization/Voter/LegacyAbstractVoterTest.php
@@ -1,5 +1,14 @@
<?php
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;