Skip to content
Snippets Groups Projects
Verified Commit 16a35fc5 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

test: assert correct migrations order

parent 5066f6b8
Branches
Tags
No related merge requests found
<?php
namespace WPDesk\Migrations\Tests;
use Psr\Log\NullLogger;
use WPDesk\Migrations\FilesystemMigrationsRepository;
use PHPUnit\Framework\TestCase;
use WPDesk\Migrations\Finder\GlobFinder;
use WPDesk\Migrations\Version\AlphabeticalComparator;
use WPDesk\Migrations\Version\WpdbMigrationFactory;
class FilesystemMigrationsRepositoryTest extends TestCase {
public function test_migrations_sorted() {
$migration_directories = [
__DIR__ . '/../../../fixtures/migrations'
];
$migrations_repository = new FilesystemMigrationsRepository(
$migration_directories,
new GlobFinder(),
new WpdbMigrationFactory(
new \wpdb(),
new NullLogger()
),
new AlphabeticalComparator()
);
$sorted_migrations = $migrations_repository->get_migrations();
self::assertEquals(
(string) $sorted_migrations[0]->get_version(),
'WPDesk\Migrations\Tests\fixtures\migrations\Version_10'
);
self::assertEquals(
(string) $sorted_migrations[1]->get_version(),
'WPDesk\Migrations\Tests\fixtures\migrations\Version_11'
);
}
}
<?php
namespace WPDesk\Migrations\Tests\Version;
use PHPUnit\Framework\TestCase;
use WPDesk\Migrations\Version\AlphabeticalComparator;
use WPDesk\Migrations\Version\Version;
class AlphabeticalComparatorTest extends TestCase {
public function test_10_is_less_than_11() {
$comparator = new AlphabeticalComparator();
$result = $comparator->compare(
new Version('Version_10'),
new Version('Version_11')
);
self::assertTrue($result === -1);
$result = $comparator->compare(
new Version('Version_11'),
new Version('Version_10')
);
self::assertTrue($result === 1);
$result = $comparator->compare(
new Version('Version_10'),
new Version('Version_10')
);
self::assertTrue($result === 0);
}
}
<?php
require __DIR__ . '/../vendor/autoload.php';
<?php
declare( strict_types=1 );
namespace WPDesk\Migrations\Tests\fixtures\migrations;
class Version_10 extends \WPDesk\Migrations\AbstractMigration {
public function up(): bool {
return true;
}
}
<?php
declare( strict_types=1 );
namespace WPDesk\Migrations\Tests\fixtures\migrations;
class Version_11 extends \WPDesk\Migrations\AbstractMigration {
public function up(): bool {
return true;
}
}
<?php
declare( strict_types=1 );
class wpdb {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment