CacheTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\analysis\logger\adapter;
  9. use lithium\storage\Cache As CacheStorage;
  10. use lithium\analysis\Logger;
  11. use lithium\analysis\logger\adapter\Cache;
  12. /**
  13. * Tests the "Cache" logger adapter.
  14. */
  15. class CacheTest extends \lithium\test\Unit {
  16. /**
  17. * Sets up and configers the logger and also the cache storage for testing.
  18. */
  19. public function setUp() {
  20. CacheStorage::config(array(
  21. 'cachelog' => array(
  22. 'adapter' => 'Memory'
  23. )
  24. ));
  25. $this->cachelog = new Cache(array(
  26. 'key' => 'cachelog_testkey',
  27. 'config' => 'cachelog'
  28. ));
  29. Logger::config(array(
  30. 'cachelog' => array(
  31. 'adapter' => $this->cachelog,
  32. 'key' => 'cachelog_testkey',
  33. 'config' => 'cachelog'
  34. )
  35. ));
  36. }
  37. /**
  38. * Test the initialization of the cache log adapter.
  39. */
  40. public function testConstruct() {
  41. $expected = array(
  42. 'config' => "cachelog",
  43. 'expiry' => "+999 days",
  44. 'key' => "cachelog_testkey",
  45. 'init' => true
  46. );
  47. $result = $this->cachelog->_config;
  48. $this->assertEqual($expected, $result);
  49. }
  50. /**
  51. * Test if the configuration is correctly set in the logger.
  52. */
  53. public function testConfiguration() {
  54. $loggers = Logger::config();
  55. $result = isset($loggers['cachelog']);
  56. $this->assertTrue($result);
  57. }
  58. /**
  59. * Tests the correct writing to the cache adapter. In this test we use the
  60. * "Memory" cache adapter so that we can easily verify the written message.
  61. */
  62. public function testWrite() {
  63. $message = "CacheLog test message...";
  64. $result = Logger::write('info', $message, array('name' => 'cachelog'));
  65. $this->assertTrue($result);
  66. $result = CacheStorage::read('cachelog', 'cachelog_testkey');
  67. $this->assertEqual($message, $result);
  68. }
  69. }
  70. ?>