@depends not work in codeception 2.2.1? #3213

Closed
TomaszKane opened this Issue Jun 13, 2016 · 9 comments

Comments

Projects
None yet
3 participants
@TomaszKane
Contributor

TomaszKane commented Jun 13, 2016

Hi,
after update codeception to 2.2.1 @Depends annotation between test methods stop work (on 2.1.0 works fine):

$ ../composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing behat/gherkin (v4.4.1)                      
    Loading from cache

  - Removing symfony/dom-crawler (v2.8.7)
  - Installing symfony/dom-crawler (v3.1.0)
    Loading from cache

  - Removing symfony/css-selector (v2.8.7)
  - Installing symfony/css-selector (v3.1.0)
    Loading from cache

  - Removing symfony/browser-kit (v2.8.7)
  - Installing symfony/browser-kit (v3.1.0)
    Loading from cache

  - Removing symfony/yaml (v2.8.7)
  - Installing symfony/yaml (v3.1.0)
    Loading from cache

  - Removing symfony/event-dispatcher (v2.8.7)
  - Installing symfony/event-dispatcher (v3.1.0)
    Loading from cache

  - Removing symfony/console (v2.8.7)
  - Installing symfony/console (v3.1.0)
    Loading from cache

  - Removing symfony/finder (v2.8.7)
  - Installing symfony/finder (v3.1.0)
    Loading from cache

  - Removing facebook/webdriver (v0.6.0)
  - Installing facebook/webdriver (1.1.2)
    Loading from cache

  - Removing sebastian/version (1.0.6)
  - Installing sebastian/version (2.0.0)
    Loading from cache

  - Installing sebastian/code-unit-reverse-lookup (1.0.0)
    Loading from cache

  - Removing phpunit/php-code-coverage (2.2.4)
  - Installing phpunit/php-code-coverage (4.0.0)
    Loading from cache

  - Installing sebastian/resource-operations (1.0.0)
    Loading from cache

  - Installing sebastian/object-enumerator (1.0.0)
    Loading from cache

  - Removing phpunit/phpunit-mock-objects (2.3.8)
  - Installing phpunit/phpunit-mock-objects (3.2.3)
    Loading from cache

  - Removing phpunit/phpunit (4.7.7)
  - Installing phpunit/phpunit (5.4.4)
    Loading from cache

  - Removing codeception/codeception (2.1.0)
  - Installing codeception/codeception (2.2.1)
    Loading from cache

Now I get:

[TypeError] Argument 1 passed to InvoiceOceanTest::testInvoice() must be of the type integer, none given

I use Yii2.0.8 framework.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jun 13, 2016

Member

Could you provide code sample of two dependent tests and annotation so we could reproduce

Member

DavertMik commented Jun 13, 2016

Could you provide code sample of two dependent tests and annotation so we could reproduce

@TomaszKane

This comment has been minimized.

Show comment
Hide comment
@TomaszKane

TomaszKane Jun 14, 2016

Contributor

Sure:

<?php

use tests\codeception\api\unit\TestCase;

class InvoiceOceanTest extends TestCase
{
    use \Codeception\Specify;

    /**
     * @inheritdoc
     * @throws \yii\base\InvalidConfigException
     */
    protected function setUp()
    {
        parent::setUp();
    }

    /**
     * @inheritdoc
     */
    protected function tearDown()
    {
        parent::tearDown();
    }

    /**
     * Test valid set requests
     */
    public function testValidClient()
    {
        // sth
        return 123;
    }

    /**
     * @depends testValidClient
     * @param int $clientId
     */
    public function testInvoice(int $clientId)
    {
        // sth
    }

    /**
     * @depends testValidClient
     * @param int $clientId
     */
    public function testDeleteClient(int $clientId)
    {
        // sth
    }
}

PHP 7.0.5,
Kubuntu 16.04
composer:

{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "require": {
        "php": "~7.0.0",
        "yiisoft/yii2": ">=2.0.8",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "kartik-v/yii2-widgets": "^3.4",
        "kartik-v/yii2-widget-switchinput": "*",
        "kartik-v/yii2-widget-select2": "@dev",
        "kartik-v/yii2-checkbox-x": "*",
        "kartik-v/yii2-detail-view": "*",
        "kartik-v/yii2-grid": "^3.1",
        "yii2mod/yii2-ion-slider": "^1.0",
        "rmrevin/yii2-ionicon": "^1.1"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*",
        "codeception/codeception": "^2.1",
        "codeception/specify": "*",
        "codeception/verify": "*"
    },
    "config": {
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}

Test output:

$ ../../../vendor/codeception/codeception/codecept run unit
Codeception PHP Testing Framework v2.2.1
Powered by PHPUnit 5.4.4 by Sebastian Bergmann and contributors.

Tests\codeception\api.unit Tests (3) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ InvoiceOceanTest: Valid client (0.1s)
E InvoiceOceanTest: Invoice 
E InvoiceOceanTest: Delete client 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 105 ms, Memory: 10.00MB

There were 2 errors:

---------
1) InvoiceOceanTest: Invoice
 Test  unit/components/InvoiceOcean/ClientTest.php:testInvoice

  [TypeError] Argument 1 passed to InvoiceOceanTest::testInvoice() must be of the type integer, none given  

