eZ\Publish\Core\Persistence\Cache\Tests\ObjectStateHandlerTest::testLoadObjectStatesCached PHP Method

testLoadObjectStatesCached() public method

    public function testLoadObjectStatesCached()
    {
        $testStates = array(new SPIObjectState(array('id' => 1, 'identifier' => 'test_state_1_group1', 'groupId' => 1)), new SPIObjectState(array('id' => 2, 'identifier' => 'test_state_2_group1', 'groupId' => 1)), new SPIObjectState(array('id' => 3, 'identifier' => 'test_state_3_group1', 'groupId' => 1)));
        $testStateIds = array_map(function ($state) {
            return $state->id;
        }, $testStates);
        $cacheItemMock = $this->getMock('Stash\\Interfaces\\ItemInterface');
        $this->cacheMock->expects($this->at(0))->method('getItem')->with('objectstate', 'byGroup', 1)->will($this->returnValue($cacheItemMock));
        $cacheItemMock->expects($this->once())->method('get')->will($this->returnValue($testStateIds));
        $cacheItemMock->expects($this->once())->method('isMiss')->will($this->returnValue(false));
        // load()
        foreach ($testStates as $i => $state) {
            $this->cacheMock->expects($this->at($i + 1))->method('getItem')->with('objectstate', $state->id)->will($this->returnCallback(function ($cachekey, $i) use($state) {
                $cacheItemMock = $this->getMock('Stash\\Interfaces\\ItemInterface');
                $cacheItemMock->expects($this->once())->method('get')->will($this->returnValue($state));
                return $cacheItemMock;
            }));
        }
        $handler = $this->persistenceCacheHandler->objectStateHandler();
        $states = $handler->loadObjectStates(1);
        $this->assertEquals($states, $testStates);
    }