diff --git a/.make/composer/rmDeniedTestDir.php b/.make/composer/rmDeniedTestDir.php new file mode 100644 index 000000000..d2e35bcec --- /dev/null +++ b/.make/composer/rmDeniedTestDir.php @@ -0,0 +1,55 @@ + + * + */ + +$iTopFolder = __DIR__ . "/../../" ; + +require_once ("$iTopFolder/approot.inc.php"); +require_once (APPROOT."/setup/setuputils.class.inc.php"); + +if (php_sapi_name() !== 'cli') +{ + throw new \Exception('This script can only run from CLI'); +} + +clearstatcache(); + +$oiTopComposer = new iTopComposer(); +$aDeniedButStillPresent = $oiTopComposer->ListDeniedButStillPresent(); + +foreach ($aDeniedButStillPresent as $sDir) +{ + if (! preg_match('#[tT]ests?/?$#', $sDir)) + { + echo "\nfound INVALID denied test dir: '$sDir'\n"; + throw new \Exception("$sDir must end with /Test/ or /test/"); + } + + try + { + SetupUtils::rrmdir($sDir); + echo "Remove denied test dir: '$sDir'\n"; + } + catch (\Exception $e) + { + echo "\nFAILED to remove denied test dir: '$sDir'\n"; + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index a312e0af4..077463a5b 100644 --- a/composer.json +++ b/composer.json @@ -74,5 +74,10 @@ "allow-contrib": false, "require": "3.4.*" } + }, + "scripts": { + "post-install-cmd": ["@rmDeniedTestDir"], + "post-update-cmd": ["@rmDeniedTestDir"], + "rmDeniedTestDir": "@php .make/composer/rmDeniedTestDir.php" } } diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php index c534b8aec..dd6c7b3ba 100644 --- a/lib/composer/autoload_classmap.php +++ b/lib/composer/autoload_classmap.php @@ -2155,6 +2155,7 @@ return array( 'iScheduledProcess' => $baseDir . '/core/backgroundprocess.inc.php', 'iSelfRegister' => $baseDir . '/core/userrights.class.inc.php', 'iTabbedPage' => $baseDir . '/application/webpage.class.inc.php', + 'iTopComposer' => $baseDir . '/sources/application/composer/iTopComposer.php', 'iTopConfigParser' => $baseDir . '/core/iTopConfigParser.php', 'iTopMutex' => $baseDir . '/core/mutex.class.inc.php', 'iTopOwnershipLock' => $baseDir . '/core/ownershiplock.class.inc.php', diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php index daffbf100..c274c20bc 100644 --- a/lib/composer/autoload_static.php +++ b/lib/composer/autoload_static.php @@ -2385,6 +2385,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b 'iScheduledProcess' => __DIR__ . '/../..' . '/core/backgroundprocess.inc.php', 'iSelfRegister' => __DIR__ . '/../..' . '/core/userrights.class.inc.php', 'iTabbedPage' => __DIR__ . '/../..' . '/application/webpage.class.inc.php', + 'iTopComposer' => __DIR__ . '/../..' . '/sources/application/composer/iTopComposer.php', 'iTopConfigParser' => __DIR__ . '/../..' . '/core/iTopConfigParser.php', 'iTopMutex' => __DIR__ . '/../..' . '/core/mutex.class.inc.php', 'iTopOwnershipLock' => __DIR__ . '/../..' . '/core/ownershiplock.class.inc.php', diff --git a/sources/application/composer/iTopComposer.php b/sources/application/composer/iTopComposer.php new file mode 100644 index 000000000..4e1a66f9f --- /dev/null +++ b/sources/application/composer/iTopComposer.php @@ -0,0 +1,100 @@ + + * + */ + +class iTopComposer +{ + + public function ListAllTestDir() + { + return array_merge( + glob(APPROOT.'lib/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/*/[tT]est/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/*/*/[tT]est/', GLOB_ONLYDIR ), + + + glob(APPROOT.'lib/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/*/[tT]ests/', GLOB_ONLYDIR ), + glob(APPROOT.'lib/*/*/*/*/*/*/*/*/[tT]ests/', GLOB_ONLYDIR ) + + ); + } + + public function ListAllowedTestDir() + { + return array( + APPROOT.'lib/twig/twig/src/Node/Expression/Test/', + APPROOT.'lib/twig/twig/lib/Twig/Node/Expression/Test/', + ); + } + + public function ListDeniedTestDir() + { + return array( + APPROOT.'lib/nikic/php-parser/test/', + APPROOT.'lib/symfony/framework-bundle/Test/', + APPROOT.'lib/symfony/var-dumper/Test/', + APPROOT.'lib/symfony/var-dumper/Tests/Test/', + APPROOT.'lib/twig/twig/src/Test/', + APPROOT.'lib/psr/log/Psr/Log/Test/', + APPROOT.'lib/twig/twig/lib/Twig/Test/', + APPROOT.'lib/symfony/framework-bundle/Tests/Fixtures/TestBundle/FooBundle/Controller/Test/', + APPROOT.'lib/pear/console_getopt/tests/', + APPROOT.'lib/pear/pear_exception/tests/', + APPROOT.'lib/symfony/cache/Tests/', + APPROOT.'lib/symfony/class-loader/Tests/', + APPROOT.'lib/symfony/config/Tests/', + APPROOT.'lib/symfony/console/Tests/', + APPROOT.'lib/symfony/css-selector/Tests/', + APPROOT.'lib/symfony/debug/Tests/', + APPROOT.'lib/symfony/dependency-injection/Tests/', + APPROOT.'lib/symfony/dotenv/Tests/', + APPROOT.'lib/symfony/event-dispatcher/Tests/', + APPROOT.'lib/symfony/filesystem/Tests/', + APPROOT.'lib/symfony/finder/Tests/', + APPROOT.'lib/symfony/framework-bundle/Tests/', + APPROOT.'lib/symfony/http-foundation/Tests/', + APPROOT.'lib/symfony/http-kernel/Tests/', + APPROOT.'lib/symfony/routing/Tests/', + APPROOT.'lib/symfony/stopwatch/Tests/', + APPROOT.'lib/symfony/twig-bridge/Tests/', + APPROOT.'lib/symfony/twig-bundle/Tests/', + APPROOT.'lib/symfony/var-dumper/Tests/', + APPROOT.'lib/symfony/web-profiler-bundle/Tests/', + APPROOT.'lib/symfony/yaml/Tests/', + APPROOT.'lib/symfony/debug/Resources/ext/tests/', + ); + } + + public function ListDeniedButStillPresent() + { + $aDeniedTestDir = $this->ListDeniedTestDir(); + $aAllTestDir = $this->ListAllTestDir(); + return array_intersect($aDeniedTestDir, $aAllTestDir); + } +} \ No newline at end of file diff --git a/test/application/composer/iTopComposerTest.php b/test/application/composer/iTopComposerTest.php new file mode 100644 index 000000000..3e9e30ead --- /dev/null +++ b/test/application/composer/iTopComposerTest.php @@ -0,0 +1,106 @@ + + * + */ + + +class iTopComposerTest extends ItopTestCase +{ + +// protected function setUp() +// { +// parent::setUp(); +// } + + public function testListAllTestDir() + { + $oiTopComposer = new iTopComposer(); + $aDirs = $oiTopComposer->ListAllTestDir(); + + $this->assertTrue(is_array($aDirs)); + + foreach ($aDirs as $sDir) + { + $this->assertRegExp('#[tT]ests?/?$#', $sDir); + } + + } + + public function testListDeniedTestDir() + { + $oiTopComposer = new iTopComposer(); + $aDirs = $oiTopComposer->ListDeniedTestDir(); + + $this->assertTrue(is_array($aDirs)); + + foreach ($aDirs as $sDir) + { + $this->assertRegExp('#[tT]ests?/?$#', $sDir); + } + } + + public function testListAllowedTestDir() + { + $oiTopComposer = new iTopComposer(); + $aDirs = $oiTopComposer->ListAllowedTestDir(); + + $this->assertTrue(is_array($aDirs)); + } + + /** + * This is NOT a unit test, this test the iTop instance running the test ... + */ + public function testNoDeniedDirIsPresentForNow() + { + $oiTopComposer = new iTopComposer(); + + $aDeniedButStillPresent = $oiTopComposer->ListDeniedButStillPresent(); + + $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 testAllDirCovered() + { + $oiTopComposer = new iTopComposer(); + $aAllowedAndDeniedDirs = array_merge( + $oiTopComposer->ListAllowedTestDir(), + $oiTopComposer->ListDeniedTestDir() + ); + + $aExistingDirs = $oiTopComposer->ListAllTestDir(); + + $aMissing = array_diff($aExistingDirs, $aAllowedAndDeniedDirs); + $aExtra = array_diff($aAllowedAndDeniedDirs, $aExistingDirs); + + $this->assertEmpty($aMissing, "The iTop instance running this test has matching directories That must be either in the allowed or in the denied list:".var_export($aMissing, true)); + + } + + +}