Skip to content

Commit 5f5f5e5

Browse files
committed
Add support for symfony Controllers: Test get unknown service from container
1 parent 7ece628 commit 5f5f5e5

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Lookyman\PHPStan\Symfony\Rules;
6+
7+
use Lookyman\PHPStan\Symfony\ServiceMap;
8+
use PHPStan\Rules\Rule;
9+
10+
final class ContainerInterfaceUnknownServiceRuleTest extends \PHPStan\Testing\RuleTestCase
11+
{
12+
13+
protected function getRule(): Rule
14+
{
15+
$serviceMap = new ServiceMap(__DIR__ . '/../container.xml');
16+
17+
return new ContainerInterfaceUnknownServiceRule($serviceMap);
18+
}
19+
20+
public function testGetUnknownService()
21+
{
22+
$this->analyse([__DIR__ . '/data/ExampleController.php'], [
23+
[
24+
'Service "service.not.found" is not registered in the container.',
25+
20,
26+
],
27+
]);
28+
}
29+
30+
}
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
<?php declare(strict_types = 1);
1+
<?php
2+
3+
declare(strict_types = 1);
24

35
namespace Lookyman\PHPStan\Symfony\Rules\data;
46

57
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
68

79
include __DIR__ . '/Controller.php';
810

9-
class ExampleController extends Controller
11+
final class ExampleController extends Controller
1012
{
1113

12-
public function getPrivateServiceAction()
13-
{
14-
$service = $this->get('private');
15-
$service->noMethod();
16-
}
14+
public function getPrivateServiceAction()
15+
{
16+
$service = $this->get('private');
17+
$service->noMethod();
18+
}
19+
20+
public function getUnknownService()
21+
{
22+
$service = $this->get('service.not.found');
23+
$service->noMethod();
24+
}
25+
1726
}

0 commit comments

Comments
 (0)