N°4771 Fix lib test dir detection

Thanks to @Molkobain and @Hipska for their review in dfaa9733
This commit is contained in:
Pierre Goiffon
2022-02-11 18:12:33 +01:00
parent 4caf52f1ae
commit 81c39c35cd
2 changed files with 42 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ use RecursiveIteratorIterator;
class iTopComposer 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}. * @return array List of all subdirs of /lib that are {@see IsTestDir}.
@@ -61,10 +61,17 @@ class iTopComposer
return $aAllTestDirs; return $aAllTestDirs;
} }
/**
* @param $sDirName
*
* @return false|int as {@see \preg_match()}
* @uses self::TEST_DIR_REGEXP
* @uses \preg_match()
*/
public static function IsTestDir($sDirName) public static function IsTestDir($sDirName)
{ {
return preg_match(self::TEST_DIR_REGEXP, $sDirName); return preg_match(static::TEST_DIR_REGEXP, $sDirName);
} }
/** /**

View File

@@ -33,6 +33,35 @@ class iTopComposerTest extends ItopTestCase
clearstatcache(); 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() public function testListAllTestDir()
{ {
$oiTopComposer = new iTopComposer(); $oiTopComposer = new iTopComposer();
@@ -40,9 +69,9 @@ class iTopComposerTest extends ItopTestCase
$this->assertTrue(is_array($aDirs)); $this->assertTrue(is_array($aDirs));
foreach ($aDirs as $sDir) foreach ($aDirs as $sDir) {
{ $sDirName = basename($sDir);
$this->assertRegExp('#[tT]ests?/?$#', $sDir); $this->assertRegExp(iTopComposer::TEST_DIR_REGEXP, $sDirName, "Directory not matching test dir : $sDir");
} }
} }