TestCase.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Test;
  11. use Monolog\Logger;
  12. use Monolog\DateTimeImmutable;
  13. use Monolog\Formatter\FormatterInterface;
  14. /**
  15. * Lets you easily generate log records and a dummy formatter for testing purposes
  16. * *
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class TestCase extends \PHPUnit\Framework\TestCase
  20. {
  21. /**
  22. * @return array Record
  23. */
  24. protected function getRecord($level = Logger::WARNING, $message = 'test', $context = [])
  25. {
  26. return [
  27. 'message' => $message,
  28. 'context' => $context,
  29. 'level' => $level,
  30. 'level_name' => Logger::getLevelName($level),
  31. 'channel' => 'test',
  32. 'datetime' => new DateTimeImmutable(true),
  33. 'extra' => [],
  34. ];
  35. }
  36. /**
  37. * @return array
  38. */
  39. protected function getMultipleRecords()
  40. {
  41. return [
  42. $this->getRecord(Logger::DEBUG, 'debug message 1'),
  43. $this->getRecord(Logger::DEBUG, 'debug message 2'),
  44. $this->getRecord(Logger::INFO, 'information'),
  45. $this->getRecord(Logger::WARNING, 'warning'),
  46. $this->getRecord(Logger::ERROR, 'error'),
  47. ];
  48. }
  49. protected function getIdentityFormatter(): FormatterInterface
  50. {
  51. $formatter = $this->createMock(FormatterInterface::class);
  52. $formatter->expects($this->any())
  53. ->method('format')
  54. ->will($this->returnCallback(function ($record) {
  55. return $record['message'];
  56. }));
  57. return $formatter;
  58. }
  59. }