Giter Site home page Giter Site logo

dmitry-ivanov / laravel-testing-tools Goto Github PK

View Code? Open in Web Editor NEW
53.0 3.0 6.0 825 KB

Laravel-specific Testing Helpers and Assertions.

License: MIT License

PHP 100.00%
laravel laravel-package testing tools helpers assertions assertion-methods assertion-functions

laravel-testing-tools's Introduction

Laravel-specific Testing Helpers and Assertions

Laravel Testing Tools

Buy me a coffee

StyleCI Build Status Coverage Status

Packagist Version Packagist Stars Packagist Downloads Packagist License

Laravel-specific Testing Helpers and Assertions.

Laravel Testing Tools
11.x Support โ˜•
10.x 10.x
9.x 9.x
8.x 8.x
7.x 7.x
6.x 6.x
5.8.* 5.8.*
5.7.* 5.7.*
5.6.* 5.6.*
5.5.* 5.5.*
5.4.* 5.4.*
5.3.* 5.3.*
5.2.* 5.2.*
5.1.* 5.1.*

Usage

  1. Install the package via Composer:

    composer require --dev illuminated/testing-tools
  2. Use Illuminated\Testing\TestingTools trait:

    use Illuminated\Testing\TestingTools;
    
    abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
    {
        use TestingTools;
    
        // ...
    }
  3. Use any of the provided helpers and assertions in your tests:

    class ExampleTest extends TestCase
    {
        /** @test */
        public function it_has_lots_of_useful_assertions()
        {
            $this->assertDatabaseHasMany('posts', [
                ['title' => 'Awesome!'],
                ['title' => 'Check multiple rows'],
                ['title' => 'In one simple assertion ๐ŸคŸ'],
            ]);
        }
    }

Available helpers

Feel free to contribute.

Available assertions

Feel free to contribute.

Helpers

ApplicationHelpers

emulateLocal()

Emulate that application is running on the local environment:

$this->emulateLocal();

emulateProduction()

Emulate that application is running on the production environment:

$this->emulateProduction();

emulateEnvironment()

Emulate that application is running on the given environment:

$this->emulateEnvironment('demo');

Assertions

CollectionAsserts

assertCollectionsEqual()

Assert that the given collections are equal based on the specified key:

$this->assertCollectionsEqual($collection1, $collection2, 'id');

assertCollectionsNotEqual()

Assert that the given collections are not equal based on the specified key:

$this->assertCollectionsNotEqual($collection1, $collection2, 'id');

DatabaseAsserts

assertDatabaseHasTable()

Assert that the database has the given table:

$this->assertDatabaseHasTable('users');

assertDatabaseMissingTable()

Assert that the database doesn't have the given table:

$this->assertDatabaseMissingTable('unicorns');

assertDatabaseHasMany()

Assert that the database has all the given rows:

$this->assertDatabaseHasMany('posts', [
    ['title' => 'First Post'],
    ['title' => 'Second Post'],
    ['title' => 'Third Post'],
]);

assertDatabaseMissingMany()

Assert that the database doesn't have all the given rows:

$this->assertDatabaseMissingMany('posts', [
    ['title' => 'Fourth Post'],
    ['title' => 'Fifth Post'],
]);

FilesystemAsserts

assertDirectoryEmpty()

Assert that the given directory is empty:

$this->assertDirectoryEmpty('./my/dir/');

assertDirectoryNotEmpty()

Assert that the given directory is not empty:

$this->assertDirectoryNotEmpty('./my/dir/');

assertFilesCount()

Assert that directory has the given number of files:

$this->assertFilesCount('./my/dir/', 3);

assertNotFilesCount()

Assert that directory doesn't have the given number of files:

$this->assertNotFilesCount('./my/dir/', 5);

LogFileAsserts

seeLogFile()

Assert that the given log file exists.

The path is relative to the storage/logs folder:

$this->seeLogFile('example.log');

dontSeeLogFile()

Assert that the given log file doesn't exist.

The path is relative to the storage/logs folder:

$this->dontSeeLogFile('foobarbaz.log');

seeInLogFile()

Assert that the log file contains the given message.

The path is relative to the storage/logs folder:

$this->seeInLogFile('example.log', 'Sample log message!');

Also, you can specify an array of messages:

$this->seeInLogFile('example.log', [
    'Sample log message 1!',
    'Sample log message 2!',
    'Sample log message 3!',
]);

You can use these placeholders in messages:

  • %datetime% - any datetime string.
$this->seeInLogFile('example.log', '[%datetime%]: Sample log message!');

dontSeeInLogFile()

Assert that the log file doesn't contain the given message.

The path is relative to the storage/logs folder:

$this->dontSeeInLogFile('example.log', 'Non-existing log message!');

Also, you can specify an array of messages:

$this->dontSeeInLogFile('example.log', [
    'Non-existing log message 1!',
    'Non-existing log message 2!',
    'Non-existing log message 3!',
]);

ScheduleAsserts

seeScheduleCount()

Assert that schedule count equals to the given value:

$this->seeScheduleCount(3);

dontSeeScheduleCount()

Assert that schedule count doesn't equal to the given value:

$this->dontSeeScheduleCount(5);

seeInSchedule()

Assert that the given command is scheduled:

$this->seeInSchedule('foo', 'everyFiveMinutes');
$this->seeInSchedule('bar', 'hourly');
$this->seeInSchedule('baz', 'twiceDaily');

Also, you can use cron expressions:

$this->seeInSchedule('foo', '*/5 * * * * *');
$this->seeInSchedule('bar', '0 * * * * *');
$this->seeInSchedule('baz', '0 1,13 * * * *');

dontSeeInSchedule()

Assert that the given command is not scheduled:

$this->dontSeeInSchedule('foobarbaz');

Sponsors

Laravel Idea
Material Theme UI Plugin

License

Laravel Testing Tools is open-sourced software licensed under the MIT license.

Buy me a coffeeย 

laravel-testing-tools's People

Contributors

dmitry-ivanov avatar mihan007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-testing-tools's Issues

Laravel 8.x support

Follow these steps:

Please, note that we have to update versions for everything, not only illuminate packages.

  1. Update versions in composer.json according to Laravel's composer.json.
  2. Add the newly supported version to README.md.
  3. Open PR to the master branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.