testActionSetParamWithActionStringSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Nip\Dispatcher\Tests\Commands;
4
5
use Nip\Dispatcher\Commands\Command;
6
use Nip\Dispatcher\Tests\AbstractTest;
7
use Nip\Http\Response\Response;
8
use Nip\Request;
9
10
/**
11
 * Class CommandTest
12
 * @package Nip\Dispatcher\Tests\Commands
13
 */
14
class CommandTest extends AbstractTest
15
{
16
    public function testGetSetRequest()
17
    {
18
        $command = new Command();
19
        self::assertEquals(null, $command->getRequest());
20
        self::assertFalse($command->hasRequest());
21
22
        $request = new Request();
0 ignored issues
show
Deprecated Code introduced by
The class Nip\Request has been deprecated: use \Nip\Http\Request ( Ignorable by Annotation )

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

22
        $request = /** @scrutinizer ignore-deprecated */ new Request();
Loading history...
23
        $command->setRequest($request);
24
25
        self::assertTrue($command->hasRequest());
26
        self::assertEquals($request, $command->getRequest());
27
    }
28
29
    public function testGetSetResponse()
30
    {
31
        $command = new Command();
32
        self::assertEquals(null, $command->getReturn());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $command->getReturn() targeting Nip\Dispatcher\Commands\Command::getReturn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33
        self::assertFalse($command->hasReturn());
34
35
        $response = new Response();
36
        $command->setReturn($response);
37
        self::assertTrue($command->hasReturn());
38
        self::assertEquals($response, $command->getReturn());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $command->getReturn() targeting Nip\Dispatcher\Commands\Command::getReturn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
    }
40
41
    /**
42
     * @throws \Exception
43
     */
44
    public function testActionGetParamWithActionStringSet()
45
    {
46
        $command = new Command();
47
        $command->setAction('Module@Controller::action');
48
        self::assertEquals('Module@Controller::action', $command->getAction());
49
50
        self::expectException(\Exception::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

50
        self::/** @scrutinizer ignore-call */ 
51
              expectException(\Exception::class);
Loading history...
51
        $command->getActionParam('name');
52
    }
53
54
    /**
55
     * @throws \Exception
56
     */
57
    public function testActionGetParamWithActionEmpty()
58
    {
59
        $command = new Command();
60
61
        self::assertNull($command->getActionParam('name'));
62
    }
63
64
    /**
65
     * @throws \Exception
66
     */
67
    public function testActionSetParamWithActionStringSet()
68
    {
69
        $command = new Command();
70
        $command->setAction('Module@Controller::action');
71
72
        self::expectException(\Exception::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

72
        self::/** @scrutinizer ignore-call */ 
73
              expectException(\Exception::class);
Loading history...
73
        $command->setActionParam('name', 'value');
74
    }
75
76
    /**
77
     * @throws \Exception
78
     */
79
    public function testActionSetParamWithActionEmpty()
80
    {
81
        $command = new Command();
82
83
        self::assertNull($command->getActionParam('name'));
84
85
        $command->setActionParam('name', 'value');
86
        self::assertEquals('value', $command->getActionParam('name'));
87
        self::assertEquals(['name' => 'value'], $command->getAction());
88
    }
89
}
90