MemcacheAnyTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Stash package.
  4. *
  5. * (c) Robert Hafner <tedivm@tedivm.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Stash\Test\Driver;
  11. use Stash\Test\Stubs\PoolGetDriverStub;
  12. use Stash\Driver\Memcache;
  13. use Stash\Item;
  14. /**
  15. * @package Stash
  16. * @author Robert Hafner <tedivm@tedivm.com>
  17. */
  18. class MemcacheAnyTest extends \PHPUnit_Framework_TestCase
  19. {
  20. protected $driverClass = 'Stash\Driver\Memcache';
  21. protected $servers = array('127.0.0.1', '11211');
  22. protected function setUp()
  23. {
  24. $driverClass = $this->driverClass;
  25. if (!$driverClass::isAvailable()) {
  26. $this->markTestSkipped('Driver class unsuited for current environment');
  27. return;
  28. }
  29. if (!($sock = @fsockopen($this->servers[0], $this->servers[1], $errno, $errstr, 1))) {
  30. $this->markTestSkipped('Memcache tests require memcache server');
  31. return;
  32. }
  33. fclose($sock);
  34. }
  35. public function testConstruction()
  36. {
  37. $key = array('apple', 'sauce');
  38. $options = array();
  39. $options['servers'][] = array('127.0.0.1', '11211', '50');
  40. $driver = new Memcache($options);
  41. $item = new Item();
  42. $poolStub = new PoolGetDriverStub();
  43. $poolStub->setDriver($driver);
  44. $item->setPool($poolStub);
  45. $item->setKey($key);
  46. $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.');
  47. }
  48. }