StreamHandlerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  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 Monolog\Handler;
  11. use Monolog\TestCase;
  12. use Monolog\Logger;
  13. class StreamHandlerTest extends TestCase
  14. {
  15. public function testHandle()
  16. {
  17. $handle = fopen('php://memory', 'a+');
  18. $handler = new StreamHandler($handle);
  19. $handler->setFormatter($this->getIdentityFormatter());
  20. $handler->handle($this->getRecord(Logger::WARNING, 'test'));
  21. $handler->handle($this->getRecord(Logger::WARNING, 'test2'));
  22. $handler->handle($this->getRecord(Logger::WARNING, 'test3'));
  23. fseek($handle, 0);
  24. $this->assertEquals('testtest2test3', fread($handle, 100));
  25. }
  26. public function testClose()
  27. {
  28. $handle = fopen('php://memory', 'a+');
  29. $handler = new StreamHandler($handle);
  30. $this->assertTrue(is_resource($handle));
  31. $handler->close();
  32. $this->assertFalse(is_resource($handle));
  33. }
  34. public function testHandleCreatesTheStreamResource()
  35. {
  36. $handler = new StreamHandler('php://memory');
  37. $handler->handle($this->getRecord());
  38. }
  39. /**
  40. * @expectedException LogicException
  41. */
  42. public function testHandleMissingResource()
  43. {
  44. $handler = new StreamHandler(null);
  45. $handler->handle($this->getRecord());
  46. }
  47. /**
  48. * @expectedException UnexpectedValueException
  49. */
  50. public function testHandleInvalidResource()
  51. {
  52. $handler = new StreamHandler('bogus://url');
  53. $handler->handle($this->getRecord());
  54. }
  55. }