Ejemplo n.º 1
0
 public function testRemovePlugin()
 {
     $this->_adapter->addPlugin($this->_plugin);
     $this->_adapter->removePlugin($this->_plugin);
     // no events should be attached
     $this->assertEquals(0, count($this->_adapter->events()->getEvents()));
 }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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));
 }