Passed
Push — master ( 125b51...71075d )
by Korotkov
03:09 queued 01:44
created

ChainOfResponsibilityTest::testAllNoticeHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @author  : Jagepard <[email protected]>
5
 * @license https://mit-license.org/ MIT
6
 */
7
8
namespace Behavioral\ChainOfResponsibility\Tests;
9
10
use Behavioral\ChainOfResponsibility\{ChainInterface, ErrorHandler, NoticeHandler, WarningHandler};
11
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
12
13
class ChainOfResponsibilityTest extends PHPUnit_Framework_TestCase
14
{
15
    protected ChainInterface $chain;
16
17
    protected function setUp(): void
18
    {
19
        $this->chain = new NoticeHandler();
20
        $this->chain->setNext(new WarningHandler())->setNext(new ErrorHandler);
0 ignored issues
show
Bug introduced by
The method setNext() does not exist on Behavioral\ChainOfResponsibility\ChainInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Behavioral\ChainOfResponsibility\ChainInterface. ( Ignorable by Annotation )

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

20
        $this->chain->/** @scrutinizer ignore-call */ 
21
                      setNext(new WarningHandler())->setNext(new ErrorHandler);
Loading history...
21
    }
22
23
    public function testNoticeHandler(): void
24
    {
25
        ob_start();
26
        $this->chain->execute(NoticeHandler::class);
27
        $notice = ob_get_clean();
28
29
        $this->assertEquals($notice, NoticeHandler::class . " has handle a request\n");
30
    }
31
32
    public function testWarningHandler(): void
33
    {
34
        ob_start();
35
        $this->chain->execute(WarningHandler::class);
36
        $warning = ob_get_clean();
37
38
        $this->assertEquals($warning, WarningHandler::class . " has handle a request\n");
39
    }
40
41
    public function testErrorHandler(): void
42
    {
43
        ob_start();
44
        $this->chain->execute(ErrorHandler::class);
45
        $error = ob_get_clean();
46
47
        $this->assertEquals($error, ErrorHandler::class . " has handle a request\n");
48
    }
49
50
    public function testAllNoticeHandler(): void
51
    {
52
        ob_start();
53
        $this->chain->executeAllInChainBeforeRequest(NoticeHandler::class);
0 ignored issues
show
Bug introduced by
The method executeAllInChainBeforeRequest() does not exist on Behavioral\ChainOfResponsibility\ChainInterface. Did you maybe mean execute()? ( Ignorable by Annotation )

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

53
        $this->chain->/** @scrutinizer ignore-call */ 
54
                      executeAllInChainBeforeRequest(NoticeHandler::class);

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...
54
        $notice = ob_get_clean();
55
56
        $this->assertEquals($notice, NoticeHandler::class . " has handle a request\n");
57
    }
58
59
    public function testAllWarningHandler(): void
60
    {
61
        ob_start();
62
        $this->chain->executeAllInChainBeforeRequest(WarningHandler::class);
63
        $warning = ob_get_clean();
64
65
        $this->assertEquals($warning,
66
            NoticeHandler::class . " has handle a request\n"
67
            . WarningHandler::class . " has handle a request\n"
68
        );
69
    }
70
71
    public function testAllErrorHandler(): void
72
    {
73
        ob_start();
74
        $this->chain->executeAllInChainBeforeRequest(ErrorHandler::class);
75
        $error = ob_get_clean();
76
77
        $this->assertEquals($error,
78
            NoticeHandler::class . " has handle a request\n"
79
            . WarningHandler::class . " has handle a request\n"
80
            . ErrorHandler::class . " has handle a request\n"
81
        );
82
    }
83
}
84