LoggerDataCollectorTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\HttpKernel\Tests\DataCollector;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
  13. class LoggerDataCollectorTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider getCollectTestData
  17. */
  18. public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
  19. {
  20. $logger = $this->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')->getMock();
  21. $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
  22. $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
  23. $c = new LoggerDataCollector($logger);
  24. $c->lateCollect();
  25. $this->assertSame('logger', $c->getName());
  26. $this->assertSame($nb, $c->countErrors());
  27. $this->assertSame($expectedLogs ?: $logs, $c->getLogs());
  28. $this->assertSame($expectedDeprecationCount, $c->countDeprecations());
  29. $this->assertSame($expectedScreamCount, $c->countScreams());
  30. if (isset($expectedPriorities)) {
  31. $this->assertSame($expectedPriorities, $c->getPriorities());
  32. }
  33. }
  34. public function getCollectTestData()
  35. {
  36. return array(
  37. array(
  38. 1,
  39. array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
  40. null,
  41. 0,
  42. 0,
  43. ),
  44. array(
  45. 1,
  46. array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
  47. array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
  48. 0,
  49. 0,
  50. ),
  51. array(
  52. 1,
  53. array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()), 'priority' => 100, 'priorityName' => 'DEBUG')),
  54. array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
  55. 0,
  56. 0,
  57. ),
  58. array(
  59. 1,
  60. array(
  61. array('message' => 'foo', 'context' => array('type' => E_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
  62. array('message' => 'foo2', 'context' => array('type' => E_USER_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
  63. ),
  64. null,
  65. 2,
  66. 0,
  67. array(100 => array('count' => 2, 'name' => 'DEBUG')),
  68. ),
  69. array(
  70. 1,
  71. array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG')),
  72. array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123, 'scream' => true), 'priority' => 100, 'priorityName' => 'DEBUG')),
  73. 0,
  74. 1,
  75. ),
  76. array(
  77. 1,
  78. array(
  79. array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => 0, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
  80. array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123), 'priority' => 100, 'priorityName' => 'DEBUG'),
  81. ),
  82. array(array('message' => 'foo3', 'context' => array('name' => 'E_USER_WARNING', 'type' => E_USER_WARNING, 'level' => -1, 'file' => __FILE__, 'line' => 123, 'errorCount' => 2), 'priority' => 100, 'priorityName' => 'DEBUG')),
  83. 0,
  84. 1,
  85. ),
  86. );
  87. }
  88. }