From 9dbc38fb6b5a1ba08ea617ab562910e62620f2f6 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Wed, 9 Dec 2015 16:49:17 +0100 Subject: [PATCH] Code refactor with new zend-servicemanager --- composer.json | 4 ++-- src/Assertion/AssertionManager.php | 25 +---------------------- test/Assertion/AssertionAggregateTest.php | 18 +++++++++------- test/Assertion/AssertionManagerTest.php | 9 ++++---- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/composer.json b/composer.json index 55f6e05..76c03cd 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require-dev": { "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0", - "zendframework/zend-di": "~2.5", - "zendframework/zend-servicemanager": "~2.5" + "zendframework/zend-di": "dev-develop as 2.7.0", + "zendframework/zend-servicemanager": "dev-develop as 2.7.0" } } diff --git a/src/Assertion/AssertionManager.php b/src/Assertion/AssertionManager.php index 69e35e8..7f18bc5 100644 --- a/src/Assertion/AssertionManager.php +++ b/src/Assertion/AssertionManager.php @@ -9,33 +9,10 @@ namespace Zend\Permissions\Acl\Assertion; use Zend\ServiceManager\AbstractPluginManager; -use Zend\Permissions\Acl\Exception\InvalidArgumentException; class AssertionManager extends AbstractPluginManager { protected $sharedByDefault = true; - /** - * Validate the plugin - * - * Checks that the element is an instance of AssertionInterface - * - * @param mixed $plugin - * - * @throws InvalidArgumentException - * @return bool - */ - public function validatePlugin($plugin) - { - if (! $plugin instanceof AssertionInterface) { - throw new InvalidArgumentException( - sprintf( - 'Plugin of type %s is invalid; must implement Zend\Permissions\Acl\Assertion\AssertionInterface', - (is_object($plugin) ? get_class($plugin) : gettype($plugin)) - ) - ); - } - - return true; - } + protected $instanceOf = AssertionInterface::class; } diff --git a/test/Assertion/AssertionAggregateTest.php b/test/Assertion/AssertionAggregateTest.php index e210421..ac217a2 100644 --- a/test/Assertion/AssertionAggregateTest.php +++ b/test/Assertion/AssertionAggregateTest.php @@ -106,7 +106,9 @@ public static function getDataForTestSetMode() public function testManagerAccessors() { - $manager = $this->getMock('Zend\Permissions\Acl\Assertion\AssertionManager'); + $manager = $this->getMockBuilder('Zend\Permissions\Acl\Assertion\AssertionManager') + ->disableOriginalConstructor() + ->getMock(); $aggregate = $this->assertionAggregate->setAssertionManager($manager); $this->assertAttributeEquals($manager, 'assertionManager', $this->assertionAggregate); @@ -129,9 +131,10 @@ public function testCallingAssertWillFetchAssertionFromManager() ->method('assert') ->will($this->returnValue(true)); - $manager = $this->getMock('Zend\Permissions\Acl\Assertion\AssertionManager', [ - 'get' - ]); + $manager = $this->getMockBuilder('Zend\Permissions\Acl\Assertion\AssertionManager') + ->disableOriginalConstructor() + ->getMock(); + $manager->expects($this->once()) ->method('get') ->with('assertion') @@ -153,9 +156,10 @@ public function testAssertThrowsAnExceptionWhenReferingToNonExistentAssertion() 'test.resource' ]); - $manager = $this->getMock('Zend\Permissions\Acl\Assertion\AssertionManager', [ - 'get' - ]); + $manager = $this->getMockBuilder('Zend\Permissions\Acl\Assertion\AssertionManager') + ->disableOriginalConstructor() + ->getMock(); + $manager->expects($this->once()) ->method('get') ->with('assertion') diff --git a/test/Assertion/AssertionManagerTest.php b/test/Assertion/AssertionManagerTest.php index 856469d..3f613db 100644 --- a/test/Assertion/AssertionManagerTest.php +++ b/test/Assertion/AssertionManagerTest.php @@ -9,6 +9,7 @@ namespace ZendTest\Permissions\Acl\Assertion; use Zend\Permissions\Acl\Assertion\AssertionManager; +use Zend\ServiceManager\ServiceManager; class AssertionManagerTest extends \PHPUnit_Framework_TestCase { @@ -16,17 +17,17 @@ class AssertionManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->manager = new AssertionManager(); + $this->manager = new AssertionManager(new ServiceManager); } public function testValidatePlugin() { $assertion = $this->getMockForAbstractClass('Zend\Permissions\Acl\Assertion\AssertionInterface'); - $this->assertTrue($this->manager->validatePlugin($assertion)); + $this->assertNull($this->manager->validate($assertion)); - $this->setExpectedException('Zend\Permissions\Acl\Exception\InvalidArgumentException'); + $this->setExpectedException('Zend\ServiceManager\Exception\InvalidServiceException'); - $this->manager->validatePlugin('invalid plugin'); + $this->manager->validate('invalid plugin'); } }