예제 #1
0
    protected function checkPreEventCanChangeArguments($method, array $args, array $expectedArgs)
    {
        $internalMethod = 'internal' . ucfirst($method);
        $eventName      = $method . '.pre';

        // init mock
        $this->_storage = $this->getMockForAbstractAdapter(array($internalMethod));
        $this->_storage->events()->attach($eventName, function ($event) use ($expectedArgs) {
            $params = $event->getParams();
            foreach ($expectedArgs as $k => $v) {
                $params[$k] = $v;
            }
        });

        // set expected arguments of internal method call
        $tmp = $this->_storage->expects($this->once())->method($internalMethod);
        $equals = array();
        foreach ($expectedArgs as $v) {
            $equals[] = $this->equalTo($v);
        }
        call_user_func_array(array($tmp, 'with'), $equals);

        // run
        call_user_func_array(array($this->_storage, $method), $args);
    }
예제 #2
0
 public function testGetMetadataCallsInternalGetMetadata()
 {
     $this->_storage = $this->getMockForAbstractAdapter(array('internalGetMetadata'));
     $options = array('ttl' => 123);
     $key = 'key1';
     $result = array();
     $this->_storage->expects($this->once())->method('internalGetMetadata')->with($this->equalTo($key), $this->equalTo($this->normalizeOptions($options)))->will($this->returnValue($result));
     $rs = $this->_storage->getMetadata($key, $options);
     $this->assertSame($result, $rs);
 }
예제 #3
0
 public function testRemoveItemsFail()
 {
     $options = array('ttl' => 123);
     $items = array('key1', 'key2', 'key3');
     $this->_storage->expects($this->at(0))->method('removeItem')->with($this->equalTo('key1'), $this->equalTo($options))->will($this->returnValue(true));
     $this->_storage->expects($this->at(1))->method('removeItem')->with($this->equalTo('key2'), $this->equalTo($options))->will($this->returnValue(false));
     // -> fail
     $this->_storage->expects($this->at(2))->method('removeItem')->with($this->equalTo('key3'), $this->equalTo($options))->will($this->returnValue(true));
     $this->assertFalse($this->_storage->removeItems($items, $options));
 }