Unit testing 测试类中有多个函数的Laravel phpUnit测试错误
我的测试课很简单Unit testing 测试类中有多个函数的Laravel phpUnit测试错误,unit-testing,laravel,Unit Testing,Laravel,我的测试课很简单 <?php use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; class ExampleTest extends TestCase { /** * A basic functio
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$this->visit('/');
}
// when I add this, I get an error
public function testAnotherExample()
{
$this->visit('profile');
}
}
同样的测试如果我注释掉“testBasicExample”,那么另一个测试就可以正常工作
感谢您的帮助。上面的PHPUnit 5.3.2适用于Laravel 5 您需要先卸载旧的phpunit
sudo apt-get purge phpunit
sudo apt-get purge --auto-remove phpunit
然后安装PHPUnit 5.6.1,如下所示
wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
phpunit --version
现在您可以运行phpunit 来自@ceejayoz的回答是:
Fatal error: Cannot redeclare formatBytes() (previously declared in C:\xampp\htdocs\laravellab\helpers\functions.php:3) in C:\xampp\htdocs\laravellab\helpers\functions.php on line 7
他是罪魁祸首
然而,从include到include_once的解决方案只是检查include是否只声明一次,这是在过程PHP中包含文件的经典方法
我建议您通过更改composer.json
文件自动加载该文件。只需在自动加载部分中包含逻辑文件路径(composer.json文件所在的位置)
"autoload": {
"files": ["helpers\functions.php"]
},
helpers\functions.php
看起来像您自己的文件。你是怎么装的,里面装的是什么?答对了!谢谢你的仔细检查。它有一些共同的功能。解决问题后,将其包含函数从include更改为include_。
"autoload": {
"files": ["helpers\functions.php"]
},