Issues (5)

tests/ChainOfResponsibilityTest.php (3 issues)

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);
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->execute(NoticeHandler::class, true);
0 ignored issues
show
The call to Behavioral\ChainOfRespon...ainInterface::execute() has too many arguments starting with true. ( 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
                      execute(NoticeHandler::class, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

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->execute(WarningHandler::class, true);
0 ignored issues
show
The call to Behavioral\ChainOfRespon...ainInterface::execute() has too many arguments starting with true. ( Ignorable by Annotation )

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

62
        $this->chain->/** @scrutinizer ignore-call */ 
63
                      execute(WarningHandler::class, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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->execute(ErrorHandler::class, true);
0 ignored issues
show
The call to Behavioral\ChainOfRespon...ainInterface::execute() has too many arguments starting with true. ( Ignorable by Annotation )

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

74
        $this->chain->/** @scrutinizer ignore-call */ 
75
                      execute(ErrorHandler::class, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

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