punktde/codeception-database

提供模块和Gherkin步骤,用于在Codeception测试中使用数据库

3.1.0 2024-02-20 16:47 UTC

This package is auto-updated.

Last update: 2024-09-20 17:58:07 UTC


README

Codeception Database模块的Gherkin步骤和附加模块功能

如何使用

扩展模块

在您的 codeception.yaml 中使用模块 PunktDe\Codeception\Database\Module\Database 代替默认的Codeception模块 db

modules:
   enabled:
      - PunktDe\Codeception\Database\Module\Database:
         dsn: 'mysql:host=localhost;dbname=testdb'
         user: 'root'
         password: ''
         dump: 'tests/_data/dump.sql'
         populate: true
         cleanup: true
         reconnect: true
         waitlock: 10
         ssl_key: '/path/to/client-key.pem'
         ssl_cert: '/path/to/client-cert.pem'
         ssl_ca: '/path/to/ca-cert.pem'
         ssl_verify_server_cert: false
         ssl_cipher: 'AES256-SHA'
         initial_queries:
             - 'CREATE DATABASE IF NOT EXISTS temp_db;'
             - 'USE temp_db;'
             - 'SET NAMES utf8;'

Gherkin步骤

只需将特性 PunktDe\Codeception\Database\ActorTraits\Database 添加到您的测试演员中。然后您可以使用 *.feature 文件编写带有新步骤的Gherkin测试。

示例演员
<?php

/*
 *  (c) 2018 punkt.de GmbH - Karlsruhe, Germany - http://punkt.de
 *  All rights reserved.
 */

/**
 * Inherited Methods
 * @method void wantToTest($text)
 * @method void wantTo($text)
 * @method void execute($callable)
 * @method void expectTo($prediction)
 * @method void expect($prediction)
 * @method void amGoingTo($argumentation)
 * @method void am($role)
 * @method void lookForwardTo($achieveValue)
 * @method void comment($description)
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
 *
 * @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
    use _generated\AcceptanceTesterActions;
    use \PunktDe\Codeception\Database\ActorTraits\Database; // use the database steps trait
}
有哪些步骤?

要获取所有可用的步骤,您只需运行以下命令

vendor/bin/codecept -c path/to/codeception.yaml gherkin:steps suiteName

这将给出所有可用步骤的表格。