Skip to content

Commit b12e9e7

Browse files
xificurkclaude
andcommitted
Add tests for LazyParameterMap and LazyServiceMap
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b4a09bd commit b12e9e7

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Symfony;
4+
5+
use PhpParser\Node\Expr\Variable;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Type\Constant\ConstantStringType;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class LazyParameterMapTest extends TestCase
11+
{
12+
13+
public function testFactoryIsNotCalledOnConstruction(): void
14+
{
15+
$factory = $this->createMock(ParameterMapFactory::class);
16+
$factory->expects(self::never())->method('create');
17+
18+
new LazyParameterMap($factory); // @phpstan-ignore new.resultUnused
19+
}
20+
21+
public function testDelegation(): void
22+
{
23+
$parameter = new Parameter('app.string', 'abcdef');
24+
$innerMap = new DefaultParameterMap(['app.string' => $parameter]);
25+
26+
$factory = $this->createMock(ParameterMapFactory::class);
27+
$factory->expects(self::once())->method('create')->willReturn($innerMap);
28+
29+
$lazyMap = new LazyParameterMap($factory);
30+
31+
self::assertSame($innerMap->getParameters(), $lazyMap->getParameters());
32+
self::assertSame($innerMap->getParameter('app.string'), $lazyMap->getParameter('app.string'));
33+
self::assertNull($lazyMap->getParameter('unknown'));
34+
35+
$node = new Variable('x');
36+
$scope = $this->createMock(Scope::class);
37+
$scope->method('getType')->with($node)->willReturn(new ConstantStringType('app.string'));
38+
39+
self::assertSame($innerMap->getParameterKeysFromNode($node, $scope), $lazyMap->getParameterKeysFromNode($node, $scope));
40+
}
41+
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Symfony;
4+
5+
use PhpParser\Node\Expr\Variable;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Type\Constant\ConstantStringType;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class LazyServiceMapTest extends TestCase
11+
{
12+
13+
public function testFactoryIsNotCalledOnConstruction(): void
14+
{
15+
$factory = $this->createMock(ServiceMapFactory::class);
16+
$factory->expects(self::never())->method('create');
17+
18+
new LazyServiceMap($factory); // @phpstan-ignore new.resultUnused
19+
}
20+
21+
public function testDelegation(): void
22+
{
23+
$service = new Service('withClass', 'Foo', false, false, null);
24+
$innerMap = new DefaultServiceMap(['withClass' => $service]);
25+
26+
$factory = $this->createMock(ServiceMapFactory::class);
27+
$factory->expects(self::once())->method('create')->willReturn($innerMap);
28+
29+
$lazyMap = new LazyServiceMap($factory);
30+
31+
self::assertSame($innerMap->getServices(), $lazyMap->getServices());
32+
self::assertSame($innerMap->getService('withClass'), $lazyMap->getService('withClass'));
33+
self::assertNull($lazyMap->getService('unknown'));
34+
35+
$node = new Variable('x');
36+
$scope = $this->createMock(Scope::class);
37+
$scope->method('getType')->with($node)->willReturn(new ConstantStringType('withClass'));
38+
39+
self::assertSame($innerMap->getServiceIdFromNode($node, $scope), $lazyMap->getServiceIdFromNode($node, $scope));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)