Skip to content
Permalink
Browse files

Use mocks to make test a bit more durable.

  • Loading branch information...
markstory committed Oct 7, 2012
1 parent 44714fe commit dcbc1830ce0a2ee722d5355c3cd245fbf37e08d3
Showing with 23 additions and 11 deletions.
  1. +23 −11 lib/Cake/Test/TestCase/Utility/DebuggerTest.php
@@ -12,8 +12,10 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Test\TestCase\Utility;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\TestSuite\TestCase;
use Cake\Utility\Debugger;
use Cake\View\View;
@@ -397,20 +399,30 @@ public function testExportVar() {
* @return void
*/
public function testLog() {
$this->skipIf(!is_writable(LOGS), 'Cannot write to logs dir');
$mock = $this->getMock('Cake\Log\Engine\BaseLog', ['write']);
Log::engine('test', $mock);
$mock->expects($this->at(0))
->method('write')
->with('debug', $this->logicalAnd(
$this->stringContains('DebuggerTest::testLog'),
$this->stringContains('cool')
));
$mock->expects($this->at(1))
->method('write')
->with('debug', $this->logicalAnd(
$this->stringContains('DebuggerTest::testLog'),
$this->stringContains('[main]'),
$this->stringContains('array'),
$this->stringContains("'whatever',"),
$this->stringContains("'here'")
));
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertContains('DebuggerTest::testLog', $result);
$this->assertContains("'cool'", $result);
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(LOGS . 'debug.log');
$this->assertContains('DebuggerTest::testLog', $result);
$this->assertContains('[main]', $result);
$this->assertContains('array', $result);
$this->assertContains("'whatever',", $result);
$this->assertContains("'here'", $result);
Log::drop('test');
}
/**

0 comments on commit dcbc183

Please sign in to comment.
You can’t perform that action at this time.