Permalink
Browse files

Added tests for ChromePhp

  • Loading branch information...
1 parent d9a0854 commit cc795d5a41156b0ad6c3c06c48e2c84830fb5fb3 @waltertamboer waltertamboer committed Aug 2, 2012
Showing with 137 additions and 0 deletions.
  1. +46 −0 tests/Zend/Log/TestAsset/MockChromePhp.php
  2. +91 −0 tests/Zend/Log/Writer/ChromePhpTest.php
View
46 tests/Zend/Log/TestAsset/MockChromePhp.php
@@ -0,0 +1,46 @@
+<?php
+namespace ZendTest\Log\TestAsset;
+
+use Zend\Log\Writer\FirePhp\FirePhpInterface;
+
+class MockFirePhp implements FirePhpInterface
+{
+ public $calls = array();
+
+ protected $enabled;
+
+ public function __construct($enabled = true)
+ {
+ $this->enabled = $enabled;
+ }
+
+ public function getEnabled()
+ {
+ return $this->enabled;
+ }
+
+ public function error($line)
+ {
+ $this->calls['error'][] = $line;
+ }
+
+ public function warn($line)
+ {
+ $this->calls['warn'][] = $line;
+ }
+
+ public function info($line)
+ {
+ $this->calls['info'][] = $line;
+ }
+
+ public function trace($line)
+ {
+ $this->calls['trace'][] = $line;
+ }
+
+ public function log($line)
+ {
+ $this->calls['log'][] = $line;
+ }
+}
View
91 tests/Zend/Log/Writer/ChromePhpTest.php
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace ZendTest\Log\Writer;
+
+use ZendTest\Log\TestAsset\MockFirePhp;
+use Zend\Log\Writer\FirePhp;
+use Zend\Log\Writer\FirePhp\FirePhpInterface;
+use Zend\Log\Logger;
+
+/**
+ * @category Zend
+ * @package Zend_Log
+ * @subpackage UnitTests
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @group Zend_Log
+ */
+class FirePhpTest extends \PHPUnit_Framework_TestCase
+{
+ protected $firephp;
+
+ public function setUp()
+ {
+ $this->firephp = new MockFirePhp();
+
+ }
+ /**
+ * Test get FirePhp
+ */
+ public function testGetFirePhp()
+ {
+ $writer = new FirePhp($this->firephp);
+ $this->assertTrue($writer->getFirePhp() instanceof FirePhpInterface);
+ }
+ /**
+ * Test set firephp
+ */
+ public function testSetFirePhp()
+ {
+ $writer = new FirePhp($this->firephp);
+ $firephp2 = new MockFirePhp();
+
+ $writer->setFirePhp($firephp2);
+ $this->assertTrue($writer->getFirePhp() instanceof FirePhpInterface);
+ $this->assertEquals($firephp2, $writer->getFirePhp());
+ }
+ /**
+ * Test write
+ */
+ public function testWrite()
+ {
+ $writer = new FirePhp($this->firephp);
+ $writer->write(array(
+ 'message' => 'my msg',
+ 'priority' => Logger::DEBUG
+ ));
+ $this->assertEquals('my msg', $this->firephp->calls['trace'][0]);
+ }
+ /**
+ * Test write with FirePhp disabled
+ */
+ public function testWriteDisabled()
+ {
+ $firephp = new MockFirePhp(false);
+ $writer = new FirePhp($firephp);
+ $writer->write(array(
+ 'message' => 'my msg',
+ 'priority' => Logger::DEBUG
+ ));
+ $this->assertTrue(empty($this->firephp->calls));
+ }
+}

0 comments on commit cc795d5

Please sign in to comment.