ApplicationStartEventListenerTest::testSupports()
last analyzed

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
nc 1
nop 0
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())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Micro\Kernel\App\Busines...tionReadyEventInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            ->/** @scrutinizer ignore-call */ 
46
              expects($this->once())

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.

Loading history...
46
            ->method('systemEnvironment')
47
            ->willReturn($isCli ? 'cli' : 'http');
48
49
        $exceptedCall = $isCli ? $this->once() : $this->never();
50
51
        $this->facade->expects($exceptedCall)->method('run');
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Micro\Plugin\Console\Fac...licationFacadeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->facade->/** @scrutinizer ignore-call */ 
52
                       expects($exceptedCall)->method('run');

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.

Loading history...
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