diff --git a/tests/WPDesk/Migrations/Tests/FilesystemMigrationsRepositoryTest.php b/tests/WPDesk/Migrations/Tests/FilesystemMigrationsRepositoryTest.php new file mode 100644 index 0000000000000000000000000000000000000000..58187d75baf4ea6e67d988f4f98b63e5fa619358 --- /dev/null +++ b/tests/WPDesk/Migrations/Tests/FilesystemMigrationsRepositoryTest.php @@ -0,0 +1,39 @@ +<?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' + ); + } + +} diff --git a/tests/WPDesk/Migrations/Tests/Version/AlphabeticalComparatorTest.php b/tests/WPDesk/Migrations/Tests/Version/AlphabeticalComparatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c3fa37e85e9faac54be77bf2fe06e1a80fe33890 --- /dev/null +++ b/tests/WPDesk/Migrations/Tests/Version/AlphabeticalComparatorTest.php @@ -0,0 +1,35 @@ +<?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); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..d21c14df8c2f4146f27fe949921b94780621e229 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ +<?php + +require __DIR__ . '/../vendor/autoload.php'; diff --git a/tests/fixtures/migrations/Version_10.php b/tests/fixtures/migrations/Version_10.php new file mode 100644 index 0000000000000000000000000000000000000000..ed8011d401ece6c6458882f5f864c1522a0e686d --- /dev/null +++ b/tests/fixtures/migrations/Version_10.php @@ -0,0 +1,11 @@ +<?php +declare( strict_types=1 ); + +namespace WPDesk\Migrations\Tests\fixtures\migrations; + +class Version_10 extends \WPDesk\Migrations\AbstractMigration { + + public function up(): bool { + return true; + } +} diff --git a/tests/fixtures/migrations/Version_11.php b/tests/fixtures/migrations/Version_11.php new file mode 100644 index 0000000000000000000000000000000000000000..d1c5a269ae51d1125cb79b61a4bdaa544a9a2b12 --- /dev/null +++ b/tests/fixtures/migrations/Version_11.php @@ -0,0 +1,11 @@ +<?php +declare( strict_types=1 ); + +namespace WPDesk\Migrations\Tests\fixtures\migrations; + +class Version_11 extends \WPDesk\Migrations\AbstractMigration { + + public function up(): bool { + return true; + } +} diff --git a/tests/stubs/wpdb.php b/tests/stubs/wpdb.php new file mode 100644 index 0000000000000000000000000000000000000000..3fd492e364f1f91d936d727b102a671d6d3ba836 --- /dev/null +++ b/tests/stubs/wpdb.php @@ -0,0 +1,6 @@ +<?php +declare( strict_types=1 ); + +class wpdb { + +}