mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2651 - Removal of "Test" dirs within dependencies handled using composer
This commit is contained in:
55
.make/composer/rmDeniedTestDir.php
Normal file
55
.make/composer/rmDeniedTestDir.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2010-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
$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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
100
sources/application/composer/iTopComposer.php
Normal file
100
sources/application/composer/iTopComposer.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2010-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
106
test/application/composer/iTopComposerTest.php
Normal file
106
test/application/composer/iTopComposerTest.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2010-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user