Add test case for locate vs find

This commit is contained in:
Daniel Kesselberg 2018-08-06 17:24:19 +02:00
parent df7bdf7033
commit 98de4eae92
2 changed files with 41 additions and 4 deletions

View File

@ -36,6 +36,7 @@ class ModuleAutoLoader implements BootstrapInterface
/**
* Find available modules
* @deprecated 1.3 replace call for locateModules with findModules and handle caching outside of method (e.g. in boostrap)
* @return array|bool|mixed
*/
public static function locateModules()

View File

@ -46,6 +46,9 @@ class ModuleAutoLoaderTest extends Unit
*/
protected $tester;
/**
* Assert that locateModules find all core modules
*/
public function testCoreModuleLoading()
{
$modules = array_column(
@ -54,12 +57,12 @@ class ModuleAutoLoaderTest extends Unit
);
/* assert that every core module is found by module loader. expected result of array_diff is an empty array. */
$this->assertEmpty(
array_diff(self::EXPECTED_CORE_MODULES, $modules),
'expected core modules are not resolved by auto loader.'
);
$this->assertEmpty(array_diff(self::EXPECTED_CORE_MODULES, $modules), 'expected core modules are not resolved by auto loader.');
}
/**
* Test that an invalid path for module loading leads to an exception
*/
public function testInvalidModulePath()
{
array_push(Yii::$app->params['moduleAutoloadPaths'], '/dev/null');
@ -72,4 +75,37 @@ class ModuleAutoLoaderTest extends Unit
array_pop(Yii::$app->params['moduleAutoloadPaths']);
}
/**
* Test module loading by path
* @dataProvider dataModuleLoadingByPath
*/
public function testModuleLoadingByPath($path, $count)
{
$this->assertCount($count, ModuleAutoLoader::findModulesByPath($path));
}
/**
* Return test cases for module loading by path
* @return array
*/
public function dataModuleLoadingByPath()
{
return [
['@humhub/modules', count(self::EXPECTED_CORE_MODULES)],
['@humhub/invalid', 0],
['@invalid/folder', 0]
];
}
/**
* Assert that locateModules and findModules return the same list of modules
*/
public function testLocateAndFindModules()
{
$this->assertEquals(
ModuleAutoLoader::locateModules(),
ModuleAutoLoader::findModules(Yii::$app->params['moduleAutoloadPaths'])
);
}
}