AbstractControllerTest::testParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * Push notification server example (http://github.com/juliangut/tify_example)
4
 *
5
 * @link https://github.com/juliangut/tify_example for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify_example/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Pusher\Tests\Entity;
11
12
use Jgut\Pusher\Controller\AbstractController;
13
use Psr\Http\Message\ServerRequestInterface;
14
15
/**
16
 * Class AbstractControllerTest
17
 */
18
class AbstractControllerTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var AbstractController
22
     */
23
    protected $controller;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function setUp()
29
    {
30
        $this->controller = $this->getMockForAbstractClass(AbstractController::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...tractController::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Jgut\Pusher\Controller\AbstractController> of property $controller.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
    }
32
33
    public function testParameters()
34
    {
35
        $reflection = new \ReflectionClass(get_class($this->controller));
36
        $method = $reflection->getMethod('resolveRequestParameters');
37
        $method->setAccessible(true);
38
39
        $parameters = [
40
            'param1' => 'value1',
41
        ];
42
43
        $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
44
        $request->expects(self::once())->method('getParsedBody')->will(self::returnValue($parameters));
45
46
        self::assertEquals($parameters, $method->invokeArgs($this->controller, [$request, ['param1'], [], ['param1']]));
47
    }
48
49
    /**
50
     * @expectedException \RuntimeException
51
     */
52
    public function testBadParameters()
53
    {
54
        $reflection = new \ReflectionClass(get_class($this->controller));
55
        $method = $reflection->getMethod('resolveRequestParameters');
56
        $method->setAccessible(true);
57
58
        $request = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
59
        $request->expects(self::once())->method('getParsedBody')->will(self::returnValue([]));
60
61
        $method->invokeArgs($this->controller, [$request, ['param1'], [], ['param1']]);
62
    }
63
}
64