forked from sofascore/purgatory-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForGroupsResolverTest.php
More file actions
76 lines (61 loc) · 2.86 KB
/
ForGroupsResolverTest.php
File metadata and controls
76 lines (61 loc) · 2.86 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
<?php
declare(strict_types=1);
namespace Sofascore\PurgatoryBundle\Tests\Cache\TargetResolver;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Sofascore\PurgatoryBundle\Attribute\PurgeOn;
use Sofascore\PurgatoryBundle\Attribute\Target\ForGroups;
use Sofascore\PurgatoryBundle\Cache\RouteMetadata\RouteMetadata;
use Sofascore\PurgatoryBundle\Cache\TargetResolver\ForGroupsResolver;
use Sofascore\PurgatoryBundle\Exception\LogicException;
use Sofascore\PurgatoryBundle\Exception\RuntimeException;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\Routing\Route;
#[CoversClass(ForGroupsResolver::class)]
final class ForGroupsResolverTest extends TestCase
{
public function testResolve(): void
{
$propertyListExtractor = $this->createMock(PropertyListExtractorInterface::class);
$propertyListExtractor->expects(self::once())
->method('getProperties')
->with('FooEntity', ['serializer_groups' => ['group1']])
->willReturn(['property1', 'property2']);
$resolver = new ForGroupsResolver($propertyListExtractor);
$routeMetadata = new RouteMetadata(
routeName: 'route_foo',
route: new Route('/foo'),
purgeOn: new PurgeOn(
class: 'FooEntity',
target: $target = new ForGroups(['group1']),
),
reflectionMethod: self::createStub(\ReflectionMethod::class),
);
$resolved = $resolver->resolve($target, $routeMetadata);
self::assertSame(['property1', 'property2'], $resolved);
}
public function testExceptionIsThrownWhenPropertiesCannotBeResolved(): void
{
$propertyListExtractor = self::createStub(PropertyListExtractorInterface::class);
$propertyListExtractor->method('getProperties')->willReturn(null);
$resolver = new ForGroupsResolver($propertyListExtractor);
$routeMetadata = new RouteMetadata(
routeName: 'route_foo',
route: new Route('/foo'),
purgeOn: new PurgeOn(
class: 'FooEntity',
target: $target = new ForGroups(['group1']),
),
reflectionMethod: self::createStub(\ReflectionMethod::class),
);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Could not resolve properties for groups "group1" in class "FooEntity".');
$resolver->resolve($target, $routeMetadata);
}
public function testExceptionIsThrownWhenSerializerExtractorIsNotAvailable(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('You cannot use the "ForGroups" attribute because the Symfony Serializer component is not installed. Try running "composer require symfony/serializer".');
new ForGroupsResolver(null);
}
}