代码接收seeInDatabase()无法按预期工作

时间:2019-06-23 09:16:02

标签: codeception

我无法使代码接受seeInDatabase()正常工作。这是我的Cest:

public function testContactMailCheckbox(AcceptanceTester $I) {
    $I->scrollTo("#adminMailSettingsForm", 0, -200);
    $I->seeInDatabase("pib_users", [
        "user_email" => "admin-cest@example.org",
        "user_receive_contact_notification" => 0
    ]);

    $I->click("//label[@for='contactMailNotification']", "#adminMailSettingsForm");
    $I->waitForJS("return $.active == 0;",10);
    $I->wait(100);
    $I->seeInDatabase("pib_users", [
        "user_email" => "admin-cest@example.org",
        "user_receive_contact_notification" => 1
    ]);
}

第一个seeInDatabase()通过,一切都很好。通过更改数据库转储中的默认数据,我可以验证此seeInDatabase-Assertion是否正常工作。当我将默认数据更改为"user_receive_contact_notification" => 1时,第一个seeInDatabase失败,这意味着它可以正常工作。

我使用$I->wait(100)来验证是否没有同步问题。在这段时间内,我可以通过phpMyAdmin检查该行确实已正确更新。那意味着测试应该通过。

这是我的Db配置:

actor: AcceptanceTester
modules:
  enabled:
      - WebDriver:
          url: 'http://pib.local/'
          window_size: false # disabled in ChromeDriver
          port: 5555
          browser: chrome
          capabilities:
            chromeOptions:
              args: ["--headless", "--no-sandbox", "--disable-gpu", "--window-size=1920,1080"]

      - \Helper\Acceptance
      - Sequence
      - \Helper\DbHelper
  config:
      \Helper\DbHelper:
          user: "root"
          password: ""
          dsn: "mysql:host=localhost;dbname=pib"
          cleanup: true
          dump: 'tests/database_dump_tests.sql'
          populate: true
          reconnect: true
  step_decorators: ~

我的DbHelper仅包含一个函数:

class DbHelper extends \Codeception\Module\Db
{
    public function putInDatabase($table, $data, $insertOnlyIfNotExisting = true) {
        // if ignoreDuplicateError is true, only execute insert when not existing already
        if($this->countInDatabase($table, $data) == 0 | !$insertOnlyIfNotExisting) {
            $this->_insertInDatabase($table, $data);
        }
    }
}

这可能与this question有关。我虽然没有使用Laravel,所以仅使用seeRecord()-helper并不会对我有帮助。

0 个答案:

没有答案