-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
111 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
|
||
namespace dbmigrate; | ||
|
||
|
||
use dbmigrate\application\MigrationDirectoryValidator; | ||
use dbmigrate\application\MigrationFileScanner; | ||
use dbmigrate\application\Planner; | ||
use dbmigrate\application\sql\LoadMigrations; | ||
use dbmigrate\application\sql\SqlFile; | ||
|
||
class MigrateDryRun | ||
{ | ||
/** @var \PDO */ | ||
private $pdo; | ||
|
||
/** @var \SplFileInfo */ | ||
private $sqlDirectory; | ||
|
||
public function __construct(\PDO $pdo, \SplFileInfo $sqlDirectory) | ||
{ | ||
if ($pdo === null) { | ||
throw new \InvalidArgumentException("PDO may not be null"); | ||
} | ||
|
||
(new MigrationDirectoryValidator())->assertValidMigrationFileDirectory($sqlDirectory); | ||
|
||
$this->pdo = $pdo; | ||
$this->sqlDirectory = $sqlDirectory; | ||
} | ||
|
||
/** @return SqlFile[] */ | ||
public function __invoke() | ||
{ | ||
$fileScanner = new MigrationFileScanner($this->sqlDirectory); | ||
$loadMigrations = new LoadMigrations($this->pdo); | ||
|
||
return (new Planner($fileScanner, $loadMigrations))->findMigrationsToInstall(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
|
||
namespace dbmigrate\application; | ||
|
||
|
||
class MigrationDirectoryValidator | ||
{ | ||
public function assertValidMigrationFileDirectory(\SplFileInfo $sqlDirectory) | ||
{ | ||
if($sqlDirectory===null) { | ||
throw new \InvalidArgumentException("sqlDirectory may not be null"); | ||
} | ||
|
||
if(!$sqlDirectory->isDir() || !is_readable($sqlDirectory->getPathname())) { | ||
throw new \InvalidArgumentException("sqlDirectory ".$sqlDirectory->getPathname()." does not exist or is not readable"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
|
||
namespace dbmigrate; | ||
|
||
|
||
use dbmigrate\application\MigrationException; | ||
use dbmigrate\application\schema\Migration; | ||
use dbmigrate\application\sql\LoadMigrations; | ||
use dbmigrate\application\sql\SqlFile; | ||
use dbmigrate\testutil\IntegrationDatabase; | ||
|
||
class MigrateDryRunIntegrationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use IntegrationDatabase; | ||
|
||
|
||
public function testInitializeFromEmptySchema() | ||
{ | ||
$pdo = $this->aNewInitializedSchema(); | ||
|
||
$sqlDirectory = new \SplFileInfo(__DIR__ . "/../testsets/nummericsorting"); | ||
|
||
$files = call_user_func(new MigrateDryRun($pdo, $sqlDirectory)); | ||
|
||
$this->assertEquals([ | ||
new SqlFile(new \SplFileInfo($sqlDirectory->getPathname()."/v3_test.sql")), | ||
new SqlFile(new \SplFileInfo($sqlDirectory->getPathname()."/v10_test.sql")) | ||
], $files); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters