1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bex\Behat\ChooseTestsExtension\Decorator; |
4
|
|
|
|
5
|
|
|
use Behat\Testwork\Cli\Controller; |
6
|
|
|
use Behat\Testwork\EventDispatcher\TestworkEventDispatcherSymfonyLegacy; |
7
|
|
|
use Bex\Behat\ChooseTestsExtension\Event\AfterAvailableSuitesRegistered; |
8
|
|
|
use Bex\Behat\ChooseTestsExtension\Event\AvailableSuitesRegistered; |
9
|
|
|
use Bex\Behat\ChooseTestsExtension\Event\BeforeAvailableSuitesRegistered; |
10
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
14
|
|
|
|
15
|
|
|
class SuiteControllerDecorator implements Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var Controller |
19
|
|
|
*/ |
20
|
|
|
private $suiteContoller; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var EventDispatcherInterface |
24
|
|
|
*/ |
25
|
|
|
private $eventDispatcher; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Controller $suiteContoller |
29
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
30
|
|
|
*/ |
31
|
|
|
public function __construct(Controller $suiteContoller, EventDispatcherInterface $eventDispatcher) |
32
|
|
|
{ |
33
|
|
|
$this->suiteContoller = $suiteContoller; |
34
|
|
|
$this->eventDispatcher = $eventDispatcher; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Configures command to be executable by the controller. |
39
|
|
|
* |
40
|
|
|
* @param SymfonyCommand $command |
41
|
|
|
*/ |
42
|
|
|
public function configure(SymfonyCommand $command) |
43
|
|
|
{ |
44
|
|
|
return $this->suiteContoller->configure($command); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Executes controller. |
49
|
|
|
* |
50
|
|
|
* @param InputInterface $input |
51
|
|
|
* @param OutputInterface $output |
52
|
|
|
* |
53
|
|
|
* @return null|integer |
54
|
|
|
*/ |
55
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
|
|
if ($this->eventDispatcher instanceof TestworkEventDispatcherSymfonyLegacy) { |
58
|
|
|
$this->eventDispatcher->dispatch(AvailableSuitesRegistered::BEFORE, new BeforeAvailableSuitesRegistered()); |
59
|
|
|
} else { |
60
|
|
|
$this->eventDispatcher->dispatch(new BeforeAvailableSuitesRegistered(), AvailableSuitesRegistered::BEFORE); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$result = $this->suiteContoller->execute($input, $output); |
64
|
|
|
|
65
|
|
|
if ($this->eventDispatcher instanceof TestworkEventDispatcherSymfonyLegacy) { |
66
|
|
|
$this->eventDispatcher->dispatch(AvailableSuitesRegistered::AFTER, new AfterAvailableSuitesRegistered()); |
67
|
|
|
} else { |
68
|
|
|
$this->eventDispatcher->dispatch(new AfterAvailableSuitesRegistered(), AvailableSuitesRegistered::AFTER); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $result; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: