diff --git a/core/autoload.php b/core/autoload.php index e82b17b04..af0bb7a7d 100644 --- a/core/autoload.php +++ b/core/autoload.php @@ -11,4 +11,8 @@ if (extension_loaded('apc') && $env == 'prod') { $apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader("thelia",$loader); $apcLoader->register(); + + return $apcLoader; } + +return $loader; diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index be278a75f..4977ab0de 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -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; } diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php index 7a66adace..d7fa4f5c2 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationFile.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationFile.php @@ -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); diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationNull.php b/core/lib/Thelia/Log/Destination/TlogDestinationNull.php index d3829c056..b5bd3dcbb 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationNull.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationNull.php @@ -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 } diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationText.php b/core/lib/Thelia/Log/Destination/TlogDestinationText.php index 052501566..81fe22d3a 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationText.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationText.php @@ -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 } diff --git a/core/lib/Thelia/Log/Tlog.php b/core/lib/Thelia/Log/Tlog.php index 4282b80c2..865fb594a 100644 --- a/core/lib/Thelia/Log/Tlog.php +++ b/core/lib/Thelia/Log/Tlog.php @@ -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(); diff --git a/core/lib/Thelia/Tests/Log/TlogTest.php b/core/lib/Thelia/Tests/Log/TlogTest.php index 7e0698584..951810da3 100644 --- a/core/lib/Thelia/Tests/Log/TlogTest.php +++ b/core/lib/Thelia/Tests/Log/TlogTest.php @@ -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]; - } -} diff --git a/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php b/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php deleted file mode 100644 index 0c0bb8250..000000000 --- a/core/lib/Thelia/Tests/Tools/DIGeneratorTest.php +++ /dev/null @@ -1,72 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ -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'); - - } -} diff --git a/core/lib/Thelia/Tests/Tools/_files/A.php b/core/lib/Thelia/Tests/Tools/_files/A.php deleted file mode 100644 index 6a4e77ce0..000000000 --- a/core/lib/Thelia/Tests/Tools/_files/A.php +++ /dev/null @@ -1,7 +0,0 @@ -