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); |
|
|
|
|
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
|
|
|
|
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..