2018-01-16 21:26:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Database\Migration;
|
|
|
|
|
2018-09-16 00:58:25 +02:00
|
|
|
use Engelsystem\Database\Database;
|
2018-01-16 21:26:59 +01:00
|
|
|
use Engelsystem\Database\Migration\Migrate;
|
|
|
|
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
|
|
|
use Illuminate\Database\Connection;
|
|
|
|
use Illuminate\Database\Schema\Builder as SchemaBuilder;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-01-16 21:26:59 +01:00
|
|
|
|
|
|
|
class MigrationServiceProviderTest extends ServiceProviderTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Database\Migration\MigrationServiceProvider::register()
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testRegister(): void
|
2018-01-16 21:26:59 +01:00
|
|
|
{
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var Migrate|MockObject $migration */
|
2018-01-16 21:26:59 +01:00
|
|
|
$migration = $this->getMockBuilder(Migrate::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-09-16 00:58:25 +02:00
|
|
|
/** @var Database|MockObject $database */
|
|
|
|
$database = $this->getMockBuilder(Database::class)
|
2018-01-16 21:26:59 +01:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var Connection|MockObject $dbConnection */
|
2018-01-16 21:26:59 +01:00
|
|
|
$dbConnection = $this->getMockBuilder(Connection::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2019-04-24 10:45:00 +02:00
|
|
|
/** @var SchemaBuilder|MockObject $schemaBuilder */
|
2018-01-16 21:26:59 +01:00
|
|
|
$schemaBuilder = $this->getMockBuilder(SchemaBuilder::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2018-09-16 00:58:25 +02:00
|
|
|
$app = $this->getApp(['make', 'instance', 'bind', 'get']);
|
2018-01-16 21:26:59 +01:00
|
|
|
|
|
|
|
$app->expects($this->atLeastOnce())
|
|
|
|
->method('instance')
|
2018-09-16 00:58:25 +02:00
|
|
|
->withConsecutive(['db.schema'], ['db.migration'])
|
2018-01-16 21:26:59 +01:00
|
|
|
->willReturnOnConsecutiveCalls($schemaBuilder, $migration);
|
|
|
|
|
2018-09-16 00:58:25 +02:00
|
|
|
$this->setExpects($app, 'bind', [SchemaBuilder::class, 'db.schema']);
|
2018-01-16 21:26:59 +01:00
|
|
|
$this->setExpects($app, 'make', [Migrate::class], $migration);
|
2018-09-16 00:58:25 +02:00
|
|
|
$this->setExpects($app, 'get', [Database::class], $database);
|
2018-01-16 21:26:59 +01:00
|
|
|
|
|
|
|
$this->setExpects($dbConnection, 'getSchemaBuilder', null, $schemaBuilder);
|
2018-09-16 00:58:25 +02:00
|
|
|
$this->setExpects($database, 'getConnection', null, $dbConnection);
|
2018-01-16 21:26:59 +01:00
|
|
|
|
|
|
|
$serviceProvider = new MigrationServiceProvider($app);
|
|
|
|
$serviceProvider->register();
|
|
|
|
}
|
|
|
|
}
|