Passed
Push — master ( 2e0c74...259d67 )
by Korotkov
08:40 queued 07:19
created

ChainOfResponsibilityTest::testWarningHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
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 an error\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 an error\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 an error\n");
48
    }
49
}
50