#1  InvoiceOceanTest->testInvoice

---------
2) InvoiceOceanTest: Delete client
 Test  unit/components/InvoiceOcean/ClientTest.php:testDeleteClient

  [TypeError] Argument 1 passed to InvoiceOceanTest::testDeleteClient() must be of the type integer, none given  

#1  InvoiceOceanTest->testDeleteClient

ERRORS!
Tests: 3, Assertions: 0, Errors: 2.
Contributor

TomaszKane commented Jun 14, 2016

Sure:

<?php

use tests\codeception\api\unit\TestCase;

class InvoiceOceanTest extends TestCase
{
    use \Codeception\Specify;

    /**
     * @inheritdoc
     * @throws \yii\base\InvalidConfigException
     */
    protected function setUp()
    {
        parent::setUp();
    }

    /**
     * @inheritdoc
     */
    protected function tearDown()
    {
        parent::tearDown();
    }

    /**
     * Test valid set requests
     */
    public function testValidClient()
    {
        // sth
        return 123;
    }

    /**
     * @depends testValidClient
     * @param int $clientId
     */
    public function testInvoice(int $clientId)
    {
        // sth
    }

    /**
     * @depends testValidClient
     * @param int $clientId
     */
    public function testDeleteClient(int $clientId)
    {
        // sth
    }
}

PHP 7.0.5,
Kubuntu 16.04
composer:

{
    "name": "yiisoft/yii2-app-advanced",
    "description": "Yii 2 Advanced Project Template",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "require": {
        "php": "~7.0.0",
        "yiisoft/yii2": ">=2.0.8",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "kartik-v/yii2-widgets": "^3.4",
        "kartik-v/yii2-widget-switchinput": "*",
        "kartik-v/yii2-widget-select2": "@dev",
        "kartik-v/yii2-checkbox-x": "*",
        "kartik-v/yii2-detail-view": "*",
        "kartik-v/yii2-grid": "^3.1",
        "yii2mod/yii2-ion-slider": "^1.0",
        "rmrevin/yii2-ionicon": "^1.1"
    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-faker": "*",
        "codeception/codeception": "^2.1",
        "codeception/specify": "*",
        "codeception/verify": "*"
    },
    "config": {
        "process-timeout": 1800
    },
    "extra": {
        "asset-installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        }
    }
}

Test output:

$ ../../../vendor/codeception/codeception/codecept run unit
Codeception PHP Testing Framework v2.2.1
Powered by PHPUnit 5.4.4 by Sebastian Bergmann and contributors.

Tests\codeception\api.unit Tests (3) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ InvoiceOceanTest: Valid client (0.1s)
E InvoiceOceanTest: Invoice 
E InvoiceOceanTest: Delete client 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 105 ms, Memory: 10.00MB

There were 2 errors:

---------
1) InvoiceOceanTest: Invoice
 Test  unit/components/InvoiceOcean/ClientTest.php:testInvoice

  [TypeError] Argument 1 passed to InvoiceOceanTest::testInvoice() must be of the type integer, none given  

#1  InvoiceOceanTest->testInvoice

---------
2) InvoiceOceanTest: Delete client
 Test  unit/components/InvoiceOcean/ClientTest.php:testDeleteClient

  [TypeError] Argument 1 passed to InvoiceOceanTest::testDeleteClient() must be of the type integer, none given  

#1  InvoiceOceanTest->testDeleteClient

ERRORS!
Tests: 3, Assertions: 0, Errors: 2.
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 15, 2016

Member

@TomaszKane what is tests\codeception\api\unit\TestCase ?

If I change it to PHPUnit_Framework_TestCase, your test passes.

Member

Naktibalda commented Jun 15, 2016

@TomaszKane what is tests\codeception\api\unit\TestCase ?

If I change it to PHPUnit_Framework_TestCase, your test passes.

@TomaszKane

This comment has been minimized.

Show comment
Hide comment
@TomaszKane

TomaszKane Jun 16, 2016

Contributor

