Skip to content

Exercise testing utils #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2020
Merged

Exercise testing utils #189

merged 2 commits into from
Dec 6, 2020

Conversation

AydinHassan
Copy link
Member

So I've made this test case so we can test exercises more like integration tests rather than the messy tests we had for learn you php. So now the tests for the Match exercise look like this:

class AMatchMadeInHeavenTest extends WorkshopExerciseTest
{
    public function getApplication(): Application
    {
        return require __DIR__ . '/../../app/bootstrap.php';
    }

    public function getExerciseClass(): string
    {
        return AMatchMadeInHeaven::class;
    }

    public function testWithNoCode(): void
    {
        $this->runExercise('solution-no-code.php');

        $this->assertVerifyWasNotSuccessful();

        $this->assertResultsHasFailure(Failure::class, 'No code was found');
    }

    public function testWithNoMatch(): void
    {
        $this->runExercise('solution-no-match.php');

        $this->assertVerifyWasNotSuccessful();

        $this->assertResultsHasFailure(Failure::class, 'Match not found');
    }

    public function testWithSwitch(): void
    {
        $this->runExercise('solution-switch.php');

        $this->assertVerifyWasNotSuccessful();

        $this->assertResultsHasFailure(Failure::class, 'Switch found');
    }

    public function testWithNoMatchDefault(): void
    {
        $this->runExercise('solution-no-default.php');

        $this->assertVerifyWasNotSuccessful();

        $this->assertResultsHasFailure(Failure::class, 'Match default not found');
    }

    public function testWithIncorrectOutput(): void
    {
        $this->runExercise('solution-wrong-output.php');

        $this->assertVerifyWasNotSuccessful();

        $this->assertOutputWasIncorrect();
    }

    public function testWithCorrectSolution(): void
    {
        $this->runExercise('solution-correct.php');

        $this->assertVerifyWasSuccessful();
    }
}

@AydinHassan AydinHassan requested a review from mikeymike December 6, 2020 17:55
@codecov-io
Copy link

Codecov Report

Merging #189 (82f3b31) into master (84196ec) will decrease coverage by 2.73%.
The diff coverage is 13.88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #189      +/-   ##
============================================
- Coverage     95.58%   92.84%   -2.74%     
- Complexity      644      661      +17     
============================================
  Files            97       98       +1     
  Lines          1971     2041      +70     
============================================
+ Hits           1884     1895      +11     
- Misses           87      146      +59     
Impacted Files Coverage Δ Complexity Δ
src/Application.php 33.33% <0.00%> (-1.39%) 23.00 <12.00> (+1.00) ⬇️
src/TestUtils/WorkshopExerciseTest.php 0.00% <0.00%> (ø) 11.00 <11.00> (?)
src/ExerciseRepository.php 100.00% <100.00%> (ø) 13.00 <3.00> (+3.00)
src/Utils/ArrayObject.php 100.00% <100.00%> (+5.12%) 20.00 <3.00> (+2.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84196ec...82f3b31. Read the comment docs.

@AydinHassan AydinHassan merged commit 897f8f6 into master Dec 6, 2020
@AydinHassan AydinHassan deleted the exercise-testing-utils branch December 6, 2020 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants