andizzle/zapper

一个允许您进行db相关测试的测试包。

dev-master 2014-02-25 00:09 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:01:44 UTC


README

Build Status

Zapper - Laravel 测试构建器

这是在数据库涉及时使您的测试过程更简单的尝试。

当前测试过程中缺少什么?

在Laravel 4中,您编写测试,将内容放入setUp()和tearDown()中,然后运行phpunit。这很好,除了当涉及数据库时,它会使用您的开发/预发布数据库。您的测试用例拾取现有数据,等等...你懂我的意思。

您可以从Zapper期望什么?

所以Zapper所做的,就是为您提供隔离的测试数据库,所有测试查询都可以在其中执行。它会构建测试数据库并在之后删除它,哦,它还为您执行迁移(包括您的包)和播种。

如何使用它?

首先,将zapper添加到您的composer.json中

"require": {
    "andizzle/zapper": "dev-master"
}

在composer更新后,您可以开始编写测试

<?php
class MyTest extens Andizzle\Zapper\TestCase {

    public function testPostAuthCode() {}

}
?>

要运行您的测试,请在您的laravel项目中运行zapper的run命令

$ php artisan zapper:run

此外,您还可以指定要运行的测试用例,而无需在测试注释中使用@group或@filter。

$ php artisan zapper:run SUITE
$ php artisan zapper:run SUITE.CLASS
$ php artisan zapper:run SUITE.CLASS.METHOD

您仍然可以传递任何phpunit参数和参数,就像您以前使用的那样。

TestCase,TransactionTestCase以及其他

Zapper为您提供了两种类型的测试用例:testCase和transactionTestCase。

它们都做同样的事情,除了testCase会回滚您的数据库,而Transaction在每次testCase的开始时截断并重新播种。

如果您的测试需要数据库事务,则可以使用TransactionTestCase,很明显...

Zapper实际上会重新排序您的测试,以便所有testCase都在可能更改数据库而不会恢复其原始状态的transactionTestCase之前运行。

Zapper还在TestCase和TransactionTestCase之后运行其他测试。

一些辅助命令

有一些命令是Zapper使用的。它们也为您提供,以便您可以执行您认为合适的事情。

zapper:build_db        Create test DB.
zapper:drop_db         Drop the test DB.
zapper:migrate         Migrate schemas.
zapper:run             Run tests.
zapper:truncate        Truncate certain tables.

如果您认为它很糟糕,并且想要改进它,请提出拉取请求。

Copyright (C) 2013  Andy Zhang

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://gnu.ac.cn/licenses/>.