This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
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
4 changed files
with
144 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendDiagnostics\Check; | ||
|
||
use Doctrine\DBAL\Migrations\Configuration\Configuration; | ||
use ZendDiagnostics\Result\Failure; | ||
use ZendDiagnostics\Result\ResultInterface; | ||
use ZendDiagnostics\Result\Success; | ||
|
||
class DoctrineMigration extends AbstractCheck | ||
{ | ||
/** | ||
* @var Configuration | ||
*/ | ||
private $migrationConfiguration; | ||
|
||
/** | ||
* @param Configuration $migrationConfiguration | ||
*/ | ||
public function __construct(Configuration $migrationConfiguration) | ||
{ | ||
$this->migrationConfiguration = $migrationConfiguration; | ||
} | ||
|
||
/** | ||
* Perform the actual check and return a ResultInterface | ||
* | ||
* @return ResultInterface | ||
*/ | ||
public function check() | ||
{ | ||
$availableVersions = $this->migrationConfiguration->getAvailableVersions(); | ||
$migratedVersions = $this->migrationConfiguration->getMigratedVersions(); | ||
|
||
$notMigratedVersions = array_diff($availableVersions, $migratedVersions); | ||
if (!empty($notMigratedVersions)) { | ||
return new Failure('Not all migrations applied', $notMigratedVersions); | ||
} | ||
|
||
$notAvailableVersion = array_diff($migratedVersions, $availableVersions); | ||
if (!empty($notAvailableVersion)) { | ||
return new Failure('Migrations applied which are not available', $notMigratedVersions); | ||
} | ||
|
||
return new Success(); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
|
||
namespace ZendDiagnosticsTest; | ||
|
||
use ZendDiagnostics\Check\DoctrineMigration; | ||
|
||
class DoctrineMigrationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testEverythingMigrated() | ||
{ | ||
$configuration = $this->getMockBuilder('Doctrine\DBAL\Migrations\Configuration\Configuration') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getAvailableVersions') | ||
->will($this->returnValue(array('Version1', 'Version2'))); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getMigratedVersions') | ||
->will($this->returnValue(array('Version1', 'Version2'))); | ||
|
||
$check = new DoctrineMigration($configuration); | ||
$result = $check->check(); | ||
|
||
$this->assertInstanceof('ZendDiagnostics\Result\SuccessInterface', $result); | ||
} | ||
|
||
public function testNotAllMigrationsMigrated() | ||
{ | ||
$configuration = $this->getMockBuilder('Doctrine\DBAL\Migrations\Configuration\Configuration') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getAvailableVersions') | ||
->will($this->returnValue(array('Version1', 'Version2'))); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getMigratedVersions') | ||
->will($this->returnValue(array('Version1'))); | ||
|
||
$check = new DoctrineMigration($configuration); | ||
$result = $check->check(); | ||
|
||
$this->assertInstanceof('ZendDiagnostics\Result\FailureInterface', $result); | ||
} | ||
|
||
public function testNoExistingMigrationMigrated() | ||
{ | ||
$configuration = $this->getMockBuilder('Doctrine\DBAL\Migrations\Configuration\Configuration') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getAvailableVersions') | ||
->will($this->returnValue(array('Version1'))); | ||
|
||
$configuration | ||
->expects($this->once()) | ||
->method('getMigratedVersions') | ||
->will($this->returnValue(array('Version1', 'Version2'))); | ||
|
||
$check = new DoctrineMigration($configuration); | ||
$result = $check->check(); | ||
|
||
$this->assertInstanceof('ZendDiagnostics\Result\FailureInterface', $result); | ||
} | ||
} |