8000 Improve tests · symfony/symfony@282eef4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 282eef4

Browse files
committed
Improve tests
1 parent 6395a4c commit 282eef4

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AttributeListenerPriorityTest.php renamed to src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CacheAttributeListenerTest.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,40 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Component\HttpFoundation\Request;
1415
use Symfony\Component\HttpFoundation\Response;
1516
use Symfony\Component\HttpKernel\Attribute\Cache;
17+
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
18+
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
1619
use Symfony\Component\Security\Core\User\InMemoryUser;
1720
use Symfony\Component\Security\Http\Attribute\IsGranted;
1821

19-
class AttributeListenerPriorityTest extends AbstractWebTestCase
22+
class CacheAttributeListenerTest extends AbstractWebTestCase
2023
{
2124
public function testAnonimousUserWithEtag()
2225
{
23-
$client = self::createClient(['test_case' => 'AttributeListenerPriority']);
26+
$client = self::createClient(['test_case' => 'CacheAttributeListener']);
2427

25-
$client->request('GET', '/12345', server: ['HTTP_IF_NONE_MATCH' => sprintf('"%s"', hash('sha256', '12345'))]);
28+
$client->request('GET', '/', server: ['HTTP_IF_NONE_MATCH' => sprintf('"%s"', hash('sha256', '12345'))]);
2629

2730
self::assertTrue($client->getResponse()->isRedirect('http://localhost/login'));
2831
}
2932

3033
public function testAnonimousUserWithoutEtag()
3134
{
32-
$client = self::createClient(['test_case' => 'AttributeListenerPriority']);
35+
$client = self::createClient(['test_case' => 'CacheAttributeListener']);
3336

34-
$client->request('GET', '/12345');
37+
$client->request('GET', '/');
3538

3639
self::assertTrue($client->getResponse()->isRedirect('http://localhost/login'));
3740
}
3841

3942
public function testLoggedInUserWithEtag()
4043
{
41-
$client = self::createClient(['test_case' => 'AttributeListenerPriority']);
44+
$client = self::createClient(['test_case' => 'CacheAttributeListener']);
4245

4346
$client->loginUser(new InMemoryUser('the-username', 'the-password', ['ROLE_USER']));
44-
$client->request('GET', '/12345', server: ['HTTP_IF_NONE_MATCH' => sprintf('"%s"', hash('sha256', '12345'))]);
47+
$client->request('GET', '/', server: ['HTTP_IF_NONE_MATCH' => sprintf('"%s"', hash('sha256', '12345'))]);
4548

4649
$response = $client->getResponse();
4750

@@ -51,10 +54,10 @@ public function testLoggedInUserWithEtag()
5154

5255
public function testLoggedInUserWithoutEtag()
5356
{
54-
$client = self::createClient(['test_case' => 'AttributeListenerPriority']);
57+
$client = self::createClient(['test_case' => 'CacheAttributeListener']);
5558

5659
$client->loginUser(new InMemoryUser('the-username', 'the-password', ['ROLE_USER']));
57-
$client->request('GET', '/12345');
60+
$client->request('GET', '/');
5861

5962
$response = $client->getResponse();
6063

@@ -63,11 +66,32 @@ public function testLoggedInUserWithoutEtag()
6366
}
6467
}
6568

69+
class TestEntityValueResolver implements ValueResolverInterface
70+
{
71+
public function resolve(Request $request, ArgumentMetadata $argument): iterable
72+
{
73+
return Post::class === $argument->getType() ? [new Post()] : [];
74+
}
75+
}
76+
77+
class Post
78+
{
79+
public function getId(): int
80+
{
81+
return 1;
82+
}
83+
84+
public function getEtag(): string
85+
{
86+
return '12345';
87+
}
88+
}
89+
6690
class WithAttributesController
6791
{
6892
#[IsGranted('ROLE_USER')]
69-
#[Cache(etag: 'etag')]
70-
public function __invoke(): Response
93+
#[Cache(etag: 'post.getEtag()')]
94+
public function __invoke(Post $post): Response
7195
{
7296
return new Response('Hi there!');
7397
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AttributeListenerPriority/config.yml renamed to src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CacheAttributeListener/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ imports:
22
- { resource: ../config/default.yml }
33

44
services:
5+
Symfony\Bundle\FrameworkBundle\Tests\Functional\TestEntityValueResolver:
6+
tags:
7+
- { name: controller.argument_value_resolver, priority: 110 }
8+
59
Symfony\Bundle\FrameworkBundle\Tests\Functional\WithAttributesController:
610
public: true
711

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
with_attributes_controller:
2-
path: /{etag}
2+
path: /
33
controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\WithAttributesController

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"symfony/error-handler": "^6.1",
2727
"symfony/event-dispatcher": "^5.4|^6.0",
2828
"symfony/http-foundation": "^6.2",
29-
"symfony/http-kernel": "^6.2",
29+
"symfony/http-kernel": "^6.2.1",
3030
"symfony/polyfill-mbstring": "~1.0",
3131
"symfony/filesystem": "^5.4|^6.0",
3232
"symfony/finder": "^5.4|^6.0",

0 commit comments

Comments
 (0)
0