File tree Expand file tree Collapse file tree 4 files changed +124
-0
lines changed Expand file tree Collapse file tree 4 files changed +124
-0
lines changed Original file line number Diff line number Diff line change 88use PHPStan \Testing \RuleTestCase ;
99use function class_exists ;
1010use function interface_exists ;
11+ use const PHP_VERSION_ID ;
1112
1213/**
1314 * @extends RuleTestCase<ContainerInterfacePrivateServiceRule>
@@ -78,4 +79,37 @@ public function testGetPrivateServiceInServiceSubscriber(): void
7879 );
7980 }
8081
82+ public function testGetPrivateServiceWithoutAutowireLocatorAttribute (): void
83+ {
84+ if (PHP_VERSION_ID < 80000 ) {
85+ self ::markTestSkipped ('The test uses PHP Attributes which are available since PHP 8.0. ' );
86+ }
87+
88+ $ this ->analyse (
89+ [
90+ __DIR__ . '/ExampleAutowireLocatorEmptyService.php ' ,
91+ ],
92+ [
93+ [
94+ 'Service "private" is private. ' ,
95+ 22 ,
96+ ],
97+ ]
98+ );
99+ }
100+
101+ public function testGetPrivateServiceViaAutowireLocatorAttribute (): void
102+ {
103+ if (PHP_VERSION_ID < 80000 ) {
104+ self ::markTestSkipped ('The test uses PHP Attributes which are available since PHP 8.0. ' );
105+ }
106+
107+ $ this ->analyse (
108+ [
109+ __DIR__ . '/ExampleAutowireLocatorService.php ' ,
110+ ],
111+ []
112+ );
113+ }
114+
81115}
Original file line number Diff line number Diff line change 99use PHPStan \Testing \RuleTestCase ;
1010use function class_exists ;
1111use function interface_exists ;
12+ use const PHP_VERSION_ID ;
1213
1314/**
1415 * @extends RuleTestCase<ContainerInterfaceUnknownServiceRule>
@@ -72,6 +73,43 @@ public function testGetPrivateServiceInLegacyServiceSubscriber(): void
7273 );
7374 }
7475
76+ public function testGetPrivateServiceWithoutAutowireLocatorAttribute (): void
77+ {
78+ if (PHP_VERSION_ID < 80000 ) {
79+ self ::markTestSkipped ('The test uses PHP Attributes which are available since PHP 8.0. ' );
80+ }
81+
82+ $ this ->analyse (
83+ [
84+ __DIR__ . '/ExampleAutowireLocatorEmptyService.php ' ,
85+ ],
86+ [
87+ [
88+ 'Service "Foo" is not registered in the AutowireLocator. ' ,
89+ 21 ,
90+ ],
91+ [
92+ 'Service "private" is not registered in the AutowireLocator. ' ,
93+ 22 ,
94+ ],
95+ ]
96+ );
97+ }
98+
99+ public function testGetPrivateServiceViaAutowireLocatorAttribute (): void
100+ {
101+ if (PHP_VERSION_ID < 80000 ) {
102+ self ::markTestSkipped ('The test uses PHP Attributes which are available since PHP 8.0. ' );
103+ }
104+
105+ $ this ->analyse (
106+ [
107+ __DIR__ . '/ExampleAutowireLocatorService.php ' ,
108+ ],
109+ []
110+ );
111+ }
112+
75113 public static function getAdditionalConfigFiles (): array
76114 {
77115 return [
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Rules \Symfony ;
4+
5+ use Psr \Container \ContainerInterface ;
6+ use Symfony \Component \DependencyInjection \Attribute \AutowireLocator ;
7+
8+ final class ExampleAutowireLocatorEmptyService
9+ {
10+
11+ public function __construct (
12+ #[AutowireLocator([])]
13+ private ContainerInterface $ locator
14+ )
15+ {
16+ $ this ->locator = $ locator ;
17+ }
18+
19+ public function privateServiceInLocator (): void
20+ {
21+ $ this ->locator ->get ('Foo ' );
22+ $ this ->locator ->get ('private ' );
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \Symfony ;
4+
5+ use Psr \Container \ContainerInterface ;
6+ use Symfony \Component \DependencyInjection \Attribute \AutowireLocator ;
7+
8+ final class ExampleAutowireLocatorService
9+ {
10+
11+ public function __construct (
12+ #[AutowireLocator([
13+ 'Foo ' => 'Foo ' ,
14+ 'private ' => 'Foo ' ,
15+ ])]
16+ private ContainerInterface $ locator
17+ )
18+ {
19+ }
20+
21+ public function privateServiceInLocator (): void
22+ {
23+ $ this ->locator ->get ('Foo ' );
24+ $ this ->locator ->get ('private ' );
25+ }
26+
27+ }
You can’t perform that action at this time.
0 commit comments