Skip to content
This repository has been 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 3 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
1 change: 1 addition & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function getConfig()

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

Expand Down
99 changes: 99 additions & 0 deletions test/ModuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* @link https://github.com/zendframework/zend-inputfilter for the canonical source repository
froschdesign marked this conversation as resolved.
Show resolved Hide resolved
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://framework.zend.com/license New BSD License
froschdesign marked this conversation as resolved.
Show resolved Hide resolved
*/

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 testGetConfigMethodShouldReturnExpectedValues()
{
$config = $this->module->getConfig();

// Service manager
$this->assertSame(
[
'aliases' => [
'InputFilterManager' => InputFilterPluginManager::class,
],
'factories' => [
InputFilterPluginManager::class => InputFilterPluginManagerFactory::class,
],
],
$config['service_manager']
);

// Input filters
$this->assertSame(
[
'abstract_factories' => [
InputFilterAbstractServiceFactory::class,
],
],
$config['input_filters']
);
}
froschdesign marked this conversation as resolved.
Show resolved Hide resolved

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 test/TestAsset/ModuleEventInterface.php
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://framework.zend.com/license New BSD License
*/

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://framework.zend.com/license New BSD License
*/

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://framework.zend.com/license New BSD License
*/

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