public function testInternalGetItemsCallsInternalGetItemForEachKey() { $this->markTestSkipped( "This test doesn't work because of an issue with PHPUnit: " . 'https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81' ); $this->_storage = $this->getMockForAbstractAdapter(array('internalGetItem')); $items = array('key1' => 'value1', 'notFound' => false, 'key2' => 'value2'); $result = array('key1' => 'value1', 'key2' => 'value2'); $i = 0; // method call counter foreach ($items as $k => $v) { $this->_storage->expects($this->at($i++)) ->method('internalGetItem') ->with( $this->equalTo($k), $this->equalTo(null), $this->equalTo(null) ) ->will($this->returnCallback(function ($k, & $success, & $casToken) use ($items) { if ($items[$k]) { $success = true; return $items[$k]; } else { $success = false; return null; } })); } $rs = $this->_storage->getItems(array_keys($items), $options); $this->assertEquals($result, $rs); }
public function testInternalGetItemsCallsInternalGetItemForEachKey() { $this->_storage = $this->getMockForAbstractAdapter(array('internalGetItem')); $options = array('ttl' => 123); $items = array('key1' => 'value1', 'notFound' => false, 'key2' => 'value2'); $result = array('key1' => 'value1', 'key2' => 'value2'); $normalizedOptions = $this->normalizeOptions($options); $normalizedOptions['ignore_missing_items'] = false; $i = 0; // method call counter foreach ($items as $k => $v) { $this->_storage->expects($this->at($i++))->method('internalGetItem')->with($this->equalTo($k), $this->equalTo($normalizedOptions))->will($v ? $this->returnValue($v) : $this->throwException(new Exception\ItemNotFoundException())); } $rs = $this->_storage->getItems(array_keys($items), $options); $this->assertEquals($result, $rs); }
public function testGetItems() { $options = array('ttl' => 123); $items = array('key1' => 'value1', 'dKey1' => false, 'key2' => 'value2'); $i = 0; foreach ($items as $k => $v) { $this->_storage->expects($this->at($i++))->method('getItem')->with($this->equalTo($k), $this->equalTo($options))->will($this->returnValue($v)); } $rs = $this->_storage->getItems(array_keys($items), $options); // remove missing items from array to test $expected = $items; foreach ($expected as $key => $value) { if (false === $value) { unset($expected[$key]); } } $this->assertEquals($expected, $rs); }