Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/marc-mabe/zf2 into hotfix…
Browse files Browse the repository at this point in the history
…/cache-pattern-tests
  • Loading branch information
weierophinney committed Jan 9, 2012
2 parents a9cb316 + c8c146e commit a75171a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/Storage/Adapter/Memcached.php
Expand Up @@ -75,9 +75,11 @@ public function __construct($options = null)

parent::__construct($options);

// It's ok to add server as soon as possible because
// ext/memcached auto-connects to the server on first use
// TODO: Handle multiple servers
$options = $this->getOptions();
$this->memcached->addServer($options->getServer(), $options->getPort());

}

/* options */
Expand Down
26 changes: 14 additions & 12 deletions test/Pattern/CallbackCacheTest.php
Expand Up @@ -115,8 +115,6 @@ public function testMagicFunctionCall()

public function testCallWithPredefinedCallbackAndArgumentKey()
{
$this->markTestIncomplete();

$callback = __NAMESPACE__ . '\TestCallbackCache::emptyMethod';
$args = array('arg1', 2, 3.33, null);
$options = array(
Expand All @@ -125,26 +123,30 @@ public function testCallWithPredefinedCallbackAndArgumentKey()
);

$expectedKey = md5($options['callback_key'].$options['argument_key']);
$usedKey = null;
$this->_options->getStorage()->events()->attach('setItem.pre', function ($event) use (&$usedKey) {
$params = $event->getParams();
$usedKey = $params['key'];
});

$this->_pattern->call($callback, $args, $options);
$this->assertEquals(
$expectedKey,
$this->_storage->getLastKey() // get the last used key by storage
);
$this->assertEquals($expectedKey, $usedKey);
}

public function testGenerateKey()
{
$this->markTestIncomplete();

$callback = __NAMESPACE__ . '\TestCallbackCache::emptyMethod';
$args = array('arg1', 2, 3.33, null);

$generatedKey = $this->_pattern->generateKey($callback, $args);
$usedKey = null;
$this->_options->getStorage()->events()->attach('setItem.pre', function ($event) use (&$usedKey) {
$params = $event->getParams();
$usedKey = $params['key'];
});

$this->_pattern->call($callback, $args);
$this->assertEquals(
$this->_storage->getLastKey(), // get the last used key by storage
$this->_pattern->generateKey($callback, $args)
);
$this->assertEquals($generatedKey, $usedKey);
}

public function testGenerateKeyWithPredefinedCallbackAndArgumentKey()
Expand Down
15 changes: 9 additions & 6 deletions test/Pattern/ClassCacheTest.php
Expand Up @@ -98,14 +98,17 @@ public function testCallDisabledCacheOutput()

public function testGenerateKey()
{
$this->markTestIncomplete();

$args = array('arg1', 2, 3.33, null);

$generatedKey = $this->_pattern->generateKey('emptyMethod', $args);
$usedKey = null;
$this->_options->getStorage()->events()->attach('setItem.pre', function ($event) use (&$usedKey) {
$params = $event->getParams();
$usedKey = $params['key'];
});

$this->_pattern->call('emptyMethod', $args);
$this->assertEquals(
$this->_storage->getLastKey(), // get the last used key by storage
$this->_pattern->generateKey('emptyMethod', $args)
);
$this->assertEquals($generatedKey, $usedKey);
}

public function testCallUnknownMethodException()
Expand Down
15 changes: 9 additions & 6 deletions test/Pattern/ObjectCacheTest.php
Expand Up @@ -112,14 +112,17 @@ public function testCallInvoke()

public function testGenerateKey()
{
$this->markTestIncomplete();

$args = array('arg1', 2, 3.33, null);

$generatedKey = $this->_pattern->generateKey('emptyMethod', $args);
$usedKey = null;
$this->_options->getStorage()->events()->attach('setItem.pre', function ($event) use (&$usedKey) {
$params = $event->getParams();
$usedKey = $params['key'];
});

$this->_pattern->call('emptyMethod', $args);
$this->assertEquals(
$this->_storage->getLastKey(), // get the last used key by storage
$this->_pattern->generateKey('emptyMethod', $args)
);
$this->assertEquals($generatedKey, $usedKey);
}

public function testGenerateKeyWithPredefinedCallbackAndArgumentKey()
Expand Down

0 comments on commit a75171a

Please sign in to comment.