Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Code refactor with new zend-servicemanager of ZF3 #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
25 changes: 1 addition & 24 deletions src/Assertion/AssertionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
18 changes: 11 additions & 7 deletions test/Assertion/AssertionAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
Expand All @@ -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')
Expand Down
9 changes: 5 additions & 4 deletions test/Assertion/AssertionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
namespace ZendTest\Permissions\Acl\Assertion;

use Zend\Permissions\Acl\Assertion\AssertionManager;
use Zend\ServiceManager\ServiceManager;

class AssertionManagerTest extends \PHPUnit_Framework_TestCase
{
protected $manager;

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');
}
}