Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Interesting testing utilities to add #3

@eduarguz

Description

@eduarguz

What kind of testing utils would you like to have in this package?

I have some utilities from courses, screencasts and some made by my own. Would they fit in a package like this?, later should be, how would they be added? given they are macros


  1. asserting a collection has an item
Collection::macro('assertContains', function ($value) {
    PHPUnit::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
});

$collection->assertContains($model)


  1. assert a collection has no item
Collection::macro('assertNotContains', function ($value) {
    PHPUnit::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
});

$collection->assertNotContains($model)


  1. Get data from a returned view
TestResponse::macro('getData', function ($key) {
    return $this->original->getData()[$key];
});

$response->getData('article')


  1. Assert response status is not Equal to.
TestResponse::macro('assertStatusNotEquals', function ($status) {
    $actual = $this->getStatusCode();

    PHPUnit::assertTrue(
        $actual != $status,
        "Expected status code different from {$status} but received {$actual}."
    );

    return $this;
});

$response->assertStatusNotEquals(200)


  1. Assert response location is not
TestResponse::macro('assertLocationDifferent', function ($uri) {
    PHPUnit::assertNotEquals(
        app('url')->to($uri),
        app('url')->to($this->headers->get('Location'))
    );

    return $this;
});

$response->assertRedirect()->assertLocationDifferent('/home')


Metadata

Metadata

Assignees

No one assigned

    Labels

    hacktoberfestGood issue for Hacktoberfest participants

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions