LoggerDataCollectorTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Tests\Component\HttpKernel\DataCollector;
  11. use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Tests\Component\HttpKernel\Logger;
  15. class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @dataProvider getCollectTestData
  19. */
  20. public function testCollect($nb, $logs, $expected)
  21. {
  22. $logger = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface');
  23. $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
  24. $logger->expects($this->once())->method('getLogs')->will($this->returnValue($logs));
  25. $c = new LoggerDataCollector($logger);
  26. $c->collect(new Request(), new Response());
  27. $this->assertSame('logger', $c->getName());
  28. $this->assertSame($nb, $c->countErrors());
  29. $this->assertSame($expected ? $expected : $logs, $c->getLogs());
  30. }
  31. public function getCollectTestData()
  32. {
  33. return array(
  34. array(
  35. 1,
  36. array(array('message' => 'foo', 'context' => array())),
  37. null,
  38. ),
  39. array(
  40. 1,
  41. array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))),
  42. array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))),
  43. ),
  44. array(
  45. 1,
  46. array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()))),
  47. array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'))),
  48. ),
  49. );
  50. }
  51. }