From 81c39c35cd218710b8cd4246de135e51b39e93ca Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 11 Feb 2022 18:12:33 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B04771=20Fix=20lib=20test=20dir=20detectio?= =?UTF-8?q?n=20Thanks=20to=20@Molkobain=20and=20@Hipska=20for=20their=20re?= =?UTF-8?q?view=20in=20dfaa9733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sources/Composer/iTopComposer.php | 13 +++++-- .../application/composer/iTopComposerTest.php | 35 +++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/sources/Composer/iTopComposer.php b/sources/Composer/iTopComposer.php index 0f5f0e77a..11ee89a91 100644 --- a/sources/Composer/iTopComposer.php +++ b/sources/Composer/iTopComposer.php @@ -27,7 +27,7 @@ use RecursiveIteratorIterator; class iTopComposer { - const TEST_DIR_REGEXP = '/^[tT]ests?$/'; + const TEST_DIR_REGEXP = '/^tests?$/i'; /** * @return array List of all subdirs of /lib that are {@see IsTestDir}. @@ -61,10 +61,17 @@ class iTopComposer return $aAllTestDirs; } - + + /** + * @param $sDirName + * + * @return false|int as {@see \preg_match()} + * @uses self::TEST_DIR_REGEXP + * @uses \preg_match() + */ public static function IsTestDir($sDirName) { - return preg_match(self::TEST_DIR_REGEXP, $sDirName); + return preg_match(static::TEST_DIR_REGEXP, $sDirName); } /** diff --git a/test/application/composer/iTopComposerTest.php b/test/application/composer/iTopComposerTest.php index 159714618..b3bcd356d 100644 --- a/test/application/composer/iTopComposerTest.php +++ b/test/application/composer/iTopComposerTest.php @@ -33,6 +33,35 @@ class iTopComposerTest extends ItopTestCase clearstatcache(); } + /** + * @dataProvider IsTestDirProvider + * @return void + */ + public function testIsTestDir($sDirName, $bIsTest) + { + $isTestDir = iTopComposer::IsTestDir($sDirName); + $this->assertInternalType('int', $isTestDir); + if (true === $bIsTest) { + $this->assertTrue(($isTestDir > 0)); + } else { + $this->assertSame(0, $isTestDir); + } + } + + public function IsTestDirProvider() + { + return [ + 'test' => ['test', true], + 'Test' => ['Test', true], + 'tests' => ['tests', true], + 'Tests' => ['Tests', true], + 'testaa' => ['testaa', false], + 'Testaa' => ['Testaa', false], + 'testsaa' => ['testsaa', false], + 'Testsaa' => ['Testsaa', false], + ]; + } + public function testListAllTestDir() { $oiTopComposer = new iTopComposer(); @@ -40,9 +69,9 @@ class iTopComposerTest extends ItopTestCase $this->assertTrue(is_array($aDirs)); - foreach ($aDirs as $sDir) - { - $this->assertRegExp('#[tT]ests?/?$#', $sDir); + foreach ($aDirs as $sDir) { + $sDirName = basename($sDir); + $this->assertRegExp(iTopComposer::TEST_DIR_REGEXP, $sDirName, "Directory not matching test dir : $sDir"); } }