1 | <?php |
||||||
2 | declare(strict_types=1); |
||||||
3 | |||||||
4 | namespace Nip\Dispatcher\Tests; |
||||||
5 | |||||||
6 | use Nip\Dispatcher\Commands\Command; |
||||||
7 | use Nip\Dispatcher\Dispatcher; |
||||||
8 | use Nip\Dispatcher\Exceptions\InvalidCommandException; |
||||||
9 | use Psr\Http\Message\RequestInterface; |
||||||
10 | use Psr\Http\Message\ResponseInterface; |
||||||
11 | |||||||
12 | /** |
||||||
13 | * Class DispatcherTest |
||||||
14 | * @package Nip\Dispatcher\Tests |
||||||
15 | */ |
||||||
16 | class DispatcherTest extends AbstractTest |
||||||
17 | { |
||||||
18 | /** |
||||||
19 | * @var Dispatcher |
||||||
20 | */ |
||||||
21 | protected $object; |
||||||
22 | |||||||
23 | |||||||
24 | public function testEmptyCommand() |
||||||
25 | { |
||||||
26 | $command = new Command(); |
||||||
27 | |||||||
28 | self::expectException(InvalidCommandException::class); |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
29 | $this->object->dispatchCommand($command); |
||||||
30 | } |
||||||
31 | |||||||
32 | public function testClosure() |
||||||
33 | { |
||||||
34 | $command = new Command(); |
||||||
35 | $command->setAutoInitRequest(true); |
||||||
36 | $command->getRequest(true)->query->set('variable', 'value'); |
||||||
37 | $command->setAction( |
||||||
38 | function (RequestInterface $request, ResponseInterface $response) { |
||||||
39 | $response->setContent($request->query->get('variable')); |
||||||
0 ignored issues
–
show
The method
setContent() does not exist on Psr\Http\Message\ResponseInterface . It seems like you code against a sub-type of said class. However, the method does not exist in Nyholm\Psr7\Response . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
40 | return $response; |
||||||
41 | } |
||||||
42 | ); |
||||||
43 | |||||||
44 | $response = $this->object->dispatchCommand($command)->getReturn(); |
||||||
0 ignored issues
–
show
Are you sure the assignment to
$response is correct as $this->object->dispatchC...($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 assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
45 | self::assertInstanceOf(ResponseInterface::class, $response); |
||||||
46 | self::assertSame('value', $response->getContent()); |
||||||
47 | } |
||||||
48 | |||||||
49 | public function testRequestModuleController() |
||||||
50 | { |
||||||
51 | $command = new Command(); |
||||||
52 | $command->setAutoInitRequest(true); |
||||||
53 | $command->getRequest(true) |
||||||
54 | ->setModuleName('frontend') |
||||||
55 | ->setControllerName('baseTrait'); |
||||||
56 | |||||||
57 | $response = $this->object->dispatchCommand($command)->getReturn(); |
||||||
0 ignored issues
–
show
Are you sure the assignment to
$response is correct as $this->object->dispatchC...($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 assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
58 | self::assertInstanceOf(ResponseInterface::class, $response); |
||||||
59 | self::assertEquals('index response', $response->getContent()); |
||||||
60 | } |
||||||
61 | |||||||
62 | protected function setUp(): void |
||||||
63 | { |
||||||
64 | parent::setUp(); |
||||||
65 | $this->object = new Dispatcher(); |
||||||
66 | } |
||||||
67 | } |
||||||
68 |