CakePHP 3 + 代码化
CakePHP 3 + Codeception
我尝试在 cakePHP 中使用代码检测框架。
我通过作曲家安装了这个插件:https://github.com/cakephp/codeception
我能够 运行 "vendor/bin/codecept bootstrap" 并且它创建了所有测试文件夹和文件。添加一个简单的测试后,我尝试 运行 "vendor/bin/codecept run" 并开始 运行 我的测试,然后在一些致命错误中结束,如下所示:
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
我使用的是 ddev-docker 环境 - 如果这符合...
这是我的 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
}
}
我也 运行 "composer dump-autoload" 因为我认为它与自动加载有关...但没有成功。
有人可以帮忙吗?
[更新]
这是我的 phpunit.xml.dist 文件:
<?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>
bootstrap.php 文件为空。
您好!
所以实际上是评论中提到的一个BUG ndm:github.com/cakephp/cakephp/issues/12603
我尝试在 cakePHP 中使用代码检测框架。 我通过作曲家安装了这个插件:https://github.com/cakephp/codeception
我能够 运行 "vendor/bin/codecept bootstrap" 并且它创建了所有测试文件夹和文件。添加一个简单的测试后,我尝试 运行 "vendor/bin/codecept run" 并开始 运行 我的测试,然后在一些致命错误中结束,如下所示:
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
我使用的是 ddev-docker 环境 - 如果这符合...
这是我的 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
}
}
我也 运行 "composer dump-autoload" 因为我认为它与自动加载有关...但没有成功。 有人可以帮忙吗?
[更新] 这是我的 phpunit.xml.dist 文件:
<?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>
bootstrap.php 文件为空。
您好!
所以实际上是评论中提到的一个BUG ndm:github.com/cakephp/cakephp/issues/12603