CacheExceptionTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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;
  11. use Stash\Test\Stubs\DriverExceptionStub;
  12. use Stash\Test\Stubs\PoolGetDriverStub;
  13. use Stash\Pool;
  14. use Stash\Item;
  15. /**
  16. * @package Stash
  17. * @author Robert Hafner <tedivm@tedivm.com>
  18. */
  19. class CacheExceptionTest extends \PHPUnit_Framework_TestCase
  20. {
  21. public function testSet()
  22. {
  23. $item = new Item();
  24. $poolStub = new PoolGetDriverStub();
  25. $poolStub->setDriver(new DriverExceptionStub());
  26. $item->setPool($poolStub);
  27. $item->setKey(array('path', 'to', 'store'));
  28. $this->assertFalse($item->isDisabled());
  29. $this->assertFalse($item->set(array(1, 2, 3), 3600)->save());
  30. $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
  31. }
  32. public function testGet()
  33. {
  34. $item = new Item();
  35. $poolStub = new PoolGetDriverStub();
  36. $poolStub->setDriver(new DriverExceptionStub());
  37. $item->setPool($poolStub);
  38. $item->setKey(array('path', 'to', 'get'));
  39. $this->assertFalse($item->isDisabled());
  40. $this->assertNull($item->get());
  41. $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
  42. }
  43. public function testClear()
  44. {
  45. $item = new Item();
  46. $poolStub = new PoolGetDriverStub();
  47. $poolStub->setDriver(new DriverExceptionStub());
  48. $item->setPool($poolStub);
  49. $item->setKey(array('path', 'to', 'clear'));
  50. $this->assertFalse($item->isDisabled());
  51. $this->assertFalse($item->clear());
  52. $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
  53. }
  54. public function testPurge()
  55. {
  56. $pool = new Pool();
  57. $pool->setDriver(new DriverExceptionStub());
  58. $item = $pool->getItem('test');
  59. $this->assertFalse($item->isDisabled());
  60. $this->assertFalse($pool->purge());
  61. $item = $pool->getItem('test');
  62. $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
  63. $this->assertFalse($pool->purge());
  64. }
  65. public function testPoolClear()
  66. {
  67. $pool = new Pool();
  68. $pool->setDriver(new DriverExceptionStub());
  69. $item = $pool->getItem('test');
  70. $this->assertFalse($item->isDisabled());
  71. $this->assertFalse($pool->clear());
  72. $item = $pool->getItem('test');
  73. $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
  74. $this->assertFalse($pool->clear());
  75. }
  76. }