Im writing some tests with Yii2 and Codeception and I'm getting a weird error when using my own class in the _before()
function:
FATAL ERROR. TESTS NOT FINISHED.
Class 'app\lib\FTPImage' not found in /var/www/proyect/tests/codeception/unit/lib/FTPImageTest.php:13
It is strange because if I use it in a test method it works like charm :/
Here is the code of the test:
<?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);
}
}
And this is the code of the FTPImage class:
<?php
namespace app\lib;
use Yii;
use app\lib\FTPClient;
use \yii\base\Exception;
use \yii\base\ErrorException;
use \yii\imagine\Image;
class FTPImage{
public function __construct() {
}
public function getImages($reference, $supplier_name){
...
}
I hope there's someone who can help me
Thanks in advance!
Finally I found the solution. I've changed to _before
and _after
functions to setUp
and tearDown
. This way, I can use my FTPImage class.
Here is what I did:
class FTPImageTest extends TestCase{
public $ftp;
public function setUp(){
parent::setUp();
$this->ftp = new FTPImage();
}
public function tearDown(){
parent::tearDown();
}
...
}