rewrite test after Tlog refactoring

This commit is contained in:
Manuel Raynaud
2013-01-19 22:52:51 +01:00
parent f3f8793074
commit 88a82c69d1
11 changed files with 58 additions and 154 deletions

View File

@@ -11,4 +11,8 @@ if (extension_loaded('apc') && $env == 'prod') {
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader);
$apcLoader->register();
return $apcLoader;
}
return $loader;

View File

@@ -75,7 +75,7 @@ class Parser implements ParserInterface
$this->loadParser();
\Thelia\Log\Tlog::instance()->debug("tutu");
\Thelia\Log\Tlog::getInstance()->debug("tutu");
return $this->content;
}

View File

@@ -56,6 +56,9 @@ class TlogDestinationFile extends AbstractTlogDestination
if (! is_dir($dir)) {
mkdir($dir, 0777, true);
}
touch($file_path);
chmod($file_path, 0777);
}
if ($this->fh) @fclose($this->fh);

View File

@@ -27,22 +27,22 @@ use Thelia\Log\AbstractTlogDestination;
class TlogDestinationNull extends AbstractTlogDestination
{
public function get_titre()
public function getTitle()
{
return "Trou noir";
}
public function get_description()
public function getDescription()
{
return "Cette destination ne provoque aucune sortie";
}
public function ajouter($string)
public function add($string)
{
// Rien
}
public function ecrire(&$res)
public function write(&$res)
{
// Rien
}

View File

@@ -32,22 +32,22 @@ class TlogDestinationText extends AbstractTlogDestination
parent::__construct();
}
public function get_titre()
public function getTitle()
{
return "Affichage direct dans la page, en texte brut";
}
public function get_description()
public function getDescription()
{
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
}
public function ajouter($texte)
public function add($texte)
{
echo $texte."\n";
}
public function ecrire(&$res)
public function write(&$res)
{
// Rien
}

View File

@@ -23,7 +23,6 @@
namespace Thelia\Log;
use Thelia\Model\ConfigQuery;
use Psr\Log\LoggerInterface;
/**
*
@@ -61,6 +60,10 @@ class Tlog Implements TlogInterface
const DEFAUT_IP = "";
const DEFAUT_SHOW_REDIRECT = 0;
/**
*
* @var \Thelia\Log\Tlog
*/
private static $instance = false;
protected $destinations = array();
@@ -88,7 +91,7 @@ class Tlog Implements TlogInterface
*
* @return \Thelia\Log\Tlog
*/
public static function instance() {
public static function getInstance() {
if (self::$instance == false) {
self::$instance = new Tlog();

View File

@@ -28,40 +28,24 @@ use Thelia\Core\Thelia;
class TlogTest extends \PHPUnit_Framework_TestCase
{
protected $logger;
protected static $logger;
protected $regex = "/(\\d)(.)(\\s+)((?:[a-z][a-z]+))(\\s+)(\\[.*?\\])(\\s+)(\\{.*?\\})(\\s+)((?:2|1)\\d{3}(?:-|\\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))(.)(\\s+)(%s)/is";
public function setUp()
{
parent::setUp();
$_SERVER['REMOTE_ADDR'] = '::1';
$containerMock = $this->getMock("Symfony\Component\DependencyInjection\Container", array("get", "getParameter"));
$configModel = new ConfigModel();
$containerMock->expects($this->any())
->method("get")
->will($this->returnValue($configModel));
$containerMock->expects($this->any())
->method("getParameter")
->with($this->stringContains("logger.class"))
->will($this->returnValue("Thelia\Log\Tlog"));
$this->logger = new Tlog($containerMock);
$this->logger->set_destinations("Thelia\Log\Destination\TlogDestinationText");
$this->logger->set_level(Tlog::TRACE);
$this->logger->set_files("*");
public static function setUpBeforeClass()
{
self::$logger = Tlog::getInstance();
self::$logger->setDestinations("Thelia\Log\Destination\TlogDestinationText");
self::$logger->setLevel(Tlog::TRACE);
self::$logger->setFiles("*");
}
public function testTraceWithTraceLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::TRACE);
$logger = self::$logger;
$logger->setLevel(Tlog::TRACE);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -70,8 +54,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testTraceWitoutTraceLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->trace("foo");
@@ -80,8 +64,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testDebugWithDebugLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::DEBUG);
$logger = self::$logger;
$logger->setLevel(Tlog::DEBUG);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -90,8 +74,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testDebugWitoutDebugLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->debug("foo");
@@ -100,8 +84,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testInfoWithInfoLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::INFO);
$logger = self::$logger;
$logger->setLevel(Tlog::INFO);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -110,8 +94,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testInfoWitoutInfoLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->info("foo");
@@ -120,8 +104,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testWarningWithWarningLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::WARNING);
$logger = self::$logger;
$logger->setLevel(Tlog::WARNING);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -130,8 +114,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testWarningWitoutWarningLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->warning("foo");
@@ -140,8 +124,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testErrorWithErrorLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::ERROR);
$logger = self::$logger;
$logger->setLevel(Tlog::ERROR);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -150,8 +134,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testErrorWitoutErrorLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->error("foo");
@@ -160,8 +144,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testFatalWithFatalLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::FATAL);
$logger = self::$logger;
$logger->setLevel(Tlog::FATAL);
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
$this->expectOutputRegex(sprintf($this->regex, "foo"));
@@ -170,18 +154,10 @@ class TlogTest extends \PHPUnit_Framework_TestCase
public function testFatalWitoutFatalLevel()
{
$logger = $this->logger;
$logger->set_level(Tlog::MUET);
$logger = self::$logger;
$logger->setLevel(Tlog::MUET);
$this->expectOutputRegex("/^$/");
$logger->fatal("foo");
}
}
class ConfigModel
{
public function __call($name, $arguments)
{
return $arguments[1];
}
}

View File

@@ -1,72 +0,0 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Tools;
use Thelia\Tools\DIGenerator;
class DIGeneratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers DIGenerator::genDiModel
*/
public function testGenDiModelWithoutModels()
{
$models = DIGenerator::genDiModel(__DIR__ . '/_filesEmpty');
$this->assertEmpty($models);
}
/**
* @covers DIGenerator::genDiModel
*/
public function testGenDiModelWithModels()
{
$models = DIGenerator::genDiModel(__DIR__ . '/_files');
$this->assertArrayHasKey("A", $models);
$this->assertArrayHasKey("B", $models);
$this->assertEquals("Thelia\Tests\Tools\_files\A", $models["A"]);
$this->assertCount(2, $models, "There is more than 2 models in this directory");
}
/**
* @covers DIGenerator::genDiModel
*/
public function testGenDiModelWithModelsAndExclusion()
{
$models = DIGenerator::genDiModel(__DIR__ . '/_files',array('B'));
$this->assertArrayHasKey("A", $models);
$this->assertCount(1, $models, "There is more than 2 models in this directory");
}
/**
* @expectedException RuntimeException
* @covers DIGenerator::genDiModel
*/
public function testGenDiModelWithWrongDirectory()
{
$models = DIGenerator::genDiModel(__DIR__ . '/wrongDirectory');
}
}

View File

@@ -1,7 +0,0 @@
<?php
namespace Thelia\Tests\Tools\_files;
class A
{
}

View File

@@ -1,8 +0,0 @@
<?php
namespace Thelia\Tests\Tools\_files;
class B
{
}

View File

@@ -5,5 +5,10 @@
* @file
* Functions needed for Thelia bootstrap
*/
$env = "test";
define('THELIA_ROOT', __DIR__ .'/../../../../');
$loader = require __DIR__ . '/../../../autoload.php';
require THELIA_ROOT . '/local/config/config_db.php';
\Propel::init(THELIA_ROOT . "/local/config/config_thelia.php");