illuminated / testing-tools
Laravel-specific Testing Helpers and Assertions.
Installs: 17 528
Dependents: 20
Suggesters: 0
Security: 0
Stars: 54
Watchers: 3
Forks: 7
Open Issues: 0
Requires
- php: ^8.1
- illuminate/database: ^10.0
- illuminate/support: ^10.0
- mockery/mockery: ^1.5.1
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.5
- dev-master
- 10.x-dev
- 10.0.0
- 9.x-dev
- 9.6.0
- 9.5.0
- 9.4.0
- 9.3.0
- 9.2.0
- 9.1.0
- 9.0.0
- 8.x-dev
- 8.1.0
- 8.0.0
- 7.x-dev
- 7.1.0
- 7.0.0
- 6.x-dev
- 6.2.0
- 6.1.0
- 6.0.0
- 5.8.x-dev
- 5.8.0
- 5.7.x-dev
- 5.7.4
- 5.7.3
- 5.7.2
- 5.7.1
- 5.7.0
- 5.6.x-dev
- 5.6.4
- 5.6.3
- 5.6.2
- 5.6.1
- 5.6.0
- 5.5.x-dev
- 5.5.5
- 5.5.4
- 5.5.3
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.x-dev
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.x-dev
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.x-dev
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.x-dev
- 5.1.2
- 5.1.1
- 5.1.0
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-11-06 17:07:44 UTC
README
Laravel Testing Tools
Laravel-specific Testing Helpers and Assertions.
Usage
-
Install the package via Composer:
composer require --dev illuminated/testing-tools
-
Use
Illuminated\Testing\TestingTools
trait:use Illuminated\Testing\TestingTools; abstract class TestCase extends Illuminate\Foundation\Testing\TestCase { use TestingTools; // ... }
-
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
License
Laravel Testing Tools is open-sourced software licensed under the MIT license.