rewrite test after Tlog refactoring
This commit is contained in:
@@ -11,4 +11,8 @@ if (extension_loaded('apc') && $env == 'prod') {
|
|||||||
|
|
||||||
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader);
|
$apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader);
|
||||||
$apcLoader->register();
|
$apcLoader->register();
|
||||||
|
|
||||||
|
return $apcLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $loader;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Parser implements ParserInterface
|
|||||||
$this->loadParser();
|
$this->loadParser();
|
||||||
|
|
||||||
|
|
||||||
\Thelia\Log\Tlog::instance()->debug("tutu");
|
\Thelia\Log\Tlog::getInstance()->debug("tutu");
|
||||||
|
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ class TlogDestinationFile extends AbstractTlogDestination
|
|||||||
if (! is_dir($dir)) {
|
if (! is_dir($dir)) {
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
touch($file_path);
|
||||||
|
chmod($file_path, 0777);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->fh) @fclose($this->fh);
|
if ($this->fh) @fclose($this->fh);
|
||||||
|
|||||||
@@ -27,22 +27,22 @@ use Thelia\Log\AbstractTlogDestination;
|
|||||||
|
|
||||||
class TlogDestinationNull extends AbstractTlogDestination
|
class TlogDestinationNull extends AbstractTlogDestination
|
||||||
{
|
{
|
||||||
public function get_titre()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return "Trou noir";
|
return "Trou noir";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_description()
|
public function getDescription()
|
||||||
{
|
{
|
||||||
return "Cette destination ne provoque aucune sortie";
|
return "Cette destination ne provoque aucune sortie";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajouter($string)
|
public function add($string)
|
||||||
{
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res)
|
public function write(&$res)
|
||||||
{
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,22 +32,22 @@ class TlogDestinationText extends AbstractTlogDestination
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_titre()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return "Affichage direct dans la page, en texte brut";
|
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.";
|
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";
|
echo $texte."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ecrire(&$res)
|
public function write(&$res)
|
||||||
{
|
{
|
||||||
// Rien
|
// Rien
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
namespace Thelia\Log;
|
namespace Thelia\Log;
|
||||||
|
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -61,6 +60,10 @@ class Tlog Implements TlogInterface
|
|||||||
const DEFAUT_IP = "";
|
const DEFAUT_IP = "";
|
||||||
const DEFAUT_SHOW_REDIRECT = 0;
|
const DEFAUT_SHOW_REDIRECT = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var \Thelia\Log\Tlog
|
||||||
|
*/
|
||||||
private static $instance = false;
|
private static $instance = false;
|
||||||
|
|
||||||
protected $destinations = array();
|
protected $destinations = array();
|
||||||
@@ -88,7 +91,7 @@ class Tlog Implements TlogInterface
|
|||||||
*
|
*
|
||||||
* @return \Thelia\Log\Tlog
|
* @return \Thelia\Log\Tlog
|
||||||
*/
|
*/
|
||||||
public static function instance() {
|
public static function getInstance() {
|
||||||
if (self::$instance == false) {
|
if (self::$instance == false) {
|
||||||
self::$instance = new Tlog();
|
self::$instance = new Tlog();
|
||||||
|
|
||||||
|
|||||||
@@ -28,40 +28,24 @@ use Thelia\Core\Thelia;
|
|||||||
|
|
||||||
class TlogTest extends \PHPUnit_Framework_TestCase
|
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";
|
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()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
self::$logger = Tlog::getInstance();
|
||||||
|
|
||||||
$_SERVER['REMOTE_ADDR'] = '::1';
|
self::$logger->setDestinations("Thelia\Log\Destination\TlogDestinationText");
|
||||||
|
self::$logger->setLevel(Tlog::TRACE);
|
||||||
$containerMock = $this->getMock("Symfony\Component\DependencyInjection\Container", array("get", "getParameter"));
|
self::$logger->setFiles("*");
|
||||||
|
|
||||||
$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 function testTraceWithTraceLevel()
|
public function testTraceWithTraceLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::TRACE);
|
$logger->setLevel(Tlog::TRACE);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -70,8 +54,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testTraceWitoutTraceLevel()
|
public function testTraceWitoutTraceLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->trace("foo");
|
$logger->trace("foo");
|
||||||
@@ -80,8 +64,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testDebugWithDebugLevel()
|
public function testDebugWithDebugLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::DEBUG);
|
$logger->setLevel(Tlog::DEBUG);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -90,8 +74,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testDebugWitoutDebugLevel()
|
public function testDebugWitoutDebugLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->debug("foo");
|
$logger->debug("foo");
|
||||||
@@ -100,8 +84,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testInfoWithInfoLevel()
|
public function testInfoWithInfoLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::INFO);
|
$logger->setLevel(Tlog::INFO);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -110,8 +94,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testInfoWitoutInfoLevel()
|
public function testInfoWitoutInfoLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->info("foo");
|
$logger->info("foo");
|
||||||
@@ -120,8 +104,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testWarningWithWarningLevel()
|
public function testWarningWithWarningLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::WARNING);
|
$logger->setLevel(Tlog::WARNING);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -130,8 +114,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testWarningWitoutWarningLevel()
|
public function testWarningWitoutWarningLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->warning("foo");
|
$logger->warning("foo");
|
||||||
@@ -140,8 +124,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testErrorWithErrorLevel()
|
public function testErrorWithErrorLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::ERROR);
|
$logger->setLevel(Tlog::ERROR);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -150,8 +134,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testErrorWitoutErrorLevel()
|
public function testErrorWitoutErrorLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->error("foo");
|
$logger->error("foo");
|
||||||
@@ -160,8 +144,8 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testFatalWithFatalLevel()
|
public function testFatalWithFatalLevel()
|
||||||
{
|
{
|
||||||
|
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::FATAL);
|
$logger->setLevel(Tlog::FATAL);
|
||||||
|
|
||||||
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
//"#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: "
|
||||||
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
$this->expectOutputRegex(sprintf($this->regex, "foo"));
|
||||||
@@ -170,18 +154,10 @@ class TlogTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFatalWitoutFatalLevel()
|
public function testFatalWitoutFatalLevel()
|
||||||
{
|
{
|
||||||
$logger = $this->logger;
|
$logger = self::$logger;
|
||||||
$logger->set_level(Tlog::MUET);
|
$logger->setLevel(Tlog::MUET);
|
||||||
|
|
||||||
$this->expectOutputRegex("/^$/");
|
$this->expectOutputRegex("/^$/");
|
||||||
$logger->fatal("foo");
|
$logger->fatal("foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigModel
|
|
||||||
{
|
|
||||||
public function __call($name, $arguments)
|
|
||||||
{
|
|
||||||
return $arguments[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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');
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Thelia\Tests\Tools\_files;
|
|
||||||
|
|
||||||
class A
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Thelia\Tests\Tools\_files;
|
|
||||||
|
|
||||||
class B
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,5 +5,10 @@
|
|||||||
* @file
|
* @file
|
||||||
* Functions needed for Thelia bootstrap
|
* Functions needed for Thelia bootstrap
|
||||||
*/
|
*/
|
||||||
|
$env = "test";
|
||||||
define('THELIA_ROOT', __DIR__ .'/../../../../');
|
define('THELIA_ROOT', __DIR__ .'/../../../../');
|
||||||
$loader = require __DIR__ . '/../../../autoload.php';
|
$loader = require __DIR__ . '/../../../autoload.php';
|
||||||
|
|
||||||
|
require THELIA_ROOT . '/local/config/config_db.php';
|
||||||
|
|
||||||
|
\Propel::init(THELIA_ROOT . "/local/config/config_thelia.php");
|
||||||
|
|||||||
Reference in New Issue
Block a user