These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace PhpGitHooks\Module\JsonLint\Tests\Behaviour; |
||
4 | |||
5 | use PhpGitHooks\Module\Configuration\Tests\Stub\ConfigurationDataResponseStub; |
||
6 | use PhpGitHooks\Module\Configuration\Tests\Stub\PreCommitResponseStub; |
||
7 | use PhpGitHooks\Module\Files\Contract\Query\JsonFilesExtractorQuery; |
||
8 | use PhpGitHooks\Module\Files\Tests\Stub\JsonFilesResponseStub; |
||
9 | use PhpGitHooks\Module\Git\Contract\Response\BadJobLogoResponse; |
||
10 | use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter; |
||
11 | use PhpGitHooks\Module\Git\Tests\Stub\FilesCommittedStub; |
||
12 | use PhpGitHooks\Module\JsonLint\Contract\Command\JsonLintToolCommand; |
||
13 | use PhpGitHooks\Module\JsonLint\Contract\CommandHandler\JsonLintToolCommandHandler; |
||
14 | use PhpGitHooks\Module\JsonLint\Contract\Exception\JsonLintViolationsException; |
||
15 | use PhpGitHooks\Module\JsonLint\Service\JsonLintTool; |
||
16 | use PhpGitHooks\Module\JsonLint\Service\JsonLintToolExecutor; |
||
17 | use PhpGitHooks\Module\JsonLint\Tests\Infrastructure\JsonLintUnitTestCase; |
||
18 | |||
19 | class JsonLintToolCommandHandlerTest extends JsonLintUnitTestCase |
||
20 | { |
||
21 | /** |
||
22 | * @var JsonLintToolCommandHandler |
||
23 | */ |
||
24 | private $jsonLintToolCommandHandler; |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $errorMessage; |
||
29 | |||
30 | protected function setUp() |
||
31 | { |
||
32 | $this->jsonLintToolCommandHandler = new JsonLintToolCommandHandler( |
||
33 | new JsonLintTool( |
||
34 | new JsonLintToolExecutor( |
||
35 | $this->getJsonLintProcessor(), |
||
0 ignored issues
–
show
|
|||
36 | $this->getOutputInterface() |
||
0 ignored issues
–
show
It seems like
$this->getOutputInterface() targeting PhpGitHooks\Module\Git\T...t::getOutputInterface() can also be of type object<Mockery\MockInterface> ; however, PhpGitHooks\Module\JsonL...Executor::__construct() does only seem to accept object<Symfony\Component...Output\OutputInterface> , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
37 | ), |
||
38 | $this->getQueryBus() |
||
0 ignored issues
–
show
It seems like
$this->getQueryBus() targeting PhpGitHooks\Module\Share...BusTrait::getQueryBus() can also be of type object<Mockery\MockInterface> ; however, PhpGitHooks\Module\JsonL...LintTool::__construct() does only seem to accept object<Bruli\EventBusBundle\QueryBus\QueryBus> , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
39 | ) |
||
40 | ); |
||
41 | |||
42 | $this->errorMessage = PreCommitResponseStub::FIX_YOUR_CODE; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @test |
||
47 | */ |
||
48 | public function itShouldNotExecuteTool() |
||
49 | { |
||
50 | $files = FilesCommittedStub::createWithoutJsonFiles(); |
||
51 | |||
52 | $this->shouldHandleQuery( |
||
53 | new JsonFilesExtractorQuery($files), |
||
54 | JsonFilesResponseStub::createNoData() |
||
55 | ); |
||
56 | |||
57 | $this->jsonLintToolCommandHandler->handle( |
||
58 | new JsonLintToolCommand($files, $this->errorMessage) |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @test |
||
64 | */ |
||
65 | public function itShouldExecuteTool() |
||
66 | { |
||
67 | $files = JsonFilesResponseStub::createWithJsonData(); |
||
68 | $output = new PreCommitOutputWriter(JsonLintToolExecutor::CHECKING_MESSAGE); |
||
69 | |||
70 | $this->shouldHandleQuery( |
||
71 | new JsonFilesExtractorQuery($files->getFiles()), |
||
72 | $files |
||
73 | ); |
||
74 | |||
75 | $this->shouldWriteOutput($output->getMessage()); |
||
76 | |||
77 | foreach ($files->getFiles() as $file) { |
||
78 | $this->shouldProcessJsonLint($file, []); |
||
0 ignored issues
–
show
array() is of type array , but the function expects a string|null .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
79 | } |
||
80 | $this->shouldWriteLnOutput($output->getSuccessfulMessage()); |
||
81 | |||
82 | $this->jsonLintToolCommandHandler->handle( |
||
83 | new JsonLintToolCommand($files->getFiles(), $this->errorMessage) |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @test |
||
89 | */ |
||
90 | public function itShouldThrowsException() |
||
91 | { |
||
92 | $this->expectException(JsonLintViolationsException::class); |
||
93 | $output = new PreCommitOutputWriter(JsonLintToolExecutor::CHECKING_MESSAGE); |
||
94 | |||
95 | $jsonFilesResponse = JsonFilesResponseStub::createWithJsonData(); |
||
96 | |||
97 | $this->shouldHandleQuery( |
||
98 | new JsonFilesExtractorQuery($jsonFilesResponse->getFiles()), |
||
99 | $jsonFilesResponse |
||
100 | ); |
||
101 | $this->shouldWriteOutput($output->getMessage()); |
||
102 | |||
103 | $errorTxt = null; |
||
104 | foreach ($jsonFilesResponse->getFiles() as $file) { |
||
105 | $error = 'ERROR'; |
||
106 | $this->shouldProcessJsonLint($file, $error); |
||
107 | $errorTxt .= $error; |
||
108 | } |
||
109 | |||
110 | $this->shouldWriteLnOutput($output->getFailMessage()); |
||
111 | $this->shouldWriteLnOutput($output->setError($errorTxt)); |
||
112 | $this->shouldWriteLnOutput(BadJobLogoResponse::paint($this->errorMessage)); |
||
113 | |||
114 | $this->jsonLintToolCommandHandler->handle( |
||
115 | new JsonLintToolCommand($jsonFilesResponse->getFiles(), $this->errorMessage) |
||
116 | ); |
||
117 | } |
||
118 | } |
||
119 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.