HasResponseTraitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 19
c 2
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_payload_set() 0 15 1
A test_newResponse() 0 13 1
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
Bug introduced by
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 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...
22
23
        /** @var Response $response */
24
        $response = $controller->callAction('index');
0 ignored issues
show
Bug introduced by
'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 ignore-type  annotation

24
        $response = $controller->callAction(/** @scrutinizer ignore-type */ 'index');
Loading history...
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
Bug introduced by
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 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...
37
        $controller->payload()->set('var1', 1);
0 ignored issues
show
Bug introduced by
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 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...
38
        $controller->payload()['var2'] = 2;
0 ignored issues
show
Bug introduced by
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 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
        $controller->payload()->with(['var3' => 3, 'var4' => 4]);
0 ignored issues
show
Bug introduced by
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 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...
40
        $controller->payload()->with('var5', 5);
0 ignored issues
show
Bug introduced by
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 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...
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