thirteen / testing
0.2.15
2015-09-13 03:23 UTC
README
Laravel 测试用例是一个特性集合和测试用例,用于测试 模型 和 仓储,使其易于管理。
安装
安装 Composer 依赖
composer require "thirteen/testing:0.2.*" --dev
在 config/app.php 中安装服务提供者
Thirteen\Testing\TestingServiceProvider::class
测试模型
要测试模型,只需在你的类中添加 ModelAssertionsTrait 即可。
use App\User;
use Thirteen\Testing\ModelAssertionsTrait;
class UserTest extends TestCase
{
/** @test **/
function it_has_many_posts()
{
$this->assertHasMany((new User)->posts(), App\Post::class);
}
}
断言
- assertBelongsTo($relationship, $class, $foreignKey = null);
- assertBelongsToMany($relationship, $class, $table = null, $foreignKey = null);
- assertHasMany($relationship, $class, $foreignKey = null);
- assertHasOne($relationship, $class, $foreignKey = null);
测试仓储
我不太推荐使用这个,因为它只是扩展了仓储测试用例的测试。
如果你 真的想测试所有仓储方法,那就这么做吧。
use App\User;
use Thirteen\Testing\EloquentRepositoryTestCase;
class UserRepositoryTest extends EloquentRepositoryTestCase
{
public function repository() {
return App\Repositories\UserRepository::class;
}
public function create() {
return ['full_name' => 'Jake the Dog'];
}
public function update() {
return ['name' => 'Finn the Human'];
}
}
问题
- 我似乎无法让 @before 函数特性工作。