Closed StalkAlex closed 8 years ago
In which type/suite did you get errors (unit, functional, acceptance)?
Unit, one test file with one test method. It seems logically, codeception can't see application classes because framework class loader has not been loaded/initialised.
@akaSStalkALEX Could you double check your unit tests.
I've just had a similar problem, but extending from yii\codeception\TestCase
with the correct $appConfig
setting should take care about application initialization.
I've added some tests for login/logout with the user module, which requires correct initialization of several application components. See also https://github.com/phundament/app/blob/master/tests/codeception/unit/prod/models/UserTest.php
I've also tried your PR, which also makes the tests pass, because an application gets initialized. But it would be cleaner, if the TestCase would do the job.
CC: @Quexer69 Unit test setup.
And they pass when you've done the correct user setup, see https://travis-ci.org/phundament/app/jobs/113484331#L1181
I changed my test as you proposed. It works. But thing is test that I used was generated by console command codecept generate:test unit Example
. It looks like this
class ExampleTest extends \Codeception\TestCase\Test
{
/**
* @var \UnitTester
*/
protected $tester;
protected function _before()
{
}
protected function _after()
{
}
// tests
public function testMe()
{
}
}
Codecept generates this file in unit folder and it doesn't include $appConfig by default.
Also with $this->tester->assertTrue(a,b)
code completion works in PhpStorm, but with $this->assertTrue(a,b)
I can't see hints in PhpStorm (assertFalse, assertNull etc.).
If I change extends \Codeception\TestCase\Test
to extends \yii\codeception\TestCase
then generated version works.
@akaSStalkALEX About the generated tests ... can you specify a template for the tests in Codeception?
Alternatively we could provide a custom gii command.
A phpdoc variable defnition like
<?php
/* @var $this Codeception\ClassXYZ */
?>
should fix the code-completion.
By the way: Which codecept
version are you using? There were some changes from 2.0 to 2.1.
Do you use Phundament with Docker or directly on your machine?
Not sure if this should work this way or not, but without it codeception throwed me "class not found" exceptions, when I tried to use classes from my components folder
$helper = new \app\components\XmlHelper();
something like that in my test function.