Skip to content

Commit f5daf13

Browse files
authored
Add ServiceMap tests
Add ServiceMap tests
2 parents efc16f9 + a7a118f commit f5daf13

File tree

6 files changed

+91
-28
lines changed

6 files changed

+91
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/vendor
22
/.php_cs.cache
3+
/phpunit.xml

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"autoload-dev": {
2020
"psr-4": {
21-
"Proget\\PHPStan\\Yii2\\": "tests/"
21+
"Proget\\Tests\\PHPStan\\Yii2\\": "tests/"
2222
}
2323
},
2424
"license": "MIT",

composer.lock

Lines changed: 30 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/ServiceMapTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Proget\Tests\PHPStan\Yii2;
6+
7+
use PhpParser\Node\Scalar\String_;
8+
use PHPUnit\Framework\TestCase;
9+
use Proget\PHPStan\Yii2\ServiceMap;
10+
11+
final class ServiceMapTest extends TestCase
12+
{
13+
public function testThrowExceptionWhenConfigurationFileDoesNotExist(): void
14+
{
15+
$this->expectException(\InvalidArgumentException::class);
16+
$this->expectExceptionMessage('Provided config path invalid-path must exist');
17+
18+
new ServiceMap('invalid-path');
19+
}
20+
21+
public function testThrowExceptionWhenClosureServiceHasMissingReturnType(): void
22+
{
23+
$this->expectException(\RuntimeException::class);
24+
$this->expectExceptionMessage('Please provide return type for no-return-type service closure');
25+
26+
new ServiceMap(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'yii-config-invalid.php');
27+
}
28+
29+
public function testItLoadsServices(): void
30+
{
31+
$serviceMap = new ServiceMap(__DIR__.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'yii-config-valid.php');
32+
33+
$this->assertSame(\SplStack::class, $serviceMap->getServiceClassFromNode(new String_('closure')));
34+
$this->assertSame(\SplObjectStorage::class, $serviceMap->getServiceClassFromNode(new String_('service')));
35+
$this->assertSame(\SplFileInfo::class, $serviceMap->getServiceClassFromNode(new String_('nested-service-class')));
36+
}
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
'container' => ['singletons' => [
5+
'no-return-type' => function () {
6+
return new \ArrayObject();
7+
}
8+
]]
9+
];

tests/assets/yii-config-valid.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'container' => ['singletons' => [
5+
'closure' => function(): \SplStack {
6+
return new \SplStack();
7+
},
8+
'service' => ['class' => \SplObjectStorage::class],
9+
'nested-service-class' => [
10+
['class' => \SplFileInfo::class]
11+
]
12+
]]
13+
];

0 commit comments

Comments
 (0)