Fix/Cleanup tests for DatabaseServiceProvider
This commit is contained in:
parent
9921c5002a
commit
af09865f3d
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Feature\Database;
|
namespace Engelsystem\Test\Feature\Database;
|
||||||
|
|
||||||
use Engelsystem\Application;
|
|
||||||
use Engelsystem\Config\Config;
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Database\Database;
|
||||||
use Engelsystem\Database\DatabaseServiceProvider;
|
use Engelsystem\Database\DatabaseServiceProvider;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
|
||||||
|
|
||||||
class DatabaseServiceProviderTest extends DatabaseTest
|
class DatabaseServiceProviderTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
|
@ -14,27 +13,13 @@ class DatabaseServiceProviderTest extends DatabaseTest
|
||||||
*/
|
*/
|
||||||
public function testRegister()
|
public function testRegister()
|
||||||
{
|
{
|
||||||
/** @var Config|MockObject $config */
|
$this->app->instance('config', new Config([
|
||||||
$config = $this->getMockBuilder(Config::class)
|
'database' => $this->getDbConfig(),
|
||||||
->getMock();
|
'timezone' => 'UTC',
|
||||||
|
]));
|
||||||
|
|
||||||
/** @var Application|MockObject $app */
|
$serviceProvider = new DatabaseServiceProvider($this->app);
|
||||||
$app = $this->getMockBuilder(Application::class)
|
|
||||||
->setMethods(['get'])
|
|
||||||
->getMock();
|
|
||||||
Application::setInstance($app);
|
|
||||||
|
|
||||||
$app->expects($this->once())
|
|
||||||
->method('get')
|
|
||||||
->with('config')
|
|
||||||
->willReturn($config);
|
|
||||||
|
|
||||||
$config->expects($this->atLeastOnce())
|
|
||||||
->method('get')
|
|
||||||
->with('database')
|
|
||||||
->willReturn($this->getDbConfig());
|
|
||||||
|
|
||||||
$serviceProvider = new DatabaseServiceProvider($app);
|
|
||||||
$serviceProvider->register();
|
$serviceProvider->register();
|
||||||
|
$this->assertTrue($this->app->has(Database::class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Feature\Database;
|
namespace Engelsystem\Test\Feature\Database;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
|
|
||||||
abstract class DatabaseTest extends TestCase
|
abstract class DatabaseTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,7 +100,10 @@ class DatabaseServiceProviderTest extends ServiceProviderTest
|
||||||
$app = $this->getApp(['get', 'make', 'instance']);
|
$app = $this->getApp(['get', 'make', 'instance']);
|
||||||
|
|
||||||
$this->setExpects($app, 'get', ['config'], $config);
|
$this->setExpects($app, 'get', ['config'], $config);
|
||||||
$this->setExpects($config, 'get', ['database'], $dbConfigData, $this->atLeastOnce());
|
$config->expects($this->exactly(2))
|
||||||
|
->method('get')
|
||||||
|
->withConsecutive(['timezone'], ['database'])
|
||||||
|
->willReturnOnConsecutiveCalls('UTC', $dbConfigData);
|
||||||
|
|
||||||
$app->expects($this->atLeastOnce())
|
$app->expects($this->atLeastOnce())
|
||||||
->method('make')
|
->method('make')
|
||||||
|
|
Loading…
Reference in New Issue