0

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!

1 Answer 1

2

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();
    }

    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

parent::setUp(); if I add this lines it goes into infinite loop? whats wrong with my code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.