8000 Fixes #177 - MVC InputFilterPluginManager missing InputFilterAbstractFactory config by froschdesign · Pull Request #181 · zendframework/zend-inputfilter · GitHub
[go: up one dir, main page]

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

Fixes #177 - MVC InputFilterPluginManager missing InputFilterAbstractFactory config #181

Merged
merged 6 commits into from
Aug 28, 2019
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
5 changes: 3 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* @link http://github.com/zendframework/zend-inputfilter for the canonical source repository
* @see http://github.com/zendframework/zend-inputfilter for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @license https://github.com/zendframework/zend-inputfilter/blob/master/LICENSE.md New BSD License
*/

namespace Zend\InputFilter;
Expand All @@ -18,6 +18,7 @@ public function getConfig()

return [
'service_manager' => $provider->getDependencyConfig(),
'input_filters' => $provider->getInputFilterConfig(),
];
}

Expand Down
101 changes: 101 additions & 0 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* @see https://github.com/zendframework/zend-inputfilter for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-inputfilter/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\InputFilter;

use Interop\Container\ContainerInterface;
use PHPUnit\Framework\TestCase;
use Zend\InputFilter\InputFilterAbstractServiceFactory;
use Zend\InputFilter\InputFilterPluginManager;
use Zend\InputFilter\InputFilterPluginManagerFactory;
use Zend\InputFilter\Module;

class ModuleTest extends TestCase
{
/** @var Module */
private $module;

public function setUp()
{
$this->module = new Module();
}

public function testGetConfigMethodShouldReturnExpectedKeys()
{
$config = $this->module->getConfig();

$this->assertInternalType('array', $config);

// Service manager
$this->assertArrayHasKey('service_manager', $config);

// Input filters
$this->assertArrayHasKey('input_filters', $config);
}

public function testServiceManagerConfigShouldContainInputFilterManager()
{
$config = $this->module->getConfig();

$this->assertArrayHasKey(
InputFilterPluginManager::class,
$config['service_manager']['factories']
);
}

public function testServiceManagerConfigShouldContainAliasForInputFilterManager()
{
$config = $this->module->getConfig();

$this->assertArrayHasKey(
'InputFilterManager',
$config['service_manager']['aliases']
);
}

public function testInputFilterConfigShouldContainAbstractServiceFactory()
{
$config = $this->module->getConfig();

$this->assertContains(
InputFilterAbstractServiceFactory::class,
$config['input_filters']['abstract_factories']
);
}

public function testInitMethodShouldRegisterPluginManagerSpecificationWithServiceListener()
{
// Service listener
$serviceListener = $this->prophesize(
TestAsset\ServiceListenerInterface::class
);
$serviceListener->addServiceManager(
'InputFilterManager',
'input_filters',
'Zend\ModuleManager\Feature\InputFilterProviderInterface',
'getInputFilterConfig'
)->shouldBeCalled();

// Container
$container = $this->prophesize(ContainerInterface::class);
$container->get('ServiceListener')->willReturn(
$serviceListener->reveal()
);

// Event
$event = $this->prophesize(TestAsset\ModuleEventInterface::class);
$event->getParam('ServiceManager')->willReturn($container->reveal());

// Module manager
$moduleManager = $this->prophesize(
TestAsset\ModuleManagerInterface::class
);
$moduleManager->getEvent()->willReturn($event->reveal());

$this->assertNull($this->module->init($moduleManager->reveal()));
}
}
18 changes: 18 additions & 0 deletions
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @link https://github.com/zendframework/zend-inputfilter for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-inputfilter/blob/master/LICENSE.md
*/

namespace ZendTest\InputFilter\TestAsset;

/**
* Mock interface to use when testing Module::init
*
* Mimics Zend\ModuleManager\ModuleEvent methods called.
*/
interface ModuleEventInterface
{
public function getParam($name, $default = null);
}
13 changes: 13 additions & 0 deletions test/TestAsset/ModuleManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* @link https://github.com/zendframework/zend-inputfilter for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-inputfilter/blob/master/LICENSE.md
*/

namespace ZendTest\InputFilter\TestAsset;

interface ModuleManagerInterface
{
public function getEvent();
}
29 changes: 29 additions & 0 deletions test/TestAsset/ServiceListenerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://github.com/zendframework/zend-inputfilter for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-inputfilter/blob/master/LICENSE.md
*/

namespace ZendTest\InputFilter\TestAsset;

/**
* Stub interfact to mock when testing Module::init.
*
* Mimics method that will be called on ServiceListener.
*/
interface ServiceListenerInterface
{
/**
* @param string $pluginManagerService
* @param string $configKey
* @param string $interface
* @param string $method
*/
public function addServiceManager(
$pluginManagerService,
$configKey,
$interface,
$method
);
}
0