@Naktibalda short answer is:
https://github.com/yiisoft/yii2-codeception/blob/master/TestCase.php
In tests\codeception\api\unit\TestCase I just overwrite $appConfig attribute.

BTW, Yii REST tests also fails with new codeception:
Output: [yii\base\UnknownPropertyException] Getting unknown property: yii\rest\UrlRule::host

Code:
/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:273

foreach (Yii::$app->urlManager->rules as $rule) {
    /** @var \yii\web\UrlRule $rule */
    if ($rule->host !== null) {
        $domains[] = $this->getDomainRegex($rule->host);
    }
}

$rule->host fails because my app config for urlManager is:

'rules' => [
    '' => 'default/index',
    [
        'class' => 'yii\rest\UrlRule',
        'controller' => ['client', 'service', 'template'],
    ],
],

and \yii\rest\UrlRule not have "host" attribute.

Contributor

TomaszKane commented Jun 16, 2016

@Naktibalda short answer is:
https://github.com/yiisoft/yii2-codeception/blob/master/TestCase.php
In tests\codeception\api\unit\TestCase I just overwrite $appConfig attribute.

BTW, Yii REST tests also fails with new codeception:
Output: [yii\base\UnknownPropertyException] Getting unknown property: yii\rest\UrlRule::host

Code:
/vendor/codeception/codeception/src/Codeception/Module/Yii2.php:273

foreach (Yii::$app->urlManager->rules as $rule) {
    /** @var \yii\web\UrlRule $rule */
    if ($rule->host !== null) {
        $domains[] = $this->getDomainRegex($rule->host);
    }
}

$rule->host fails because my app config for urlManager is:

'rules' => [
    '' => 'default/index',
    [
        'class' => 'yii\rest\UrlRule',
        'controller' => ['client', 'service', 'template'],
    ],
],

and \yii\rest\UrlRule not have "host" attribute.

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 16, 2016

Member

If you want all the features of PhpUnit extend PHPUnit_Framework_TestCase.
All Codeception test formats have different advantages and disadvantages. In 2.2 Cept and Cest formats no longer extend PHPUnit_Framework_TestCase and Unit format relies on it less.

Codeception 2.2 Unit format disables dependency handling of
Compare: https://github.com/Codeception/Codeception/blob/2.2.1/src/Codeception/Test/Unit.php#L122
to https://github.com/sebastianbergmann/phpunit/blob/5.4.6/src/Framework/TestCase.php#L2090

Yii TestCase looks like a bad practice to me because it is initializes a whole application in unit test.
Unit tests should be isolated.

getInternalDomains method is not new, it was there since 2.1.5
But it looks like an easy fix, just change if ($rule->host !== null) { to if (isset($rule->host)) {

Member

Naktibalda commented Jun 16, 2016

If you want all the features of PhpUnit extend PHPUnit_Framework_TestCase.
All Codeception test formats have different advantages and disadvantages. In 2.2 Cept and Cest formats no longer extend PHPUnit_Framework_TestCase and Unit format relies on it less.

Codeception 2.2 Unit format disables dependency handling of
Compare: https://github.com/Codeception/Codeception/blob/2.2.1/src/Codeception/Test/Unit.php#L122
to https://github.com/sebastianbergmann/phpunit/blob/5.4.6/src/Framework/TestCase.php#L2090

Yii TestCase looks like a bad practice to me because it is initializes a whole application in unit test.
Unit tests should be isolated.

getInternalDomains method is not new, it was there since 2.1.5
But it looks like an easy fix, just change if ($rule->host !== null) { to if (isset($rule->host)) {

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 17, 2016

Member

@DavertMik can you fix this aspect of Unit format?

Member

Naktibalda commented Jun 17, 2016

@DavertMik can you fix this aspect of Unit format?

@TomaszKane

This comment has been minimized.

Show comment
Hide comment
@TomaszKane

TomaszKane Jun 29, 2016

Contributor

What about REST bug
#3213 (comment)
in release 2.2.2? I see quick fix is missing.

Contributor

TomaszKane commented Jun 29, 2016

What about REST bug
#3213 (comment)
in release 2.2.2? I see quick fix is missing.

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jun 29, 2016

Member

It wasn't fixed.

@TomaszKane Could you fix it, test it and make a pull request?

Member

Naktibalda commented Jun 29, 2016

It wasn't fixed.

@TomaszKane Could you fix it, test it and make a pull request?

@TomaszKane

This comment has been minimized.

Show comment
Hide comment
@TomaszKane

TomaszKane Jun 29, 2016

Contributor

@Naktibalda I probably find some time to do it.

Contributor

TomaszKane commented Jun 29, 2016

@Naktibalda I probably find some time to do it.

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