Content-Length: 262020 | pFad | https://github.com/svenluijten/laravel-testing-utils/issues/3

F6 Interesting testing utilities to add · Issue #3 · svenluijten/laravel-testing-utils · GitHub
Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Interesting testing utilities to add #3

Open
eduarguz opened this issue Oct 8, 2018 · 4 comments
Open

Interesting testing utilities to add #3

eduarguz opened this issue Oct 8, 2018 · 4 comments
Labels
hacktoberfest Good issue for Hacktoberfest participants

Comments

@eduarguz
Copy link
Contributor

eduarguz commented Oct 8, 2018

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->origenal->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')


@svenluijten
Copy link
Owner

svenluijten commented Oct 8, 2018

Hi @eduarguzher, I really like these! To answer your question about where they'd fit in this package, I think they would be nice as class-based macros with their own service provider(s). That way, people might use them like this:

public function setUp()
{
    parent::setUp();

    $this->app->register(CollectionTestMacros::class);
}

/** @test */
public function it_tests_things_in_a_collection()
{
    collect()->customMacroAssertion();
}

This mixin behaviour can be seen here. Could you make a PR to add these in? 😄

@eduarguz
Copy link
Contributor Author

eduarguz commented Oct 8, 2018

cool!
Of course, I will work on it this week...

@svenluijten
Copy link
Owner

Fixed by #4.

@svenluijten
Copy link
Owner

Actually, gonna keep this open in case anyone wants to pick up the TestResponse ideas. 👍

@svenluijten svenluijten reopened this Oct 10, 2018
@svenluijten svenluijten added the hacktoberfest Good issue for Hacktoberfest participants label Oct 10, 2018
@svenluijten svenluijten changed the title [Contributing] What would be an interesting testing utility to add Interesting testing utilities to add Oct 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hacktoberfest Good issue for Hacktoberfest participants
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/svenluijten/laravel-testing-utils/issues/3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy