* */ class iTopComposerTest extends ItopTestCase { protected function setUp(): void { parent::setUp(); clearstatcache(); } /** * @dataProvider IsQuestionnableFolderProvider * @return void */ public function testIsQuestionnableFolder($sDirName, $bIsTest) { $isTestDir = iTopComposer::IsQuestionnableFile($sDirName); $this->assertIsInt($isTestDir); if (true === $bIsTest) { $this->assertTrue(($isTestDir > 0)); } else { $this->assertSame(0, $isTestDir); } } public function IsQuestionnableFolderProvider() { 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 testListAllFoldersAbsPaths() { $oiTopComposer = new iTopComposer(); $aDirs = $oiTopComposer->ListAllFilesAbsPaths(); $this->assertTrue(is_array($aDirs)); foreach ($aDirs as $sDir) { $sDirName = basename($sDir); $this->assertMatchesRegularExpression(iTopComposer::QUESTIONNABLE_FILES_REGEXP, $sDirName, "Directory not matching test dir : $sDir"); } } public function testListDeniedFolderAbsPaths() { $oiTopComposer = new iTopComposer(); $aDirs = $oiTopComposer->ListDeniedFilesAbsPaths(); $this->assertTrue(is_array($aDirs)); $aDeniedDirWrongFormat = []; foreach ($aDirs as $sDir) { if (false === iTopComposer::IsQuestionnableFile($sDir)) { $aDeniedDirWrongFormat[] = $sDir; } } $this->assertEmpty($aDeniedDirWrongFormat, 'There are elements in \Combodo\iTop\Dependencies\Composer\iTopComposer::ListDeniedFoldersRelPaths that are not test dirs :'.var_export($aDeniedDirWrongFormat, true)); } public function testListAllowedFoldersAbsPaths() { $oiTopComposer = new iTopComposer(); $aDirs = $oiTopComposer->ListAllowedFilesAbsPaths(); $this->assertTrue(is_array($aDirs)); } /** * This is NOT a unit test, this test the iTop instance running the test ... */ public function testNoDeniedFolderIsPresentForNow() { $oiTopComposer = new iTopComposer(); $aDeniedButStillPresent = $oiTopComposer->ListDeniedButStillPresentFilesAbsPaths(); $this->assertEmpty( $aDeniedButStillPresent, 'The iTop instance running this test must not contain any denied test directory, found: '.var_export($aDeniedButStillPresent, true) ); } /** * This is NOT a unit test, this test the iTop instance running the test ... */ public function testAllFoldersCovered() { $oDependenciesHandler = new iTopComposer(); $aAllowedAndDeniedDirs = array_merge( $oDependenciesHandler->ListAllowedFilesAbsPaths(), $oDependenciesHandler->ListDeniedFilesAbsPaths() ); $aExistingDirs = $oDependenciesHandler->ListAllFilesAbsPaths(); $aMissing = array_diff($aExistingDirs, $aAllowedAndDeniedDirs); $aExtra = array_diff($aAllowedAndDeniedDirs, $aExistingDirs); $this->assertEmpty( $aMissing, 'Test dirs exists in /lib !'."\n" .' They must be declared either in the allowed or denied list in '.iTopComposer::class." (see N°2651).\n" .' List of dirs:'."\n".var_export($aMissing, true) ); } }