diff options
Diffstat (limited to 'tests/Feature/Database')
-rw-r--r-- | tests/Feature/Database/DatabaseServiceProviderTest.php | 40 | ||||
-rw-r--r-- | tests/Feature/Database/DatabaseTest.php | 25 |
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/Feature/Database/DatabaseServiceProviderTest.php b/tests/Feature/Database/DatabaseServiceProviderTest.php new file mode 100644 index 00000000..d5fdd108 --- /dev/null +++ b/tests/Feature/Database/DatabaseServiceProviderTest.php @@ -0,0 +1,40 @@ +<?php + +namespace Engelsystem\Test\Feature\Database; + +use Engelsystem\Application; +use Engelsystem\Config\Config; +use Engelsystem\Database\DatabaseServiceProvider; +use PHPUnit_Framework_MockObject_MockObject as MockObject; + +class DatabaseServiceProviderTest extends DatabaseTest +{ + /** + * @covers \Engelsystem\Database\DatabaseServiceProvider::register() + */ + public function testRegister() + { + /** @var MockObject|Config $config */ + $config = $this->getMockBuilder(Config::class) + ->getMock(); + + /** @var MockObject|Application $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(); + } +} diff --git a/tests/Feature/Database/DatabaseTest.php b/tests/Feature/Database/DatabaseTest.php new file mode 100644 index 00000000..11df6779 --- /dev/null +++ b/tests/Feature/Database/DatabaseTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Engelsystem\Test\Feature\Database; + +use PHPUnit\Framework\TestCase; + +abstract class DatabaseTest extends TestCase +{ + /** + * Returns the database config + * + * @return string[] + */ + protected function getDbConfig() + { + $configValues = require __DIR__ . '/../../../config/config.default.php'; + $configFile = __DIR__ . '/../../../config/config.php'; + + if (file_exists($configFile)) { + $configValues = array_replace_recursive($configValues, require $configFile); + } + + return $configValues['database']; + } +} |