getMockBuilder(InMemorySessionStore::class) ->disableOriginalConstructor() ->onlyMethods(['read']) ->getMock(); $store->expects($this->once())->method('read')->willReturn(json_encode(['foo' => 'bar'])); $session = new Session($store); $result = $session->all(); $this->assertEquals(['foo' => 'bar'], $result); // Call again to make sure we dont read from Store $result = $session->all(); $this->assertEquals(['foo' => 'bar'], $result); } public function testAllReturnsEmptyArrayForNullPayload() { $store = $this->getMockBuilder(InMemorySessionStore::class) ->disableOriginalConstructor() ->onlyMethods(['read']) ->getMock(); $store->expects($this->once())->method('read')->willReturn('null'); $session = new Session($store); $result = $session->all(); $this->assertSame([], $result); } }