-
Notifications
You must be signed in to change notification settings - Fork 5
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
172 additions
and
23 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
144 changes: 144 additions & 0 deletions
144
testing/unit/Infrastructure/Migration/MigrationTest.php
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,144 @@ | ||
<?php | ||
|
||
namespace Honeybee\Tests\Infrastructure\Migration; | ||
|
||
use Honeybee\Infrastructure\Migration\Migration; | ||
use Honeybee\Infrastructure\Migration\MigrationInterface; | ||
use Honeybee\Infrastructure\Migration\MigrationTargetInterface; | ||
use Honeybee\Tests\TestCase; | ||
use Mockery; | ||
use Honeybee\Infrastructure\DataAccess\Connector\ConnectorInterface; | ||
|
||
class MigrationTest extends TestCase | ||
{ | ||
public function testGetNameNull() | ||
{ | ||
$mock_migration = Mockery::mock(Migration::CLASS)->makePartial(); | ||
$this->assertNull($mock_migration->getName()); | ||
} | ||
|
||
public function testGetName() | ||
{ | ||
$mock_migration = Mockery::mock(Migration::CLASS, [['name' => 'mock_migration']])->makePartial(); | ||
$this->assertEquals('mock_migration', $mock_migration->getName()); | ||
} | ||
|
||
public function testGetVersionNull() | ||
{ | ||
$mock_migration = Mockery::mock(Migration::CLASS)->makePartial(); | ||
$this->assertNull($mock_migration->getVersion()); | ||
} | ||
|
||
public function testGetVersion() | ||
{ | ||
$mock_migration = Mockery::mock(Migration::CLASS, [['version' => '2020']])->makePartial(); | ||
$this->assertEquals('2020', $mock_migration->getVersion()); | ||
} | ||
|
||
/** | ||
* @expectedException Honeybee\Common\Error\RuntimeError | ||
*/ | ||
public function testGetTimestampInvalid() | ||
{ | ||
$mock_migration = Mockery::namedMock('InvalidMock', Migration::CLASS)->makePartial(); | ||
$mock_migration->getTimestamp(); | ||
} | ||
|
||
public function testGetTimestamp() | ||
{ | ||
$mock_migration = Mockery::namedMock('Migration_12345678901234', Migration::CLASS)->makePartial(); | ||
$this->assertEquals('12345678901234', $mock_migration->getTimestamp()); | ||
} | ||
|
||
public function testGetConnection() | ||
{ | ||
$mock_migration = Mockery::mock(Migration::CLASS)->makePartial(); | ||
$mock_connection = new \stdClass; | ||
$mock_connector = Mockery::mock(ConnectorInterface::CLASS); | ||
$mock_connector->shouldReceive('getConnection')->once()->withNoArgs()->andReturn($mock_connection); | ||
$mock_migration_target = Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('getTargetConnector')->once()->withNoArgs()->andReturn($mock_connector); | ||
$this->assertSame($mock_connection, $mock_migration->getConnection($mock_migration_target)); | ||
} | ||
|
||
/** | ||
* @expectedException Honeybee\Common\Error\RuntimeError | ||
*/ | ||
public function testMigrateGuardInactive() | ||
{ | ||
$mock_migration = Mockery::mock( | ||
Migration::CLASS, | ||
[['name' => 'mock_migration', 'version' => '20201234567890']] | ||
)->makePartial(); | ||
$mock_migration_target= Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('isActivated')->once()->withNoArgs()->andReturnFalse(); | ||
$mock_migration_target->shouldReceive('getName')->once()->withNoArgs()->andReturn('mock_target'); | ||
$mock_migration->migrate($mock_migration_target); | ||
} //@codeCoverageIgnore | ||
|
||
/** | ||
* @expectedException Honeybee\Common\Error\RuntimeError | ||
*/ | ||
public function testMigrateGuardDirection() | ||
{ | ||
$mock_migration = Mockery::mock( | ||
Migration::CLASS, | ||
[['name' => 'mock_migration', 'version' => '20201234567890']] | ||
)->makePartial(); | ||
$mock_migration_target= Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('isActivated')->once()->withNoArgs()->andReturnTrue(); | ||
$mock_migration->migrate($mock_migration_target, 'invalid'); | ||
} //@codeCoverageIgnore | ||
|
||
/** | ||
* @expectedException Honeybee\Common\Error\RuntimeError | ||
*/ | ||
public function testMigrateGuardReversal() | ||
{ | ||
$mock_migration = Mockery::mock( | ||
Migration::CLASS, | ||
[['name' => 'mock_migration', 'version' => '20201234567890']] | ||
)->makePartial(); | ||
$mock_migration->shouldReceive('isReversible')->once()->withNoArgs()->andReturnFalse(); | ||
$mock_migration_target= Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('isActivated')->once()->withNoArgs()->andReturnTrue(); | ||
$mock_migration->migrate($mock_migration_target, 'down'); | ||
} //@codeCoverageIgnore | ||
|
||
public function testMigrateUp() | ||
{ | ||
$mock_migration = Mockery::mock( | ||
Migration::CLASS, | ||
[['name' => 'mock_migration', 'version' => '20201234567890']] | ||
)->makePartial(); | ||
$mock_migration_target= Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('isActivated')->once()->withNoArgs()->andReturnTrue(); | ||
$mock_migration_target->shouldReceive('bumpStructureVersion')->once()->with( | ||
Mockery::on(function (MigrationInterface $migration) use ($mock_migration) { | ||
$this->assertSame($mock_migration, $migration); | ||
return true; | ||
}), | ||
'up' | ||
)->andReturnNull(); | ||
$mock_migration->migrate($mock_migration_target, 'up'); | ||
} | ||
|
||
public function testMigrateDown() | ||
{ | ||
$mock_migration = Mockery::mock( | ||
Migration::CLASS, | ||
[['name' => 'mock_migration', 'version' => '20201234567890']] | ||
)->makePartial(); | ||
$mock_migration->shouldReceive('isReversible')->once()->withNoArgs()->andReturnTrue(); | ||
$mock_migration_target= Mockery::mock(MigrationTargetInterface::CLASS); | ||
$mock_migration_target->shouldReceive('isActivated')->once()->withNoArgs()->andReturnTrue(); | ||
$mock_migration_target->shouldReceive('bumpStructureVersion')->once()->with( | ||
Mockery::on(function (MigrationInterface $migration) use ($mock_migration) { | ||
$this->assertSame($mock_migration, $migration); | ||
return true; | ||
}), | ||
'down' | ||
)->andReturnNull(); | ||
$mock_migration->migrate($mock_migration_target, 'down'); | ||
} | ||
} |