Yii2 在Codeception TestCase的函数之前的_中找不到类
我正在用Yii2和Codeception编写一些测试,在Yii2 在Codeception TestCase的函数之前的_中找不到类,yii2,codeception,Yii2,Codeception,我正在用Yii2和Codeception编写一些测试,在\u before()函数中使用自己的类时,我遇到了一个奇怪的错误: FATAL ERROR. TESTS NOT FINISHED. Class 'app\lib\FTPImage' not found in /var/www/proyect/tests/codeception/unit/lib/FTPImageTest.php:13 这很奇怪,因为如果我在测试方法中使用它,它就像魅力一样:/ 以下是测试代码: <?php nam
\u before()函数中使用自己的类时,我遇到了一个奇怪的错误:
FATAL ERROR. TESTS NOT FINISHED.
Class 'app\lib\FTPImage' not found in /var/www/proyect/tests/codeception/unit/lib/FTPImageTest.php:13
这很奇怪,因为如果我在测试方法中使用它,它就像魅力一样:/
以下是测试代码:
<?php
namespace tests\codeception\unit\lib;
use Yii;
use yii\codeception\TestCase;
use app\lib\FTPImage;
class FTPImageTest extends TestCase{
public $ftp;
public function _before(){
$this->ftp = new FTPImage();
}
public function _after(){
}
public function testGetImagesNoImages(){
$ftp = new FTPImage();
$images = $ftp->getImages("123", "Foobar");
$this->assertEmpty($images);
}
}
我终于找到了解决方案。我已将
之前的\u和
之后的\u功能更改为设置
和拆卸
。这样,我就可以使用我的FTPImage类
以下是我所做的:
class FTPImageTest extends TestCase{
public $ftp;
public function setUp(){
parent::setUp();
$this->ftp = new FTPImage();
}
public function tearDown(){
parent::tearDown();
}
...
}
父::设置();如果我加上这几行,它就会进入无限循环?我的代码怎么了
class FTPImageTest extends TestCase{
public $ftp;
public function setUp(){
parent::setUp();
$this->ftp = new FTPImage();
}
public function tearDown(){
parent::tearDown();
}
...
}