PsrLogMessageProcessorTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php declare(strict_types=1);
  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\Processor;
  11. class PsrLogMessageProcessorTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @dataProvider getPairs
  15. */
  16. public function testReplacement($val, $expected)
  17. {
  18. $proc = new PsrLogMessageProcessor;
  19. $message = $proc([
  20. 'message' => '{foo}',
  21. 'context' => ['foo' => $val],
  22. ]);
  23. $this->assertEquals($expected, $message['message']);
  24. }
  25. public function testCustomDateFormat()
  26. {
  27. $format = "Y-m-d";
  28. $date = new \DateTime();
  29. $proc = new PsrLogMessageProcessor($format);
  30. $message = $proc([
  31. 'message' => '{foo}',
  32. 'context' => ['foo' => $date],
  33. ]);
  34. $this->assertEquals($date->format($format), $message['message']);
  35. }
  36. public function getPairs()
  37. {
  38. $date = new \DateTime();
  39. return [
  40. ['foo', 'foo'],
  41. ['3', '3'],
  42. [3, '3'],
  43. [null, ''],
  44. [true, '1'],
  45. [false, ''],
  46. [$date, $date->format(PsrLogMessageProcessor::SIMPLE_DATE)],
  47. [new \stdClass, '[object stdClass]'],
  48. [[], '[array]'],
  49. ];
  50. }
  51. }