sven/laravel-testing-utils

This package is abandoned and no longer maintained. No replacement package was suggested.

v1.4.0 2019-12-14 15:07 UTC

This package is auto-updated.

Last update: 2021-01-21 11:16:58 UTC


README

laravel-testing-utils

Laravel Testing Utils

Latest Version on Packagist Total Downloads Software License Build Status StyleCI PhpStan

This package adds various Laravel-related assertions so you won't have to write them yourself in every new application.

Index

Installation

You will have to follow a couple of steps to install this package.

Downloading

Via Composer:

$ composer require sven/laravel-testing-utils:^1.0 --dev

Or add the package to your development dependencies in composer.json and run composer update on the command line to download the package:

{
    "require-dev": {
        "sven/laravel-testing-utils": "^1.0"
    }
}

Usage

You will now have access to several traits and macros to use in your test classes.

InteractsWithViews

This trait adds several view-related assertions. They are used as follows:

<?php

use Sven\LaravelTestingUtils\InteractsWithViews;
use Illuminate\Foundation\Testing\TestCase;

class ServiceTest extends TestCase
{
    use InteractsWithViews;

    /** @test */
    public function it_creates_a_view()
    {
        // ...
        
        $this->assertViewExists('some.view-file');
    }
    
    /** @test */
    public function it_does_not_create_a_view()
    {
        // ...
        
        $this->assertViewNotExists('some.view-file');
    }
    
    /** @test */
    public function the_view_equals()
    {
        // ...
        
        $this->assertViewEquals('The Expected Contents', 'index');
    }
    
    /** @test */
    public function the_view_does_not_equal()
    {
        // ...
        
        $this->assertViewNotEquals('This Is Not The Content You\'re Looking For', 'index');
    }
}

TestCollectionMacros

This set of macros adds some assertions to Laravel collections: assertContains and assertNotContains. They are used as follows:

<?php

use Sven\LaravelTestingUtils\Collections\TestCollectionMacros;
use Illuminate\Foundation\Testing\TestCase;

class ServiceTest extends TestCase
{
    protected function setUp()
    {
        parent::setUp();
        TestCollectionMacros::enable();
    }
        
    /** @test */
    public function it_fetches_some_data()
    {
        // ...
        
        $collection->assertContains('some-item');
        $collection->assertNotContains('some-other-item');
    }
}

Contributing

All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors.

License

sven/laravel-testing-utils is licensed under the MIT License (MIT). Please see the license file for more information.