Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#963 MemcachedStorage Notice if deamon is not running, incl. test #980

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Nette/Caching/Storages/MemcachedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public function addServer($host = 'localhost', $port = 11211, $timeout = 1)
$error = error_get_last();
throw new Nette\InvalidStateException("Memcache::addServer(): $error[message].");
}

$stats = @$this->memcache->getExtendedStats();
$status = (bool) $stats["$host:$port"];
if ($status === FALSE) {
$error = error_get_last();
throw new Nette\InvalidStateException("Memcache::addServer(): $error[message].");
}
}


Expand Down
30 changes: 30 additions & 0 deletions tests/Nette/Caching/Memcached.addServer.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Test: Nette\Caching\Storages\MemcachedStorage connection status test.
*
* @author Patrik Šíma
* @package Nette\Caching
*/

use Nette\Caching\Storages\MemcachedStorage,
Nette\Caching\Storages\FileJournal,
Nette\Caching\Cache;



require __DIR__ . '/../bootstrap.php';


if (!MemcachedStorage::isAvailable()) {
Tester\Helpers::skip('Requires PHP extension Memcache.');
}


try {
$cache = new Cache(new MemcachedStorage('localhost', 11666)); // assume that on this port by default is not running
Assert::fail('Expected exception');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an Assert::exception() for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. That's exactly what I was looking for. This code I copied from other tests. Btw. Is there any help for Nette/Tester?

} catch (Exception $e) {
Assert::true($e instanceof Nette\InvalidStateException);
Assert::contains("Memcache::addServer()", $e->getMessage());
}