PHP code example of endeavour-agency / laravel-migration-tests
1. Go to this page and download the library: Download endeavour-agency/laravel-migration-tests library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
endeavour-agency / laravel-migration-tests example snippets
declare(strict_types=1);
namespace Tests\Migrations;
use EndeavourAgency\LaravelMigrationTests\Traits\TestsLaravelMigrationsTrait;
use Illuminate\Foundation\Testing\TestCase;
use PHPUnit\Framework\Attributes\Test;
class ExampleMigrationTest extends TestCase
{
use TestsLaravelMigrationsTrait;
#[Test]
public function it_tests_a_migration_using_the_test_migration_method(): void
{
$this->testMigration(
'2024_05_29_083854_rename_birth_day_column_to_date_of_birth_on_users_table',
setup: function () {
// Setup
DB::table('users')->insert([
'id' => 15,
'email' => '[email protected]',
'birth_day' => '1990-02-01',
]);
},
tests: function () {
// Tests
static::assertDatabaseHas('users', [
'id' => 15,
'date_of_birth' => '1990-02-01',
]);
}
);
}
#[Test]
public function it_tests_a_migration_using_convenience_methods(): void
{
$this->runMigrationsBefore('2024_05_29_083854_rename_birth_day_column_to_date_of_birth_on_users_table');
// Setup
DB::table('users')->insert([
'id' => 15,
'email' => '[email protected]',
'birth_day' => '1990-02-01',
]);
$this->runNextMigration();
// Tests
static::assertDatabaseHas('users', [
'id' => 15,
'date_of_birth' => '1990-02-01',
]);
}
}