1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Micro framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Console\Test\Unit\Listener; |
15
|
|
|
|
16
|
|
|
use Micro\Component\EventEmitter\EventInterface; |
17
|
|
|
use Micro\Kernel\App\Business\Event\ApplicationReadyEventInterface; |
18
|
|
|
use Micro\Plugin\Console\Facade\ConsoleApplicationFacadeInterface; |
19
|
|
|
use Micro\Plugin\Console\Listener\ApplicationStartEventListener; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
class ApplicationStartEventListenerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
private ApplicationStartEventListener $listener; |
25
|
|
|
|
26
|
|
|
private ConsoleApplicationFacadeInterface $facade; |
27
|
|
|
|
28
|
|
|
private ApplicationReadyEventInterface $event; |
29
|
|
|
|
30
|
|
|
protected function setUp(): void |
31
|
|
|
{ |
32
|
|
|
$this->event = $this->createMock(ApplicationReadyEventInterface::class); |
33
|
|
|
$this->facade = $this->createMock(ConsoleApplicationFacadeInterface::class); |
34
|
|
|
$this->listener = new ApplicationStartEventListener( |
35
|
|
|
$this->facade, |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @dataProvider dataProvider |
41
|
|
|
*/ |
42
|
|
|
public function testOn(bool $isCli) |
43
|
|
|
{ |
44
|
|
|
$this->event |
45
|
|
|
->expects($this->once()) |
|
|
|
|
46
|
|
|
->method('systemEnvironment') |
47
|
|
|
->willReturn($isCli ? 'cli' : 'http'); |
48
|
|
|
|
49
|
|
|
$exceptedCall = $isCli ? $this->once() : $this->never(); |
50
|
|
|
|
51
|
|
|
$this->facade->expects($exceptedCall)->method('run'); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->listener->on($this->event); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSupports() |
57
|
|
|
{ |
58
|
|
|
$this->assertFalse(ApplicationStartEventListener::supports(new class() implements EventInterface {})); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function dataProvider() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
[true], |
65
|
|
|
[false], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.