LoggerDataCollectorTest.php 1.9 KB

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