Skip to content

Commit 1217342

Browse files
committed
Add phpstan
1 parent c452316 commit 1217342

File tree

8 files changed

+38
-10
lines changed

8 files changed

+38
-10
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"nette/utils": "^3.0.0@alpha"
2525
},
2626
"require-dev": {
27+
"nette/caching": "^3.0.0@alpha",
28+
"nette/finder": "^3.0.0@alpha",
2729
"latte/latte": "^3.0.0@alpha",
2830
"tracy/tracy": "^2.4.0"
2931
},

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- '#^Arachne\\Codeception\\Http\\Request::__construct\(\) does not call parent constructor from Nette\\Http\\Request#'

src/Module/NetteApplicationModule.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
*/
2222
class NetteApplicationModule extends Framework
2323
{
24+
/**
25+
* @var NetteConnector
26+
*/
27+
public $client;
28+
29+
/**
30+
* @var array
31+
*/
2432
protected $config = [
2533
'followRedirects' => true,
2634
];
@@ -37,11 +45,15 @@ public function _beforeSuite($settings = [])
3745

3846
public function _before(TestInterface $test)
3947
{
40-
$this->configFiles = null;
4148
$this->client = new NetteConnector();
42-
$this->client->setContainerAccessor(function () {
43-
return $this->getModule(NetteDIModule::class)->getContainer();
44-
});
49+
$this->client->setContainerAccessor(
50+
function () {
51+
/** @var NetteDIModule $diModule */
52+
$diModule = $this->getModule(NetteDIModule::class);
53+
54+
return $diModule->getContainer();
55+
}
56+
);
4557
$this->client->followRedirects($this->config['followRedirects']);
4658

4759
parent::_before($test);
@@ -74,8 +86,10 @@ public function seeRedirectTo($url)
7486
if ($this->client->isFollowingRedirects()) {
7587
$this->fail('Method seeRedirectTo only works when followRedirects option is disabled');
7688
}
77-
$request = $this->getModule(NetteDIModule::class)->grabService(IRequest::class);
78-
$response = $this->getModule(NetteDIModule::class)->grabService(IResponse::class);
89+
/** @var NetteDIModule $diModule */
90+
$diModule = $this->getModule(NetteDIModule::class);
91+
$request = $diModule->grabService(IRequest::class);
92+
$response = $diModule->grabService(IResponse::class);
7993
if ($response->getHeader('Location') !== $request->getUrl()->getHostUrl().$url && $response->getHeader('Location') !== $url) {
8094
$this->fail('Couldn\'t confirm redirect target to be "'.$url.'", Location header contains "'.$response->getHeader('Location').'".');
8195
}

src/Module/NetteDIModule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class NetteDIModule extends Module
5353
private $configFiles;
5454

5555
/**
56-
* @var Container
56+
* @var Container|null
5757
*/
5858
private $container;
5959

src/Tracy/Logger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Logger extends Extension
2222
Events::TEST_ERROR => 'testError',
2323
];
2424

25-
public function __construct()
25+
public function __construct($config, $options)
2626
{
27+
parent::__construct($config, $options);
2728
Debugger::$logDirectory = $this->getLogDir();
2829
}
2930

tests.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ How to run tests
22
====
33

44
```
5-
# install php-cs-fixer
6-
composer global require friendsofphp/php-cs-fixer "^2.0.0@dev"
5+
# install php-cs-fixer and phpstan
6+
composer global require friendsofphp/php-cs-fixer
7+
composer global require phpstan/phpstan
78
89
# go to the project's root directory, but NOT the tests subdirectory
910
cd <project_dir>
@@ -17,6 +18,9 @@ php-cs-fixer fix --dry-run
1718
# fix coding style
1819
php-cs-fixer fix
1920
21+
# static analysis
22+
phpstan analyse --level=4 --configuration=phpstan.neon src tests
23+
2024
# run tests
2125
sh ./tests/run.sh
2226
```

tests/integration/src/ApplicationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
class ApplicationTest extends Unit
1212
{
13+
protected $tester;
14+
1315
public function testApplication()
1416
{
1517
$this->assertInstanceOf(Application::class, $this->tester->grabService(Application::class));

tests/integration/src/DITest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
class DITest extends Unit
1212
{
13+
protected $tester;
14+
1315
public function testContainer()
1416
{
1517
$this->assertInstanceOf(Container::class, $this->tester->grabService(Container::class));

0 commit comments

Comments
 (0)