Completed
Push — master ( ff5baa...3970bf )
by Korotkov
07:54 queued 04:02
created

ChainOfResponsibilityTest::testChainRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\ChainOfResponsibility\Tests;
11
12
use Behavioral\ChainOfResponsibility\Chain;
13
use Behavioral\ChainOfResponsibility\ErrorHandler;
14
use Behavioral\ChainOfResponsibility\NoticeHandler;
15
use Behavioral\ChainOfResponsibility\WarningHandler;
16
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
17
18
/**
19
 * Class ChainOfResponsibilityTest
20
 * @package Behavioral\ChainOfResponsibility\Tests
21
 */
22
class ChainOfResponsibilityTest extends PHPUnit_Framework_TestCase
23
{
24
25
    /**
26
     * @var Chain
27
     */
28
    protected $chain;
29
30
    protected function setUp(): void
31
    {
32
        $this->chain = new Chain();
33
        $this->chain->addToChain(NoticeHandler::class);
34
        $this->chain->addToChain(WarningHandler::class);
35
        $this->chain->addToChain(ErrorHandler::class);
36
    }
37
38
    public function testChainRun(): void
39
    {
40
        ob_start();
41
        $this->chain->run(1);
42
        $notice = ob_get_clean();
43
44
        ob_start();
45
        $this->chain->run(2);
46
        $warning = ob_get_clean();
47
48
        ob_start();
49
        $this->chain->run(3);
50
        $error = ob_get_clean();
51
52
        $this->assertEquals($notice, "NOTICE \n\n");
53
        $this->assertEquals($warning, "NOTICE \nWARNING \n\n");
54
        $this->assertEquals($error, "NOTICE \nWARNING \nERROR \n\n");
55
    }
56
}
57