Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reverted to clean class definitions for event listeners
- Loading branch information
Showing
9 changed files
with
163 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\EventListener; | ||
|
||
use Craue\FormFlowBundle\Exception\InvalidTypeException; | ||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2021 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
trait EventListenerWithTranslatorTrait { | ||
|
||
/** | ||
* @var TranslatorInterface|LegacyTranslatorInterface | ||
*/ | ||
protected $translator; | ||
|
||
/** | ||
* @param TranslatorInterface|LegacyTranslatorInterface $translator | ||
* @throws InvalidTypeException | ||
*/ | ||
public function setTranslator($translator) { | ||
// TODO revert to type-hint with only TranslatorInterface as soon as Symfony >= 5.0 is required | ||
if ($translator instanceof TranslatorInterface || $translator instanceof LegacyTranslatorInterface) { | ||
$this->translator = $translator; | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidTypeException($translator, [TranslatorInterface::class, LegacyTranslatorInterface::class]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Tests/EventListener/EventListenerWithTranslatorTestTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Tests\EventListener; | ||
|
||
use Craue\FormFlowBundle\Exception\InvalidTypeException; | ||
|
||
/** | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2021 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
trait EventListenerWithTranslatorTestTrait { | ||
|
||
protected abstract function getListener(); | ||
|
||
/** | ||
* @dataProvider dataSetTranslator_invalidArguments | ||
*/ | ||
public function testSetTranslator_invalidArguments($translator) { | ||
$listener = $this->getListener(); | ||
|
||
$this->expectException(InvalidTypeException::class); | ||
$listener->setTranslator($translator); | ||
} | ||
|
||
public function dataSetTranslator_invalidArguments() { | ||
return [ | ||
[null], | ||
[new \stdClass()], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Tests\EventListener; | ||
|
||
use Craue\FormFlowBundle\EventListener\FlowExpiredEventListener; | ||
use Craue\FormFlowBundle\Tests\UnitTestCase; | ||
|
||
/** | ||
* @group unit | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2021 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class FlowExpiredEventListenerTest extends UnitTestCase { | ||
|
||
use EventListenerWithTranslatorTestTrait; | ||
|
||
protected function getListener() { | ||
return new FlowExpiredEventListener(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
Tests/EventListener/PreviousStepInvalidEventListenerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Craue\FormFlowBundle\Tests\EventListener; | ||
|
||
use Craue\FormFlowBundle\EventListener\PreviousStepInvalidEventListener; | ||
use Craue\FormFlowBundle\Tests\UnitTestCase; | ||
|
||
/** | ||
* @group unit | ||
* | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2021 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class PreviousStepInvalidEventListenerTest extends UnitTestCase { | ||
|
||
use EventListenerWithTranslatorTestTrait; | ||
|
||
protected function getListener() { | ||
return new PreviousStepInvalidEventListener(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters