class LoggerDataCollectorTest

Hierarchy

  • class \Symfony\Component\HttpKernel\Tests\DataCollector\LoggerDataCollectorTest extends \Symfony\Component\HttpKernel\Tests\DataCollector\PHPUnit_Framework_TestCase

Expanded class hierarchy of LoggerDataCollectorTest

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php, line 18

Namespace

Symfony\Component\HttpKernel\Tests\DataCollector
View source
class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase {
  protected function setUp() {
    if (!class_exists('Symfony\\Component\\HttpFoundation\\Request')) {
      $this
        ->markTestSkipped('The "HttpFoundation" component is not available');
    }
  }

  /**
   * @dataProvider getCollectTestData
   */
  public function testCollect($nb, $logs, $expected) {
    $logger = $this
      ->getMock('Symfony\\Component\\HttpKernel\\Log\\DebugLoggerInterface');
    $logger
      ->expects($this
      ->once())
      ->method('countErrors')
      ->will($this
      ->returnValue($nb));
    $logger
      ->expects($this
      ->once())
      ->method('getLogs')
      ->will($this
      ->returnValue($logs));
    $c = new LoggerDataCollector($logger);
    $c
      ->collect(new Request(), new Response());
    $this
      ->assertSame('logger', $c
      ->getName());
    $this
      ->assertSame($nb, $c
      ->countErrors());
    $this
      ->assertSame($expected ? $expected : $logs, $c
      ->getLogs());
  }
  public function getCollectTestData() {
    return array(
      array(
        1,
        array(
          array(
            'message' => 'foo',
            'context' => array(),
          ),
        ),
        null,
      ),
      array(
        1,
        array(
          array(
            'message' => 'foo',
            'context' => array(
              'foo' => fopen(__FILE__, 'r'),
            ),
          ),
        ),
        array(
          array(
            'message' => 'foo',
            'context' => array(
              'foo' => 'Resource(stream)',
            ),
          ),
        ),
      ),
      array(
        1,
        array(
          array(
            'message' => 'foo',
            'context' => array(
              'foo' => new \stdClass(),
            ),
          ),
        ),
        array(
          array(
            'message' => 'foo',
            'context' => array(
              'foo' => 'Object(stdClass)',
            ),
          ),
        ),
      ),
    );
  }

}

Members