运行phpUnit两次后,PHPUnit / Laravel出现问题

时间:2016-03-17 20:07:32

标签: laravel phpunit

当我运行phpunit时,我收到一个错误:

1) InviteTest::an_admin_may_invite_users_but_users_must_register_after
InvalidArgumentException: Input "cat[0]" cannot take "11" as a value (possible values: 15).

/home/vagrant/Code/vendor/symfony/dom-crawler/Field/ChoiceFormField.php:136
/home/vagrant/Code/vendor/symfony/dom-crawler/FormFieldRegistry.php:128
/home/vagrant/Code/vendor/symfony/dom-crawler/Form.php:77
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:713
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:693
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:680
/home/vagrant/Code/tests/functional/InviteTest.php:109

当我第二次运行phpunit时,我收到2个错误,我收到一个新错误:

 LogicException: The selected node does not have a form ancestor.

There were 2 errors:

1) InviteTest::an_admin_may_invite_users_but_users_must_register_after
InvalidArgumentException: Input "cat[0]" cannot take "42" as a value (possible values: 46).

/home/vagrant/Code/vendor/symfony/dom-crawler/Field/ChoiceFormField.php:136
/home/vagrant/Code/vendor/symfony/dom-crawler/FormFieldRegistry.php:128
/home/vagrant/Code/vendor/symfony/dom-crawler/Form.php:77
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:713
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:693
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:680
/home/vagrant/Code/tests/functional/InviteTest.php:109

2) InviteTest::a_user_may_register_an_open_tournament
LogicException: The selected node does not have a form ancestor.

/home/vagrant/Code/vendor/symfony/dom-crawler/Form.php:379
/home/vagrant/Code/vendor/symfony/dom-crawler/Link.php:51
/home/vagrant/Code/vendor/symfony/dom-crawler/Form.php:51
/home/vagrant/Code/vendor/symfony/dom-crawler/Crawler.php:755
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:728
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:713
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:693
/home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php:680
/home/vagrant/Code/tests/functional/InviteTest.php:155

109行和155行是新闻动态(提交表格)

这是我的单元测试:

Here is my 2 tests: 


/** @test */
public function an_admin_may_invite_users_but_users_must_register_after()
{
    // Given
    $tournament = factory(Tournament::class)->create(['type' => 0]);
    $categoriesTournament = new Collection;
    for ($i = 0; $i < 5; $i++) {
        try {
            $categoriesTournament->push(factory(CategoryTournament::class)->create(['tournament_id' => $tournament->id]));
        } catch (Exception $e) {
        }
    }

    // Check that inviting one user by email
    $this->visit('/tournaments/' . $tournament->slug . '/invite/')
        ->type('["john@example.com","john2@example.com"]', 'recipients')// Must simulate js plugin
        ->press(trans('crud.send_invites'))
        ->seePageIs('/tournaments/' . $tournament->slug . '/edit')
        ->seeInDatabase('invitation',
            ['email' => 'john@example.com',
                'tournament_id' => $tournament->id,
                'expiration' => $tournament->registerDateLimit,
                'active' => 1,
                'used' => 0,
            ])
        ->seeInDatabase('invitation',
            ['email' => 'john2@example.com',
                'tournament_id' => $tournament->id,
                'expiration' => $tournament->registerDateLimit,
                'active' => 1,
                'used' => 0,
            ]);

    $invitation = Invite::where('tournament_id', $tournament->id)
        ->where('email', 'john@example.com')
        ->first();


    $user = User::where('email', 'john@example.com')->first();

    //Bad Code or no code
    $this->visit("/tournaments/" . $invitation->tournament->slug . "/invite/123456s")
        ->see("403");

    // Invitation expired
    if ($invitation->expiration < Carbon::now() && $invitation->expiration != '0000-00-00'){
        $this->see("403");
    }

    if ($invitation->active == 0){
        $this->see("403");
    }


    $this->visit("/tournaments/" . $invitation->tournament->slug. "/invite/" . $invitation->code);
    // If user didn't exit, check that it is created
    if (is_null($user)) {
        // System redirect to user creation
        $this->type('Johnny', 'name')
            ->type('11111111', 'password')
            ->type('11111111', 'password_confirmation')
            ->press(Lang::get('auth.create_account'))
            ->seeInDatabase('users', ['email' => 'john@example.com', 'verified' => '1'])
            ->see(trans('auth.registration_completed'));

    }

    // Get all categories for this tournament
    // Now we are on category Selection page

    foreach ($categoriesTournament as $key => $ct) {
        $this->type($ct->id, 'cat[' . $key . ']');
    }
    // Can't resolve: LogicException: The selected node does not have a form ancestor.

    $this->press(trans("core.save"));

    foreach ($categoriesTournament as $key => $ct) {
        $this->seeInDatabase('category_tournament_user',
            ['category_tournament_id' => $ct->id,
                'user_id' => Auth::user()->id,
            ]);
    }
    $this->seePageIs('/invites')
        ->see(htmlentities(Lang::get('core.operation_successful')));

}

/** @test */
public function a_user_may_register_an_open_tournament()
{
    Auth::logout();
    // Given
    $tournament = factory(Tournament::class)->create(['type' => 1]);
    $categoriesTournament = new Collection;

    for ($i = 0; $i < 5; $i++) {
        try {
            $categoriesTournament->push(factory(CategoryTournament::class)->create(['tournament_id' => $tournament->id]));
        } catch (QueryException $e) {
        } catch (PDOException $e) {
        }
    }
    $user = factory(User::class)->create(['email' => 'xoco@aaa.bbb2',
        'role_id' => 3,
        'password' => bcrypt('111111'), // 111111
    ]);

    $this->visit("/tournaments/" . $tournament->slug . "/register");

    // System redirect to user creation
    $this->type($user->email, 'email')
        ->type('111111', 'password')
        ->press(Lang::get('auth.signin'))
        ->seePageIs('/tournaments/' . $tournament->slug . '/register');

    // Get all categories for this tournament
    // Now we are on category Selection page
    foreach ($categoriesTournament as $key => $ct) {
        $this->type($ct->id, 'cat[' . $key . ']');
    }
    $this->press(trans("core.save"));
    foreach ($categoriesTournament as $key => $ct) {
        $this->seeInDatabase('category_tournament_user',
            ['category_tournament_id' => $ct->id,
                'user_id' => $user->id,
            ]);
    }
    $this->seePageIs('/invites')
        ->see(htmlentities(Lang::get('core.operation_successful')));
}

任何想法应该是什么原因????

如果需要,我可以附上我的控制器文件

0 个答案:

没有答案