Nimut / testing-framework

TYPO3 testing framework that provides base classes and configuration for PHPUnit tests
GNU General Public License v2.0
52 stars 25 forks source link

ClassAliasMap::$classAliasLoader is not defined in UnitTest Bootstrap #154

Closed web-commerce-og closed 1 year ago

web-commerce-og commented 1 year ago

General Information:

TYPO3 11 typo3-composer-installers: 3

The Problem

When starting an UnitTest with a command like: .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit/ everything works as expected until you add an extension that provides an alias for a class. An example would be friendsoftypo3/fontawesome-provider. If this extension is added this exception is thrown:

Error in bootstrap script: RuntimeException:
Cannot set an alias map as the alias loader is not registered!
#0 <myprojectpath>/.Build/public/typo3/sysext/core/Classes/Core/ClassLoadingInformation.php(142): TYPO3\ClassAliasLoader\ClassAliasMap::addAliasMap()
#1 <myprojectpath>/.Build/vendor/nimut/testing-framework/src/TestingFramework/Bootstrap/AbstractBootstrap.php(262): TYPO3\CMS\Core\Core\ClassLoadingInformation::registerClassLoadingInformation()
#2 <myprojectpath>/.Build/vendor/nimut/testing-framework/src/TestingFramework/Bootstrap/AbstractBootstrap.php(82): Nimut\TestingFramework\Bootstrap\AbstractBootstrap->dumpAutoloadFiles()
#3 <myprojectpath>/.Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php(35): Nimut\TestingFramework\Bootstrap\AbstractBootstrap->bootstrapUnitTestSystem()
#4 <myprojectpath>/.Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php(36): PHPUnit\Util\FileLoader::{closure}()
#5 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('<myprojectpath>/...')
#6 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load()
#7 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/TextUI/Command.php(565): PHPUnit\Util\FileLoader::checkAndLoad()
#8 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/TextUI/Command.php(345): PHPUnit\TextUI\Command->handleBootstrap()
#9 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/TextUI/Command.php(112): PHPUnit\TextUI\Command->handleArguments()
#10 <myprojectpath>/.Build/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run()
#11 phpvfscomposer://<myprojectpath>/.Build/vendor/phpunit/phpunit/phpunit(97): PHPUnit\TextUI\Command::main()
#12 <myprojectpath>/.Build/bin/phpunit(115): include('phpvfscomposer:...')
#13 {main}

The file in .Build/public/typo3conf/autoload-tests/autoload_classaliasmap.php has now filled arrays so that the ClassAliasMap::$classaliasloader is needed which seems like it is not defined.

helhum commented 1 year ago

Thanks for the report. We cannot reproduce unfortunately.

Here is what I did to verify that alias map is not an issue in composer based setups we use:

git clone https://github.com/IchHabRecht/filefill.git
cd filefill
git checkout 4.1.1
composer update
# confirm requests to allow plugins manually
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --testsuite unit

# unit tests run successfully

composer req mask/mask:*
# friendsoftypo3/fontawesome-provider will be installed as well, as it is required by mask
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --testsuite unit

# unit tests still run successfully

Filefill does nothing exciting here. Pure Composer based setup, TYPO3 and Nimut Testingframework is required and used.

How exactly is your setup when running into the issue you are describing?

Tim-Obert commented 1 year ago

If the Autoload-Information is already generated this step is skipped. See AbstractBootstrap.php#L260 You have to rm -r .Build/public/typo3conf/autoload-tests before running the tests again.

git clone https://github.com/IchHabRecht/filefill.git
cd filefill
git checkout 4.1.1
composer update
# confirm requests to allow plugins manually
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --testsuite unit

# unit tests run successfully

composer req mask/mask:*
rm -r .Build/public/typo3conf/autoload-tests
# friendsoftypo3/fontawesome-provider will be installed as well, as it is required by mask
.Build/bin/phpunit --bootstrap .Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php --testsuite unit
helhum commented 1 year ago

Thanks @Tim-Obert for a way to reproduce it.

You actually unveiled a bug in friendsoftypo3/fontawesome-provider, which does not register the class aliases in its composer.json file, as documented, which in fact leads to the alias not working for Composer installations and also indirectly causing the issue you are seeing here.

With this bug fixed in that extension, the testing framework should work just fine without any changes.