Codeception / module-yii2

Codeception module for Yii2 framework
MIT License
16 stars 36 forks source link

Module\Yii2: force set $config->['transaction'] to false inside of Acceptance tests #39

Closed bscheshirwork closed 2 years ago

bscheshirwork commented 6 years ago

What are you trying to achieve?

don't use transaction mechanism in Acceptance tests

What do you get instead?

usage depends of config https://github.com/Codeception/Codeception/blob/b1d96dad56bb3dbc5185d7dcb7913db441c121b6/src/Codeception/Module/Yii2.php#L156-L158 https://github.com/Codeception/Codeception/blob/b1d96dad56bb3dbc5185d7dcb7913db441c121b6/src/Codeception/Module/Yii2.php#L194-L200

Details

class_name: AcceptanceTester
modules:
    enabled:
# See docker-codeception-run/docker-compose.yml: "ports" of service "nginx" is null; the selenium service named "chrome"
# See nginx-conf/nginx.conf: listen 8080 for frontend; listen 8081 for backend
        - WebDriver:
            url: http://nginx:8080/
            host: browser
            port: 4444
            browser: chrome
        - \bscheshirwork\Codeception\Module\DbYii2Config:
            dump: ../common/tests/_data/dump.sql #relative path from "codeception.yml"
            populate: true
            cleanup: true
        - Yii2:
            part:
              - email
              - ORM
              - Fixtures
            cleanup: true # remove fixture in _after and load fixture in _before. In this case data from fixtures insert to db AFTER DbYii2Config populate
            transaction: false # don't wrap test in transaction. Acceptance tests use another db connection; i.e. transaction has no effect.
        - Asserts
        - common\tests\Helper\Acceptance
samdark commented 6 years ago

Why not using transactions?

samdark commented 6 years ago

Or do you mean that you want to turn it off via config but you can not?

bscheshirwork commented 6 years ago

Why not using transactions?

Acceptance browser (in my cese it is a Selenium) (i.e. app who running from browser) use another connection to db; I am right?

samdark commented 6 years ago

What do you mean by another? Do you have multiple connections?

bscheshirwork commented 6 years ago

Someone like "another instance of connection handler". Another process. Another (separated) request. (in my case - another container, another php :smile_cat: )
Use same(common) db connection settings for connect. Use same(common) code for create connection;

samdark commented 6 years ago

I don't get it :(

bscheshirwork commented 6 years ago

@samdark в разных приложениях -

тестовом, которое подключается к коду через коннектор (в вендорах или phar) src/Codeception/Lib/Connector/Yii2.php модуля

и том, которое запускает сервер по запросу от эмулятора браузера (точка входа frontend/web/index-test.php)

соединения к базе yii2\db\Connection::$pdo, естественно, не один экземпляр класса PHP PDO. Соответственно и естественно, транзакция не имеет смысла - происходящее в транзакции никак не скажется на тестируемой базе.

Учитывая скрытую магию задания этого параметра, в случае если он не указан, https://github.com/Codeception/Codeception/blob/b1d96dad56bb3dbc5185d7dcb7913db441c121b6/src/Codeception/Module/Yii2.php#L156-L158 создаётся путаница.

samdark commented 6 years ago

А, вот оно что... да, это будут два разных соединения и да, это не сразу очевидно. Что предлагаете сделать? Изменить умолчание совсем или изменить его только для этого типа тестов?

@DavertMik думаю, без тебя не обойдёмся...

bscheshirwork commented 6 years ago

Думаю, идеально зашла бы проверка на текущего тестера

class_name: AcceptanceTester

либо же осветить этот момент в документации поподробнее и объяснить всем и каждому, как задавать эту пару параметров для случая acceptance.suite.yml:

class_name: AcceptanceTester
modules:
    enabled:
        - Yii2:
            cleanup: true
            transaction: false

и в чём её смысл.

С учётом того, что ещё встречаются проблемы с историческим _before, это будет не лишним

samdark commented 6 years ago

Вот даже не знаю, что лучше...

DavertMik commented 6 years ago

usage depends of config

Yes, you are right usage depends on config There is no magical guessing which type of tests you run now. You have configuration and you are free to use it the way you like it.

What we can probably do is to provide an example config with transaction: false for acceptance tests, or throw warnings if WebDriver module is located.

samdark commented 6 years ago

Both ideas are good to implement.

denisbondar commented 6 years ago

Внесите, пожалуйста, правки в документ http://codeception.com/for/yii в связи с изменениями.

SamMousa commented 6 years ago

What we can probably do is to provide an example config with transaction: false for acceptance tests, or throw warnings if WebDriver module is located.

Alternatively we could split the module into several smaller modules. Then we could have a Yii2Transaction module that depends on Yii2 and conflicts with WebDriver.