Skip to content

Commit

Permalink
Improving the code coverage for log adapter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrainbow committed Jul 24, 2012
1 parent 100e8e2 commit e2378c7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/Presque/Log/ClosureLogAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ class ClosureLogAdapter implements LoggerInterface
{
protected $log;

public function __construct(\Closure $log = null)
public function __construct($log = null)
{
if (null !== $log && !is_callable($log)) {
throw new \InvalidArgumentException(
'The ClosureLogAdapter must be provided a valid callable.'
);
}

$this->log = $log;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/Presque/Tests/Log/AbstractLogAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Presque package.
*
* (c) Justin Rainbow <justin.rainbow@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Presque\Tests;

use Presque\Tests\TestCase;

abstract class AbstractLogAdapterTest extends TestCase
{
public function getLogLevels()
{
return array(
array('debug'),
array('info'),
array('warn'),
array('err'),
array('crit'),
array('emerg'),
array('notice'),
array('alert'),
);
}
}
36 changes: 36 additions & 0 deletions tests/Presque/Tests/Log/ClosureLogAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Presque package.
*
* (c) Justin Rainbow <justin.rainbow@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Presque\Tests;

use Presque\Tests\TestCase;
use Presque\Log\ClosureLogAdapter;
use Monolog\Logger;

class ClosureLogAdapterTest extends AbstractLogAdapterTest
{
protected $logger;
protected $adapter;

/**
* @dataProvider getLogLevels
*/
public function testLoggingMessages($level)
{
$test = $this;
$adapter = new ClosureLogAdapter(function ($message, $type) use (&$test, $level) {
$test->assertEquals("My message", $message);
$test->assertEquals($level, $type);
});

$adapter->{$level}("My message");
}
}
14 changes: 1 addition & 13 deletions tests/Presque/Tests/Log/MonologLogAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Presque\Log\MonologLogAdapter;
use Monolog\Logger;

class MonologLogAdapterTest extends TestCase
class MonologLogAdapterTest extends AbstractLogAdapterTest
{
protected $logger;
protected $adapter;
Expand All @@ -33,18 +33,6 @@ public function testLoggingMessages($level)
$this->adapter->{$level}("My message");
}

public function getLogLevels()
{
return array(
array('debug'),
array('info'),
array('warn'),
array('err'),
array('crit'),
array('emerg'),
);
}

protected function setUp()
{
$this->logger = $this->createMonologMock();
Expand Down

0 comments on commit e2378c7

Please sign in to comment.