LogTraitTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Log;
  16. use Cake\Log\Log;
  17. use Cake\Log\LogTrait;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for LogTrait
  21. */
  22. class LogTraitTest extends TestCase
  23. {
  24. public function tearDown(): void
  25. {
  26. parent::tearDown();
  27. Log::drop('trait_test');
  28. }
  29. /**
  30. * Test log method.
  31. */
  32. public function testLog(): void
  33. {
  34. $mock = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  35. $mock->expects($this->exactly(2))
  36. ->method('log')
  37. ->with(
  38. ...self::withConsecutive(
  39. ['error', 'Testing'],
  40. ['debug', 'message']
  41. )
  42. );
  43. Log::setConfig('trait_test', ['engine' => $mock]);
  44. $subject = new class {
  45. use LogTrait;
  46. };
  47. $subject->log('Testing');
  48. $subject->log('message', 'debug');
  49. }
  50. }