Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit282eef4

Browse files
committed
Improve tests
1 parent6395a4c commit282eef4

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AttributeListenerPriorityTest.phprenamed 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
namespaceSymfony\Bundle\FrameworkBundle\Tests\Functional;
1313

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

19-
classAttributeListenerPriorityTestextends AbstractWebTestCase
22+
classCacheAttributeListenerTestextends AbstractWebTestCase
2023
{
2124
publicfunctiontestAnonimousUserWithEtag()
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
publicfunctiontestAnonimousUserWithoutEtag()
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
publicfunctiontestLoggedInUserWithEtag()
4043
{
41-
$client =self::createClient(['test_case' =>'AttributeListenerPriority']);
44+
$client =self::createClient(['test_case' =>'CacheAttributeListener']);
4245

4346
$client->loginUser(newInMemoryUser('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
publicfunctiontestLoggedInUserWithoutEtag()
5356
{
54-
$client =self::createClient(['test_case' =>'AttributeListenerPriority']);
57+
$client =self::createClient(['test_case' =>'CacheAttributeListener']);
5558

5659
$client->loginUser(newInMemoryUser('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 TestEntityValueResolverimplements ValueResolverInterface
70+
{
71+
publicfunctionresolve(Request$request,ArgumentMetadata$argument):iterable
72+
{
73+
return Post::class ===$argument->getType() ? [newPost()] : [];
74+
}
75+
}
76+
77+
class Post
78+
{
79+
publicfunctiongetId():int
80+
{
81+
return1;
82+
}
83+
84+
publicfunctiongetEtag():string
85+
{
86+
return'12345';
87+
}
88+
}
89+
6690
class WithAttributesController
6791
{
6892
#[IsGranted('ROLE_USER')]
69-
#[Cache(etag:'etag')]
70-
publicfunction__invoke():Response
93+
#[Cache(etag:'post.getEtag()')]
94+
publicfunction__invoke(Post$post):Response
7195
{
7296
returnnewResponse('Hi there!');
7397
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AttributeListenerPriority/config.ymlrenamed 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)

[8]ページ先頭

©2009-2025 Movatter.jp