File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
MakeAuthenticatorLoginFormUserEntityLogout/tests
MakeAuthenticatorLoginFormUserEntity/tests
MakeAuthenticatorSecurity52LoginForm/tests Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 6
6
use App \Security \AppCustomAuthenticator ;
7
7
use Doctrine \ORM \EntityManagerInterface ;
8
8
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
9
+ use Symfony \Component \HttpKernel \Kernel ;
9
10
10
11
class SecurityControllerTest extends WebTestCase
11
12
{
@@ -60,7 +61,17 @@ public function testCommand()
60
61
$ client ->submit ($ form );
61
62
62
63
$ this ->assertStringContainsString ('TODO: provide a valid redirect ' , $ client ->getResponse ()->getContent ());
63
- $ this ->assertNotNull ($ token = $ client ->getContainer ()->get ('security.token_storage ' )->getToken ());
64
+
65
+ $ tokenStorage = static ::$ container ->get ('security.token_storage ' );
66
+
67
+ // Handle Session deprecations in Symfony 5.3+
68
+ if (Kernel::VERSION_ID >= 50300 ) {
69
+ $ tokenStorage ->disableUsageTracking ();
70
+ }
71
+
72
+ $ token = $ tokenStorage ->getToken ();
73
+
74
+ self ::assertNotNull ($ token );
64
75
$ this ->assertInstanceOf (User::class, $ token ->getUser ());
65
76
}
66
77
}
Original file line number Diff line number Diff line change 6
6
use App \Security \AppCustomAuthenticator ;
7
7
use Doctrine \ORM \EntityManagerInterface ;
8
8
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
9
+ use Symfony \Component \HttpKernel \Kernel ;
10
+ use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
9
11
10
12
class SecurityControllerTest extends WebTestCase
11
13
{
@@ -60,10 +62,23 @@ public function testCommand()
60
62
$ client ->submit ($ form );
61
63
62
64
$ this ->assertStringContainsString ('TODO: provide a valid redirect ' , $ client ->getResponse ()->getContent ());
63
- $ this ->assertNotNull ($ token = $ client ->getContainer ()->get ('security.token_storage ' )->getToken ());
64
- $ this ->assertInstanceOf (User::class, $ token ->getUser ());
65
+ $ this ->assertInstanceOf (User::class, $ this ->getToken ()->getUser ());
65
66
66
67
$ client ->request ('GET ' , '/logout ' );
67
- $ this ->assertNull ($ client ->getContainer ()->get ('security.token_storage ' )->getToken ());
68
+ $ this ->assertNull ($ this ->getToken ());
69
+ }
70
+
71
+ /**
72
+ * Handle Session deprecations in Symfony 5.3+
73
+ */
74
+ private function getToken (): ?TokenInterface
75
+ {
76
+ $ tokenStorage = static ::$ container ->get ('security.token_storage ' );
77
+
78
+ if (Kernel::VERSION_ID >= 50300 ) {
79
+ $ tokenStorage ->disableUsageTracking ();
80
+ }
81
+
82
+ return $ tokenStorage ->getToken ();
68
83
}
69
84
}
Original file line number Diff line number Diff line change 6
6
use App \Security \AppTestSecurity52LoginFormAuthenticator ;
7
7
use Doctrine \ORM \EntityManagerInterface ;
8
8
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
9
+ use Symfony \Component \HttpKernel \Kernel ;
9
10
use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
10
11
11
12
/**
@@ -68,7 +69,17 @@ public function testLoginFormAuthenticatorUsingSecurity51(): void
68
69
$ client ->submit ($ form );
69
70
70
71
self ::assertStringContainsString ('TODO: provide a valid redirect ' , $ client ->getResponse ()->getContent ());
71
- self ::assertNotNull ($ token = $ client ->getContainer ()->get ('security.token_storage ' )->getToken ());
72
+
73
+ $ tokenStorage = static ::$ container ->get ('security.token_storage ' );
74
+
75
+ // Handle Session deprecations in Symfony 5.3+
76
+ if (Kernel::VERSION_ID >= 50300 ) {
77
+ $ tokenStorage ->disableUsageTracking ();
78
+ }
79
+
80
+ $ token = $ tokenStorage ->getToken ();
81
+
82
+ self ::assertNotNull ($ token );
72
83
self ::assertInstanceOf (User::class, $ token ->getUser ());
73
84
}
74
85
}
You can’t perform that action at this time.
0 commit comments