Skip to content

Commit

Permalink
Updates the factory for module options
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Brückner <[email protected]>
  • Loading branch information
froschdesign committed Oct 8, 2021
1 parent 7ae5af2 commit a9b9dcb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 82 deletions.
54 changes: 7 additions & 47 deletions src/TwbsHelper/Options/Factory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,16 @@

namespace TwbsHelper\Options\Factory;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;
use TwbsHelper\Options\ModuleOptions;

/**
* ModuleOptionsFactory
*
* @uses FactoryInterface
*/
class ModuleOptionsFactory implements FactoryInterface
class ModuleOptionsFactory
{


/**
* createService
*
* @param ServiceLocatorInterface $oServiceLocator
* @access public
* @return \TwbsHelper\Options\ModuleOptions
*/
public function createService(ServiceLocatorInterface $oServiceLocator)
public function __invoke(ContainerInterface $container): ModuleOptions
{
return $this->createServiceWithConfig($oServiceLocator->get('config'));
}
/** @var array $config */
$config = $container->get('config');


/**
* __invoke
*
* @param ContainerInterface $oContainer
* @param string $sRequestedName
* @param array $aOptions
* @access public
* @return \TwbsHelper\Options\ModuleOptions
*/
public function __invoke(ContainerInterface $oContainer, $sRequestedName, array $aOptions = null)
{
return $this->createServiceWithConfig($oContainer->get('config'));
}


/**
* createServiceWithConfig
*
* @param array $aConfig
* @access protected
* @return \TwbsHelper\Options\ModuleOptions
*/
protected function createServiceWithConfig(array $aConfig)
{
return new \TwbsHelper\Options\ModuleOptions($aConfig['twbshelper']);
return new ModuleOptions($config['twbshelper']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,55 @@

namespace TestSuite\TwbsHelper\Form\View\Helper\Factory;

class FormElementFactoryTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\TestCase;
use TestSuite\Bootstrap;
use TwbsHelper\Form\View\Helper\Factory\FormModuleOptionsFactory;
use TwbsHelper\Form\View\Helper\Form;
use TwbsHelper\Form\View\Helper\FormCollection;
use TwbsHelper\Form\View\Helper\FormElement;
use TwbsHelper\Form\View\Helper\FormRow;

class FormElementFactoryTest extends TestCase
{
/**
* @var \TwbsHelper\Form\View\Helper\Factory\FormElementFactory
* @var FormModuleOptionsFactory
*/
protected $formElementFactory;
protected $formModuleOptionsFactory;

/**
* @see \PHPUnit\Framework\TestCase::setUp()
*/
public function setUp(): void
{
$this->formElementFactory = new \TwbsHelper\Form\View\Helper\Factory\FormElementFactory();
$this->formElementFactory = new FormModuleOptionsFactory();
}

public function testRenderElement()
/**
* @dataProvider formElementProvider
*/
public function testRenderElement(string $formElement)
{
$this->assertInstanceOf(
\TwbsHelper\Form\View\Helper\FormElement::class,
$this->formElementFactory->createService(\TestSuite\Bootstrap::getServiceManager())
$formElement,
($this->formElementFactory)(
Bootstrap::getServiceManager(),
$formElement
)
);
}

public function formElementProvider(): array
{
return [
Form::class => [
Form::class,
],
FormElement::class => [
FormElement::class,
],
FormRow::class => [
FormRow::class,
],
FormCollection::class => [
FormCollection::class,
],
];
}
}

This file was deleted.

0 comments on commit a9b9dcb

Please sign in to comment.