Skip to content

Commit

Permalink
Inject event dispatcher and filter url builder
Browse files Browse the repository at this point in the history
  • Loading branch information
discordier committed Mar 8, 2019
1 parent e66d689 commit 25bdbce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
37 changes: 36 additions & 1 deletion src/FilterSetting/RegisterFilterSettingTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,36 @@

namespace MetaModels\FilterRegisterBundle\FilterSetting;

use MetaModels\Filter\FilterUrlBuilder;
use MetaModels\Filter\Setting\AbstractFilterSettingTypeFactory;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Attribute type factory for from-to filter settings.
*/
class RegisterFilterSettingTypeFactory extends AbstractFilterSettingTypeFactory
{
/**
* The event dispatcher.
*
* @var EventDispatcherInterface
*/
private $dispatcher;

/**
* The filter URL builder.
*
* @var FilterUrlBuilder
*/
private $filterUrlBuilder;

/**
* {@inheritDoc}
*
* @param EventDispatcherInterface $dispatcher The event dispatcher.
* @param FilterUrlBuilder $filterUrlBuilder The filter URL builder.
*/
public function __construct()
public function __construct(EventDispatcherInterface $dispatcher, FilterUrlBuilder $filterUrlBuilder)
{
parent::__construct();

Expand All @@ -41,5 +60,21 @@ public function __construct()
->setTypeIcon('bundles/metamodelsfilterregister/filter_register.png')
->setTypeClass(Register::class)
->allowAttributeTypes('tabletext', 'translatedtext', 'text');

$this->dispatcher = $dispatcher;
$this->filterUrlBuilder = $filterUrlBuilder;
}

/**
* {@inheritDoc}
*/
public function createInstance($information, $filterSettings)
{
return new Register(
$filterSettings,
$information,
$this->dispatcher,
$this->filterUrlBuilder
);
}
}
3 changes: 3 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
services:
metamodels.filter_register.factory:
class: MetaModels\FilterRegisterBundle\FilterSetting\RegisterFilterSettingTypeFactory
arguments:
- '@event_dispatcher'
- '@MetaModels\Filter\FilterUrlBuilder'
tags:
- { name: metamodels.filter_factory }

Expand Down
12 changes: 10 additions & 2 deletions tests/FilterSetting/RegisterFilterSettingTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

namespace MetaModels\FilterRegisterBundle\Test\FilterSetting;

use MetaModels\Filter\FilterUrlBuilder;
use MetaModels\Filter\Setting\ICollection;
use MetaModels\FilterRegisterBundle\FilterSetting\Register;
use MetaModels\FilterRegisterBundle\FilterSetting\RegisterFilterSettingTypeFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* This tests the factory.
Expand All @@ -38,7 +40,10 @@ class RegisterFilterSettingTypeFactoryTest extends TestCase
*/
public function testFactory()
{
$factory = new RegisterFilterSettingTypeFactory();
$eventDispatcher = $this->getMockForAbstractClass(EventDispatcherInterface::class);
$filterUrlBuilder = $this->getMockBuilder(FilterUrlBuilder::class)->disableOriginalConstructor()->getMock();

$factory = new RegisterFilterSettingTypeFactory($eventDispatcher, $filterUrlBuilder);

$this->assertSame('register', $factory->getTypeName());
$this->assertSame(
Expand All @@ -55,8 +60,11 @@ public function testFactory()
*/
public function testCreateInstance()
{
$eventDispatcher = $this->getMockForAbstractClass(EventDispatcherInterface::class);
$filterUrlBuilder = $this->getMockBuilder(FilterUrlBuilder::class)->disableOriginalConstructor()->getMock();

$collection = $this->getMockForAbstractClass(ICollection::class);
$factory = new RegisterFilterSettingTypeFactory();
$factory = new RegisterFilterSettingTypeFactory($eventDispatcher, $filterUrlBuilder);

$this->assertInstanceOf(Register::class, $factory->createInstance([], $collection));
}
Expand Down

0 comments on commit 25bdbce

Please sign in to comment.