StreamHandlerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Logger;
  12. class StreamHandlerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testWrite()
  15. {
  16. $handle = fopen('php://memory', 'a+');
  17. $handler = new StreamHandler($handle);
  18. $handler->write(array('message' => 'test'));
  19. $handler->write(array('message' => 'test2'));
  20. $handler->write(array('message' => 'test3'));
  21. fseek($handle, 0);
  22. $this->assertEquals('testtest2test3', fread($handle, 100));
  23. }
  24. public function testClose()
  25. {
  26. $handle = fopen('php://memory', 'a+');
  27. $handler = new StreamHandler($handle);
  28. $this->assertTrue(is_resource($handle));
  29. $handler->close();
  30. $this->assertFalse(is_resource($handle));
  31. }
  32. public function testWriteCreatesTheStreamResource()
  33. {
  34. $handler = new StreamHandler('php://memory');
  35. $handler->write(array('message' => 'test'));
  36. }
  37. /**
  38. * @expectedException LogicException
  39. */
  40. public function testWriteMissingResource()
  41. {
  42. $handler = new StreamHandler(null);
  43. $handler->write(array('message' => 'test'));
  44. }
  45. /**
  46. * @expectedException UnexpectedValueException
  47. */
  48. public function testWriteInvalidResource()
  49. {
  50. $handler = new StreamHandler('bogus://url');
  51. @$handler->write(array('message' => 'test'));
  52. }
  53. }