44
55use Behat \Behat \Context \Context ;
66use Compwright \PhpSession \Config ;
7- use Compwright \PhpSession \Handlers \Psr16Handler ;
8- use Compwright \PhpSession \Handlers \ScrapbookHandler ;
9- use Compwright \PhpSession \Handlers \FileHandler ;
10- use Compwright \PhpSession \Handlers \RedisHandler ;
117use Compwright \PhpSession \Manager ;
128use Compwright \PhpSession \Session ;
139use PHPUnit \Framework \Assert ;
1915 */
2016class PersistenceContext implements Context
2117{
18+ use GivenHandlerContextTrait;
19+
2220 private Config $ config ;
2321
2422 private Manager $ manager ;
@@ -27,48 +25,6 @@ class PersistenceContext implements Context
2725
2826 private string $ previousSessionId ;
2927
30- /**
31- * @Given session :handler stored at :location
32- */
33- public function sessionHandlerStoredAtLocation (string $ handler , string $ location ): void
34- {
35- if ($ handler !== 'redis ' ) {
36- $ location = sys_get_temp_dir () . DIRECTORY_SEPARATOR . trim ($ location );
37- if (!is_dir ($ location )) {
38- mkdir ($ location , 0777 , true );
39- }
40- }
41-
42- $ this ->config = new Config ();
43-
44- $ this ->config ->setSavePath ($ location );
45-
46- switch ($ handler ) {
47- case 'kodus ' :
48- $ cache = new \Kodus \Cache \FileCache ($ location , $ this ->config ->getGcMaxLifetime ());
49- $ handler = new Psr16Handler ($ this ->config , $ cache );
50- break ;
51- case 'scrapbook ' :
52- $ fs = new \League \Flysystem \Filesystem (
53- new \League \Flysystem \Local \LocalFilesystemAdapter ($ location , null , LOCK_EX )
54- );
55- $ cache = new \MatthiasMullie \Scrapbook \Adapters \Flysystem ($ fs );
56- $ handler = new ScrapbookHandler ($ this ->config , $ cache );
57- break ;
58- case 'redis ' :
59- $ this ->config ->setSavePath ('tcp://localhost:6379?database=0 ' );
60- $ handler = new RedisHandler ($ this ->config );
61- break ;
62- case 'file ' :
63- $ handler = new FileHandler ($ this ->config );
64- break ;
65- default :
66- throw new RuntimeException ('Not implemented: ' . $ handler );
67- }
68-
69- $ this ->config ->setSaveHandler ($ handler );
70- }
71-
7228 /**
7329 * @Then new session is started
7430 */
0 commit comments