From a42f472301468696c810e867164e7efaa2446332 Mon Sep 17 00:00:00 2001 From: Anael MOBILIA Date: Mon, 9 Dec 2024 00:33:34 +0100 Subject: [PATCH] Fix tests - double chargement de la config --- __tests/DisplayPicsTest.php | 14 ++++++++++++++ displayPics.php | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/__tests/DisplayPicsTest.php b/__tests/DisplayPicsTest.php index effbf02..9f515c0 100644 --- a/__tests/DisplayPicsTest.php +++ b/__tests/DisplayPicsTest.php @@ -33,11 +33,14 @@ class DisplayPicsTest extends TestCase #[RunInSeparateProcess] public function testImageInexistante(): void { + require 'config/config.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = 'files/fichierInexistant.jpg'; + ob_start(); require 'displayPics.php'; ob_end_clean(); + /* @var $monObjet RessourceObject */ $this->assertEquals( _IMAGE_404_, @@ -52,11 +55,14 @@ public function testImageInexistante(): void #[RunInSeparateProcess] public function testMiniatureInexistante(): void { + require 'config/config.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = 'files/thumbs/fichierInexistant.jpg'; + ob_start(); require 'displayPics.php'; ob_end_clean(); + /* @var $monObjet RessourceObject */ $this->assertEquals( _IMAGE_404_, @@ -71,11 +77,14 @@ public function testMiniatureInexistante(): void #[RunInSeparateProcess] public function testRepertoireInexistant(): void { + require 'config/config.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = 'files/repertoireInexistant/fichierInexistant.jpg'; + ob_start(); require 'displayPics.php'; ob_end_clean(); + /* @var $monObjet RessourceObject */ $this->assertEquals( _IMAGE_404_, @@ -90,8 +99,10 @@ public function testRepertoireInexistant(): void #[RunInSeparateProcess] public function testImageBloquee(): void { + require 'config/config.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = 'files/image_10.png'; + ob_start(); require 'displayPics.php'; ob_end_clean(); @@ -110,11 +121,14 @@ public function testImageBloquee(): void #[RunInSeparateProcess] public function testImageSignalee(): void { + require 'config/config.php'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_URI'] = 'files/image_18.png'; + ob_start(); require 'displayPics.php'; ob_end_clean(); + /* @var $monObjet RessourceObject */ $this->assertEquals( _IMAGE_BAN_, diff --git a/displayPics.php b/displayPics.php index 41bfd5b..63ffe0a 100644 --- a/displayPics.php +++ b/displayPics.php @@ -24,7 +24,9 @@ /* * Affichage d'une image & mise à jour des stats */ -require 'config/config.php'; +if (!defined('_PHPUNIT_')) { + require 'config/config.php'; +} // URL demandée $url = $_SERVER['REQUEST_URI'];