Refactoring Test Methods

Posted 5 months ago by xtremer360

I'm trying to clean up some old code from a project and trying to figure out some ideas on renaming the test functions in a better way so that I nor others have to scratch their head to try to understand what I'm attempting to do. Also any suggestions on if there are areas in the test that I could modify.

/** @test */
    public function a_non_title_match_can_set_a_winner()
    {
        $wrestlerA = factory(Wrestler::class)->create();
        $wrestlerB = factory(Wrestler::class)->create();
        $match->addWrestlers([
            0 => [$wrestlerA],
            1 => [$wrestlerB]
        ]);

        $this->match->setWinner($wrestlerA, 'pinfall');

        $this->assertEquals($wrestlerA->id, $this->match->winner_id);
        $this->assertEquals($wrestlerB->id, $this->match->loser_id);
    }

    /** @test */
    public function a_title_match_champion_can_be_set_as_winner()
    {
        $wrestlerA = factory(Wrestler::class)->create();
        $title = factory(Title::class)->create();
        $title->setChampion($wrestlerA, Carbon::parse('2018-03-03'));

        $event = factory(Event::class)->create(['date' => '2018-03-05']);
        $match = factory(Match::class)->create(['event_id' => $event->id]);
        $wrestlerB = factory(Wrestler::class)->create();
        $match->addWrestlers([
            0 => [$wrestlerA],
            1 => [$wrestlerB]
        ]);
        $match->addTitle($title);

        $match->setWinner($wrestlerA, 'dq');

        $this->assertEquals($wrestlerA->id, $match->winner_id);
        $this->assertEquals($wrestlerB->id, $match->loser_id);
        $this->assertEquals($wrestlerA, $title->currentChampion);
    }

    /** @test */
    public function a_title_changes_hands_when_a_non_champion_wins_a_title_match()
    {
        $wrestlerA = factory(Wrestler::class)->create(['name' => 'Wrestler A']);
        $title = factory(Title::class)->create();
        $title->setChampion($wrestlerA, Carbon::parse('2018-03-03'));

        $event = factory(Event::class)->create(['date' => Carbon::parse('2018-03-05')]);
        $match = factory(Match::class)->create(['event_id' => $event->id]);
        $wrestlerB = factory(Wrestler::class)->create(['name' => 'Wrestler B']);
        $match->addWrestlers([
            0 => [$wrestlerA],
            1 => [$wrestlerB]
        ]);
        $match->addTitle($title);

        $match->setWinner($wrestlerB, 'pinfall');

        $title->refresh();
        $this->assertEquals($wrestlerB->id, $match->winner_id);
        $this->assertEquals($wrestlerA->id, $match->loser_id);
        $this->assertEquals($wrestlerB->id, $title->currentChampion->id);
    }

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.