*/ protected $user; /** * setup */ public function setUp(): void { parent::setUp(); $this->session = $this->getMockBuilder(Session::class)->getMock(); $request = new ServerRequest(['session' => $this->session]); $response = new Response(); $this->storage = new SessionStorage($request, $response, ['key' => 'Auth.AuthUser']); $this->user = ['id' => 1]; } /** * Test write */ public function testWrite(): void { $this->session->expects($this->once()) ->method('write') ->with('Auth.AuthUser', $this->user) ->will($this->returnValue(true)); $this->storage->write($this->user); } /** * Test read */ public function testRead(): void { $this->session->expects($this->once()) ->method('read') ->with('Auth.AuthUser') ->will($this->returnValue($this->user)); $result = $this->storage->read(); $this->assertSame($this->user, $result); } /** * Test read from local var */ public function testGetFromLocalVar(): void { $this->storage->write($this->user); $this->session->expects($this->never()) ->method('read'); $result = $this->storage->read(); $this->assertSame($this->user, $result); } /** * Test delete */ public function testDelete(): void { $this->session->expects($this->once()) ->method('delete') ->with('Auth.AuthUser'); $this->storage->delete(); } /** * Test redirectUrl() */ public function redirectUrl(): void { $url = '/url'; $this->session->expects($this->once()) ->method('write') ->with('Auth.redirectUrl', $url); $this->storage->redirectUrl($url); $this->session->expects($this->once()) ->method('read') ->with('Auth.redirectUrl') ->will($this->returnValue($url)); $result = $this->storage->redirectUrl(); $this->assertSame($url, $result); $this->session->expects($this->once()) ->method('delete') ->with('Auth.redirectUrl'); $this->storage->redirectUrl(false); } }