Yii2 module don't call _fixtures() method of Cest class #3612

Closed
sashsvamir opened this Issue Oct 15, 2016 · 10 comments

Projects

None yet

6 participants

@sashsvamir

I'm tried to add _fixture() method to my Cest classes on any suites, but Yii2 module on 169 line: method_exists($test, self::TEST_FIXTURES_METHOD) always return false value and loading fixture is passing;
I'm try to debug this moment, on 169 line, $test contain "Codeception\Test\Case" class and have property $testClassInstance with my current Cest class. But when i tried check to any exist method by calling method_exist($test, 'exist_method_name') of this Cest class, that always return false value, only methods of "Codeception\Test\Case" can be finded (ex. calling method_exist($test, "test") return true).

  • Codeception version: 2.2.5
  • PHP Version: 5.5.37
  • Operating System: os x
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
    codeception.yml
namespace: productEav\tests\backend
actor: Tester
paths:
    tests: .
    log: ./_output
    data: ./_data
    support: ./_support
settings:
    bootstrap: ../../../../../tests/codeception/backend/_bootstrap.php
    colors: true
    memory_limit: 1024M
    log: true
extensions:
    enabled:
        - Codeception\Extension\RunFailed
config:
    test_entry_url: http://shop-back/index-test.php

unit.suite.yml

class_name: UnitTester
modules:
    enabled:
        - Asserts
        - productEav\tests\backend\Helper\Unit
        - Yii2:
            configFile: '../../../../tests/codeception/config/backend/unit.php'
@samdark samdark added the Yii label Oct 15, 2016
@DavertMik DavertMik self-assigned this Oct 15, 2016
@Oxyaction

Issuing the same problem while running Cest file. In Yii2::_before()#169 $test is Codeception\Test\Cest instance and no the instance of my Cest test class.

codeception version: 2.2.5

@primipilus
Contributor

Imho their is an error in codeception/codeception/src/Codeception/Module/Yii2.php on line 170
$this->haveFixtures(call_user_func($test, self::TEST_FIXTURES_METHOD));
must be $this->haveFixtures(call_user_func([$test, self::TEST_FIXTURES_METHOD]));

@michaelarnauts

The change of @primipilus fixes it.

@DavertMik
Member

Thanks @primipilus

@DavertMik DavertMik closed this Oct 26, 2016
@sashsvamir

Excuse me, argument $test in _before method of Yii2 module still contain Codeception\Test\Cest class when Cest test was used and method_exists($test, self::TEST_FIXTURES_METHOD) return false although my Cest class have _fixtures method.
May be i'm wrong, but my composer.json have "codeception/codeception": "2.2.x-dev" branch and i think i have last update (5fbe312) of codeception.
Also fix from @primipilus resolve another problem but current issue still no pass:
Yii2 module don't call _fixtures() method of Cest class.

@primipilus
Contributor

I thing it's not a bug.

here example that works for me

class OneCest
{
    public function _before(AcceptanceTester $I)
    {
        $I->haveFixtures($this->_fixtures());
    }

    public function _after(AcceptanceTester $I)
    {
    }

    // tests
    public function tryToTest(AcceptanceTester $I)
    {
    }

    public function _fixtures()
    {
        return [
            'users'     => [
                'class'    => UserFixture::class,
                'dataFile' => '@tests/codeception/welcome/tests/unit/fixtures/data/models/users.php',
            ],
            'customers' => [
                'class'    => CustomerFixture::class,
                'dataFile' => '@tests/codeception/welcome/tests/unit/fixtures/data/models/customers.php',
            ],
        ];
    }
}

and config acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
        - \tests\codeception\welcome\tests\Helper\Acceptance
        - Yii2:
            configFile: 'tests/config/unit.php'
@sashsvamir

it's because you have called _fixtures method in _before

@primipilus
Contributor
primipilus commented Oct 27, 2016 edited

@sashsvamir And what prevents you to do the same?
Cest class is extends nothing and all actions do AcceptanceTester instance.

you wrote:
Yii2 module still contain Codeception\Test\Cest class when Cest test was used

and all other modules contains this class, no Cest that you used

Codeception for Yii framework

@sashsvamir

Ok, agree with you.
But now in Codeception Yii2 Module Documentation at http://codeception.com/docs/modules/Yii2 on Fixture section now placed code example (look at comment):

<?php
// inside Cest file or Codeception\TestCase\Unit
public function _fixtures()
{
    return ['posts' => PostsFixture::className()]
}

typo?

@primipilus primipilus added a commit to primipilus/Codeception that referenced this issue Oct 30, 2016
@primipilus primipilus Codeception#3612
Now in Codeception Yii2 Module Documentation at http://codeception.com/docs/modules/Yii2 on Fixture section now placed code example:

<?php
// inside Cest file or Codeception\TestCase\Unit
public function _fixtures()
{
    return ['posts' => PostsFixture::className()]
}

For Cest file this does not works before this commit
ad65c6f
@sashsvamir

nice solution ad65c6f, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment