New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

This comment has been minimized.

Show comment
Hide comment
@Oxyaction

Oxyaction Oct 16, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@primipilus

primipilus Oct 24, 2016

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]));

Contributor

primipilus commented Oct 24, 2016

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

This comment has been minimized.

Show comment
Hide comment
@michaelarnauts

michaelarnauts Oct 26, 2016

The change of @primipilus fixes it.

The change of @primipilus fixes it.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
Member

DavertMik commented Oct 26, 2016

Thanks @primipilus

@DavertMik DavertMik closed this Oct 26, 2016

@sashsvamir

This comment has been minimized.

Show comment
Hide comment
@sashsvamir

sashsvamir Oct 27, 2016

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.

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

This comment has been minimized.

Show comment
Hide comment
@primipilus

primipilus Oct 27, 2016

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'
Contributor

primipilus commented Oct 27, 2016

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

This comment has been minimized.

Show comment
Hide comment
@sashsvamir

sashsvamir Oct 27, 2016

it's because you have called _fixtures method in _before

it's because you have called _fixtures method in _before

@primipilus

This comment has been minimized.

Show comment
Hide comment
@primipilus

primipilus Oct 27, 2016

Contributor

@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

Contributor

primipilus commented Oct 27, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@sashsvamir

sashsvamir Oct 29, 2016

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?

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?

@sashsvamir

This comment has been minimized.

Show comment
Hide comment
@sashsvamir

sashsvamir Oct 31, 2016

nice solution ad65c6f, thank you!

nice solution ad65c6f, thank you!

Naktibalda added a commit that referenced this issue Nov 5, 2016

chris1312 added a commit to chris1312/Codeception that referenced this issue Jun 16, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment