Phpunit Laravel 5.1 - 错误特征DatabaseMigrations - 不刷新数据库

时间:2015-11-21 15:20:17

标签: php phpunit laravel-5.1 artisan

我有一个测试文件

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

use Faker\Factory as Faker;

class AdsTest extends TestCase
{

    use DatabaseMigrations;

    public function test_it_one()
    {
        $ad = factory(App\Ad::class, 2)
            ->create( [
                'firstname' => 'jeremie',
                'lastname' => 'ges'
            ]);
    }


    public function test_it_two()
    {
        foreach (App\Ad::get() as $value) 
        {
            var_dump($value->slug);
        }

    }

}

我希望在每次测试数据库后回滚,以避免误报和误报。所以我使用了特征DatabaseMigrations,但它不起作用,方法test_it_two输出:

[15:13:56] PHPUnit 4.8.18 by Sebastian Bergmann and contributors.


Starting test 'AdsTest::test_it_one'.
.
Starting test 'AdsTest::test_it_two'.
.string(11) "jeremie-ges"
string(9) "test-test"
string(11) "test-test-2"
string(13) "ergerg-regerg"
string(11) "test-test-3"
string(13) "jeremie-ges-2"
string(10) "rgreg-regr"
string(13) "jeremie-ges-3"
string(13) "jeremie-ges-4"
string(13) "jeremie-ges-5"
string(13) "jeremie-ges-6"
string(13) "jeremie-ges-7"
string(13) "jeremie-ges-8"
string(13) "jeremie-ges-9"
string(14) "jeremie-ges-10"
string(14) "jeremie-ges-11"
string(14) "jeremie-ges-12"
string(14) "jeremie-ges-13"
string(14) "jeremie-ges-14"

我做错了什么?

解决:在运行测试之前,请注意拥有一个干净的数据库,$ artisan migrate:refresh可以解决问题;)

0 个答案:

没有答案