1 | <?php |
||||
2 | |||||
3 | namespace Nip\Controllers\Tests\Traits; |
||||
4 | |||||
5 | use Nip\Controllers\Tests\AbstractTest; |
||||
6 | use Nip\Controllers\Tests\Fixtures\Controllers\BaseController; |
||||
7 | use Nip\Controllers\Tests\Fixtures\Controllers\ViewController; |
||||
8 | use Nip\Http\Response\JsonResponse; |
||||
9 | use Nip\Http\Response\Response; |
||||
10 | |||||
11 | /** |
||||
12 | * Class HasResponseTraitTest |
||||
13 | * @package Nip\Controllers\Tests\Traits |
||||
14 | */ |
||||
15 | class HasResponseTraitTest extends AbstractTest |
||||
16 | { |
||||
17 | public function test_newResponse() |
||||
18 | { |
||||
19 | $controller = new ViewController(); |
||||
20 | $controller->setName('base'); |
||||
21 | $controller->payload()->withDefaultFormat('view'); |
||||
0 ignored issues
–
show
|
|||||
22 | |||||
23 | /** @var Response $response */ |
||||
24 | $response = $controller->callAction('index'); |
||||
0 ignored issues
–
show
'index' of type string is incompatible with the type boolean expected by parameter $method of Nip\Controllers\Controller::callAction() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
25 | |||||
26 | self::assertInstanceOf(Response::class, $response); |
||||
27 | |||||
28 | $content = $response->getContent(); |
||||
29 | self::assertStringContainsString('BASE-INDEX-CONTENT', $content); |
||||
30 | } |
||||
31 | |||||
32 | public function test_payload_set() |
||||
33 | { |
||||
34 | $controller = new BaseController(); |
||||
35 | $controller->setName('base'); |
||||
36 | $controller->payload()->withDefaultFormat('json'); |
||||
0 ignored issues
–
show
Are you sure the usage of
$controller->payload() targeting Nip\Controllers\Controller::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
37 | $controller->payload()->set('var1', 1); |
||||
0 ignored issues
–
show
Are you sure the usage of
$controller->payload() targeting Nip\Controllers\Controller::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
38 | $controller->payload()['var2'] = 2; |
||||
0 ignored issues
–
show
Are you sure the usage of
$controller->payload() targeting Nip\Controllers\Controller::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
39 | $controller->payload()->with(['var3' => 3, 'var4' => 4]); |
||||
0 ignored issues
–
show
Are you sure the usage of
$controller->payload() targeting Nip\Controllers\Controller::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
40 | $controller->payload()->with('var5', 5); |
||||
0 ignored issues
–
show
Are you sure the usage of
$controller->payload() targeting Nip\Controllers\Controller::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
41 | |||||
42 | $response = $controller->getResponse(true); |
||||
43 | self::assertInstanceOf(JsonResponse::class, $response); |
||||
44 | |||||
45 | $content = $response->getContent(); |
||||
46 | self::assertStringContainsString('{"var1":1,"var2":2,"var3":3,"var4":4,"var5":5}', $content); |
||||
47 | } |
||||
48 | } |
||||
49 |
This check looks for function or method calls that always return null and whose return value is used.
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.