forked from sofascore/purgatory-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInverseValuesBuildersTest.php
More file actions
79 lines (72 loc) · 3.63 KB
/
InverseValuesBuildersTest.php
File metadata and controls
79 lines (72 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace Sofascore\PurgatoryBundle\Tests\Cache\PropertyResolver;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\CompoundValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\DynamicValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\EnumValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\ExpressionValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\PropertyValues;
use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\RawValues;
use Sofascore\PurgatoryBundle\Cache\PropertyResolver\ExpressionLanguage\InverseRelationExpressionTransformer;
use Sofascore\PurgatoryBundle\Cache\PropertyResolver\InverseValuesBuilder\CompoundInverseValuesBuilder;
use Sofascore\PurgatoryBundle\Cache\PropertyResolver\InverseValuesBuilder\DynamicInverseValuesBuilder;
use Sofascore\PurgatoryBundle\Cache\PropertyResolver\InverseValuesBuilder\ExpressionInverseValuesBuilder;
use Sofascore\PurgatoryBundle\Cache\PropertyResolver\InverseValuesBuilder\PropertyInverseValuesBuilder;
use Sofascore\PurgatoryBundle\Tests\Fixtures\DummyIntEnum;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\PropertyInfo\PropertyReadInfo;
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
#[CoversClass(CompoundInverseValuesBuilder::class)]
#[CoversClass(DynamicInverseValuesBuilder::class)]
#[CoversClass(PropertyInverseValuesBuilder::class)]
final class InverseValuesBuildersTest extends TestCase
{
public function testBuild(): void
{
$extractor = self::createStub(PropertyReadInfoExtractorInterface::class);
$extractor->method('getReadInfo')
->with(\stdClass::class, 'association')
->willReturn(
new PropertyReadInfo(
type: PropertyReadInfo::TYPE_METHOD,
name: 'getAssociation',
visibility: PropertyReadInfo::VISIBILITY_PUBLIC,
static: false,
byRef: false,
),
);
$inverseValuesBuilder = new CompoundInverseValuesBuilder(new ServiceLocator([
DynamicValues::type() => static fn () => new DynamicInverseValuesBuilder(),
ExpressionValues::type() => static fn () => new ExpressionInverseValuesBuilder(
new InverseRelationExpressionTransformer($extractor),
),
PropertyValues::type() => static fn () => new PropertyInverseValuesBuilder(),
]));
$compoundValues = new CompoundValues(
new DynamicValues('alias'),
new DynamicValues('alias', propertyPath: 'obj'),
new EnumValues(DummyIntEnum::class),
new PropertyValues('obj'),
new RawValues(1, null, 'str'),
new ExpressionValues('obj.firstName~"-"~obj.lastName'),
);
self::assertEquals(
expected: new CompoundValues(
new DynamicValues('alias', propertyPath: 'association'),
new DynamicValues(
alias: 'alias',
propertyPath: 'association?.obj',
),
new EnumValues(DummyIntEnum::class),
new PropertyValues('association?.obj'),
new RawValues(1, null, 'str'),
new ExpressionValues(
'obj.getAssociation() !== null ? (obj.getAssociation().firstName~"-"~obj.getAssociation().lastName) : null',
),
),
actual: $inverseValuesBuilder->build($compoundValues, \stdClass::class, 'association'),
);
}
}