I try to use codeception testing framework with cakePHP. I installed this plugin via composer: https://github.com/cakephp/codeception
I was able to run "vendor/bin/codecept bootstrap" and it created all the tests folders and files. After adding a simple Test I try to run "vendor/bin/codecept run" and it starts running my test and then ends up in some Fatal errors looking like this:
vendor/bin/codecept run
Codeception PHP Testing Framework v2.3.9
Powered by PHPUnit 6.5.13 by Sebastian Bergmann and contributors.
App\TestSuite\Codeception.Acceptance Tests (1) ---------------------------------------------------------------------------
✔ SigninCest: Try to test (0.00s)
---------------------------------------------------------------------------------------------------------------------------
PHP Fatal error: Uncaught Error: Call to undefined function Cake\TestSuite\Fixture\loadPHPUnitAliases() in /var/www/html/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php:17
Stack trace:
#0 /var/www/html/vendor/composer/ClassLoader.php(444): include()
#1 /var/www/html/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/html/v...')
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass('Cake\\TestSuite\\...')
#3 /var/www/html/vendor/cakephp/codeception/src/Helper/FixtureTrait.php(48): spl_autoload_call('Cake\\TestSuite\\...')
#4 /var/www/html/vendor/cakephp/codeception/src/Framework.php(40): Cake\Codeception\Framework->loadFixtureManager()
#5 /var/www/html/vendor/codeception/codeception/src/Codeception/SuiteManager.php(80): Cake\Codeception\Framework->_initialize()
#6 /var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php(187): Codeception\SuiteManager->initialize()
#7 /var/www/html/vendor/codeception/codeception/src/Codeception/Codecept.php(158): Codeception in /var/www/html/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php on line 17
I use a ddev-docker environment - if this metters...
And this is my composer.json
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "https://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=7.0",
"cakephp/cakephp": "3.6.*",
"cakephp/migrations": "^2.0.0",
"cakephp/plugin-installer": "^1.0",
"josegonzalez/dotenv": "3.*",
"mobiledetect/mobiledetectlib": "2.*"
},
"require-dev": {
"cakephp/bake": "^1.1",
"cakephp/cakephp-codesniffer": "^3.0",
"cakephp/codeception": "dev-master",
"cakephp/debug_kit": "^3.15.0",
"psy/psysh": "@stable"
},
"suggest": {
"markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
"dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.",
"phpunit/phpunit": "Allows automated tests to be run without system-wide install."
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-create-project-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
"fullcheck": [
"@test",
"@cs-check"
],
"cs-check": "phpcs --colors -p --extensions=php,ctp --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"cs-fix": "phpcbf --colors --extensions=php,ctp --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
"test": "phpunit --colors=always"
},
"prefer-stable": true,
"config": {
"sort-packages": true
}
}
I also run "composer dump-autoload" because I think it has something to do with the autoloading... but without success. Can anyone help with that?
[UPDATE] Here is my phpunit.xml.dist file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>
<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="app">
<directory>tests/TestCase/</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>
<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
<!-- Ignore vendor tests in code coverage reports -->
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<directory suffix=".php">plugins/*/src/</directory>
</whitelist>
</filter>
</phpunit>
The bootstrap.php file are empty.
Greetings!
phpunit.xml.distandtests/bootstrap.phpfiles look like? - ndmtestsfolder, not the ones in theAcceptance,Functional, etc. folders! - ndmtests/bootstrap.phpfile that includes the autoloader and bootstraps your application, which in turn bootstraps the CakePHP core, and the latter is where the missing function is being defined. Compare your app structure/files to github.com/cakephp/app/tree/3.6.5. - ndm