Laravel facory并非在单元测试中禁用所有观察者

时间:2018-12-18 07:51:34

标签: laravel-5.7

我为工厂的单元测试创​​建了一些元素。我需要禁用一些观察员,但不是全部。我尝试过

    GameSerie::unsetEventDispatcher();


    factory(GameSerie::class)->create([
        'id' => 1,
        'team_a_id' => 1,
        'team_b_id' => 2,
        'championship_id' => 1,
        'count_wins_a' => 0,
        'count_wins_b' => 0,
        'winner_team_id' => null,
        'date' => '2018-08-17 12:00:00',
        'table_id' => 1
    ]);

    factory(GameSerie::class)->create([
        'id' => 2,
        'team_a_id' => 2,
        'team_b_id' => 1,
        'championship_id' => 1,
        'count_wins_a' => 0,
        'count_wins_b' => 0,
        'winner_team_id' => null,
        'date' => '2018-08-18 12:00:00',
        'table_id' => 2
    ]);

    factory(GameSerie::class)->create([
        'id' => 3,
        'team_a_id' => 3,
        'team_b_id' => 4,
        'championship_id' => 2,
        'count_wins_a' => 0,
        'count_wins_b' => 0,
        'winner_team_id' => null,
        'date' => '2018-08-18 12:00:00',
        'table_id' => 2
    ]);

    GameSerie::setEventDispatcher(new Dispatcher());

但是此表达式也禁用了其他观察者。如何仅禁用观察者一个模型?

0 个答案:

没有答案