From 2cce967eb09edd6ef35238c68f8ff5ed2348f5fd Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 6 Nov 2019 13:16:00 +0100 Subject: Tests: Replaced duplicates and formatting/cleanup --- tests/Unit/Config/ConfigServiceProviderTest.php | 57 +++++++++++++------------ 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'tests/Unit/Config/ConfigServiceProviderTest.php') diff --git a/tests/Unit/Config/ConfigServiceProviderTest.php b/tests/Unit/Config/ConfigServiceProviderTest.php index 62a662f8..8895f66d 100644 --- a/tests/Unit/Config/ConfigServiceProviderTest.php +++ b/tests/Unit/Config/ConfigServiceProviderTest.php @@ -23,21 +23,9 @@ class ConfigServiceProviderTest extends ServiceProviderTest */ public function testRegister() { + /** @var Application|MockObject $app */ /** @var Config|MockObject $config */ - $config = $this->getMockBuilder(Config::class) - ->getMock(); - - $app = $this->getApp(['make', 'instance', 'get']); - Application::setInstance($app); - - $this->setExpects($app, 'make', [Config::class], $config); - $this->setExpects($app, 'get', ['path.config'], __DIR__ . '/../../../config', $this->atLeastOnce()); - $app->expects($this->exactly(2)) - ->method('instance') - ->withConsecutive( - [Config::class, $config], - ['config', $config] - ); + list($app, $config) = $this->getConfiguredApp(__DIR__ . '/../../../config'); $this->setExpects($config, 'set', null, null, $this->exactly(2)); $config->expects($this->exactly(3)) @@ -64,21 +52,9 @@ class ConfigServiceProviderTest extends ServiceProviderTest */ public function testRegisterException() { + /** @var Application|MockObject $app */ /** @var Config|MockObject $config */ - $config = $this->getMockBuilder(Config::class) - ->getMock(); - - $app = $this->getApp(['make', 'instance', 'get']); - Application::setInstance($app); - - $this->setExpects($app, 'make', [Config::class], $config); - $app->expects($this->exactly(2)) - ->method('instance') - ->withConsecutive( - [Config::class, $config], - ['config', $config] - ); - $this->setExpects($app, 'get', ['path.config'], __DIR__ . '/not_existing', $this->atLeastOnce()); + list($app, $config) = $this->getConfiguredApp(__DIR__ . '/not_existing'); $this->setExpects($config, 'set', null, null, $this->never()); $this->setExpects($config, 'get', [null], []); @@ -151,4 +127,29 @@ class ConfigServiceProviderTest extends ServiceProviderTest $config->get(null) ); } + + /** + * @param string $configPath + * @return Application[]|Config[] + */ + protected function getConfiguredApp(string $configPath) + { + /** @var Config|MockObject $config */ + $config = $this->getMockBuilder(Config::class) + ->getMock(); + + $app = $this->getApp(['make', 'instance', 'get']); + Application::setInstance($app); + + $this->setExpects($app, 'make', [Config::class], $config); + $this->setExpects($app, 'get', ['path.config'], $configPath, $this->atLeastOnce()); + $app->expects($this->exactly(2)) + ->method('instance') + ->withConsecutive( + [Config::class, $config], + ['config', $config] + ); + + return [$app, $config]; + } } -- cgit v1.2.3-54-g00ecf