From 61a48202e4d81bfc6d63203af883f3e64bfe903e Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Thu, 27 Jun 2019 12:12:25 -0500 Subject: [PATCH 01/13] Rename class to avoid naming collision with external API function. --- .../phpunit/unit/config-store/_loadConfigFromFilesystem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/_loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/_loadConfigFromFilesystem.php index cd1b8acd..681055ba 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/_loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/_loadConfigFromFilesystem.php @@ -16,12 +16,12 @@ use spiralWebDb\Cornerstone\Tests\Unit\Test_Case; /** - * Class Tests_LoadConfigFromFilesystem + * Class Tests__LoadConfigFromFilesystem * * @package spiralWebDb\centralHub\Tests\Unit\ConfigStore * @group config-store */ -class Tests_LoadConfigFromFilesystem extends Test_Case { +class Tests__LoadConfigFromFilesystem extends Test_Case { /** * Prepares the test environment before each test. From 37a6e38b30d25e99d22bcccce6e1ba3687285e9e Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Thu, 27 Jun 2019 12:14:58 -0500 Subject: [PATCH 02/13] Unit test for API function loadConfigFromFilesystem. - Function should merge defaults with config and return store key. --- .../config-store/loadConfigFromFilesystem.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php new file mode 100644 index 00000000..a99312c4 --- /dev/null +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -0,0 +1,55 @@ + [ + 'aaa' => 37, + 'eee' => 'Coding is fun!' + ] + ]; + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); + } + + /** + * Test for edge case #2. + */ + + +} \ No newline at end of file From b548e39762e69ff315c8eb94beff5e1eda80571b Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Thu, 27 Jun 2019 14:26:17 -0500 Subject: [PATCH 03/13] Add two unit tests 1) Function should store a config and return a store key. 2) Function should return an error when the argument $path_to_file is empty. - fixed test description and method name. --- .../config-store/loadConfigFromFilesystem.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index a99312c4..bc9eecea 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -11,6 +11,7 @@ namespace spiralWebDb\centralHub\Tests\Unit\ConfigStore; +use Brain\Monkey; use function KnowTheCode\ConfigStore\loadConfigFromFilesystem; use spiralWebDb\Cornerstone\Tests\Unit\Test_Case; @@ -33,7 +34,7 @@ protected function setUp() { /** * Test loadConfigFromFilesystem() should merge defaults with config - * and return store key. + * and return a store key. */ public function test_should_merge_defaults_and_return_store_key() { $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; @@ -48,8 +49,27 @@ public function test_should_merge_defaults_and_return_store_key() { } /** - * Test for edge case #2. + * Test loadConfigFromFilesystem() should store a config and return the store key. */ + public function test_should_store_a_config_and_return_store_key() { + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; + $defaults = []; + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); + } + + /** + * Test loadConfigFromFilesystem() should return a fatal error when + * $path_to_file is invalid path. + */ + public function test_should_return_error_when_argument_is_invalid_path() { + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) + ->once() + ->with( 'path/to/file.php' ) + ->andThrow( 'Error' ); + $this->expectException( \Error::class ); + loadConfigFromFilesystem( 'path/to/file.php' ); + } } \ No newline at end of file From 40a3a9ae27c86130332f8155e087659e808840cc Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Thu, 27 Jun 2019 15:22:12 -0500 Subject: [PATCH 04/13] [WIP] Unit test for edge case #4. - Test function should overwrite stored configuration and return store key from file configuration. --- .../unit/config-store/loadConfigFromFilesystem.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index bc9eecea..d7bc0bf7 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -71,5 +71,19 @@ public function test_should_return_error_when_argument_is_invalid_path() { loadConfigFromFilesystem( 'path/to/file.php' ); } + /** + * Test loadConfigFromFilesystem() should overwrite stored configuration and + * return store key from file configuration. + */ + public function test_should_overwrite_store_and_return_store_key_from_file_config() { + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' ) + ->once() + ->with( 'baz', 'config_to_store' ) + ->andReturn( 'baz'); + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; + loadConfigFromFilesystem( $path_to_file ); + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); + } } \ No newline at end of file From c21a0deedf4f764a20c86fb32a8064eaa82b543f Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Fri, 28 Jun 2019 12:01:12 -0500 Subject: [PATCH 05/13] Test should overwrite store & return store key from file configuration. --- .../phpunit/unit/config-store/loadConfigFromFilesystem.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index d7bc0bf7..9588d483 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -76,10 +76,8 @@ public function test_should_return_error_when_argument_is_invalid_path() { * return store key from file configuration. */ public function test_should_overwrite_store_and_return_store_key_from_file_config() { - Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' ) - ->once() - ->with( 'baz', 'config_to_store' ) - ->andReturn( 'baz'); + Monkey\Functions\when( '\KnowTheCode\ConfigStore\_the_store' ) + ->justReturn( 'baz'); $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; loadConfigFromFilesystem( $path_to_file ); From a7301199ce4dfc6e351b75f9d233f39740d48e1c Mon Sep 17 00:00:00 2001 From: Robert Gadon Date: Fri, 28 Jun 2019 12:15:19 -0500 Subject: [PATCH 06/13] Formatting fix. Add newline at end of file. --- .../phpunit/unit/config-store/loadConfigFromFilesystem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index 9588d483..ee9f44ed 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -77,11 +77,11 @@ public function test_should_return_error_when_argument_is_invalid_path() { */ public function test_should_overwrite_store_and_return_store_key_from_file_config() { Monkey\Functions\when( '\KnowTheCode\ConfigStore\_the_store' ) - ->justReturn( 'baz'); + ->justReturn( 'baz' ); $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; loadConfigFromFilesystem( $path_to_file ); $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); } +} -} \ No newline at end of file From 2bdee049bb9ebc1d52532a4de15046841c9180ab Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:05:25 -0500 Subject: [PATCH 07/13] Added mocks for internal function dependencies. --- .../config-store/loadConfigFromFilesystem.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index ee9f44ed..4e0071e5 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -72,16 +72,27 @@ public function test_should_return_error_when_argument_is_invalid_path() { } /** - * Test loadConfigFromFilesystem() should overwrite stored configuration and - * return store key from file configuration. + * Test loadConfigFromFilesystem() should overwrite stored configuration and return store key from + * file configuration. */ public function test_should_overwrite_store_and_return_store_key_from_file_config() { - Monkey\Functions\when( '\KnowTheCode\ConfigStore\_the_store' ) - ->justReturn( 'baz' ); $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; - loadConfigFromFilesystem( $path_to_file ); + $config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd' + ]; + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) + ->twice() + ->with( $path_to_file ) + ->andReturn( [ 'foo', $config ] ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_merge_with_defaults' )->never(); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' ) + ->twice() + ->with( 'foo', $config ) + ->andReturn( true ); $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); } } From d7c49080a2d1a54e1cee749dfa94c1c72075e3d0 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:41:19 -0500 Subject: [PATCH 08/13] Removed invalid path unit test. Why? It's an integration test. --- .../config-store/loadConfigFromFilesystem.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index 4e0071e5..b0fc7b04 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -14,6 +14,8 @@ use Brain\Monkey; use function KnowTheCode\ConfigStore\loadConfigFromFilesystem; use spiralWebDb\Cornerstone\Tests\Unit\Test_Case; +use PHPUnit\Framework\Error\Notice; + /** * Class Tests_LoadConfigFromFilesystem @@ -58,19 +60,6 @@ public function test_should_store_a_config_and_return_store_key() { $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); } - /** - * Test loadConfigFromFilesystem() should return a fatal error when - * $path_to_file is invalid path. - */ - public function test_should_return_error_when_argument_is_invalid_path() { - Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) - ->once() - ->with( 'path/to/file.php' ) - ->andThrow( 'Error' ); - $this->expectException( \Error::class ); - loadConfigFromFilesystem( 'path/to/file.php' ); - } - /** * Test loadConfigFromFilesystem() should overwrite stored configuration and return store key from * file configuration. From 4b6786dc64727778c5acc44560e435d3448fa95d Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:43:47 -0500 Subject: [PATCH 09/13] Added mocks to should_store_a_config_and_return_store_key unit test. --- .../config-store/loadConfigFromFilesystem.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index b0fc7b04..e0243744 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -55,9 +55,21 @@ public function test_should_merge_defaults_and_return_store_key() { */ public function test_should_store_a_config_and_return_store_key() { $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; - $defaults = []; + $config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd' + ]; + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) + ->once() + ->with( $path_to_file ) + ->andReturn( [ 'foo', $config ] ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_merge_with_defaults' )->never(); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' ) + ->once() + ->with( 'foo', $config ) + ->andReturn( true ); - $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); } /** From 1fd17fece25bb9bd89250347d1662e1aaa3ddd1e Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:46:16 -0500 Subject: [PATCH 10/13] Added mocks for merge defaults unit test. --- .../config-store/loadConfigFromFilesystem.php | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index e0243744..2f756afa 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -39,13 +39,32 @@ protected function setUp() { * and return a store key. */ public function test_should_merge_defaults_and_return_store_key() { - $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; - $defaults = [ - 'foo' => [ - 'aaa' => 37, - 'eee' => 'Coding is fun!' - ] + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; + $defaults = [ + 'aaa' => 37, + 'eee' => 'Coding is fun!', + ]; + $config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd', ]; + $merged_config = [ + 'aaa' => 37, + 'ccc' => 'ddd', + 'eee' => 'Coding is fun!', + ]; + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) + ->once() + ->with( $path_to_file ) + ->andReturn( [ 'foo', $config ] ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_merge_with_defaults' ) + ->once() + ->with( $config, $defaults ) + ->andReturn( $merged_config ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' ) + ->once() + ->with( 'foo', $merged_config ) + ->andReturn( true ); $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); } @@ -55,9 +74,9 @@ public function test_should_merge_defaults_and_return_store_key() { */ public function test_should_store_a_config_and_return_store_key() { $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; - $config = [ + $config = [ 'aaa' => 'bbb', - 'ccc' => 'ddd' + 'ccc' => 'ddd', ]; Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) ->once() @@ -78,9 +97,9 @@ public function test_should_store_a_config_and_return_store_key() { */ public function test_should_overwrite_store_and_return_store_key_from_file_config() { $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; - $config = [ + $config = [ 'aaa' => 'bbb', - 'ccc' => 'ddd' + 'ccc' => 'ddd', ]; Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_load_config_from_filesystem' ) ->twice() From b3870b326ec4b5c462b660a0d5af18b10fc06e46 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:46:37 -0500 Subject: [PATCH 11/13] Fixed formatting. --- .../phpunit/unit/config-store/loadConfigFromFilesystem.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index 2f756afa..d2805b3e 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -35,8 +35,7 @@ protected function setUp() { } /** - * Test loadConfigFromFilesystem() should merge defaults with config - * and return a store key. + * Test loadConfigFromFilesystem() should merge defaults with config and return a store key. */ public function test_should_merge_defaults_and_return_store_key() { $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; @@ -115,4 +114,3 @@ public function test_should_overwrite_store_and_return_store_key_from_file_confi $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); } } - From 86028e601d6b1d8291cff57866360173319df509 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:56:17 -0500 Subject: [PATCH 12/13] Added integration tests. --- .../config-store/loadConfigFromFilesystem.php | 110 ++++++++++++++++++ .../config-store/loadConfigFromFilesystem.php | 2 - 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 mu-plugins/central-hub/tests/phpunit/integration/config-store/loadConfigFromFilesystem.php diff --git a/mu-plugins/central-hub/tests/phpunit/integration/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/integration/config-store/loadConfigFromFilesystem.php new file mode 100644 index 00000000..905fb559 --- /dev/null +++ b/mu-plugins/central-hub/tests/phpunit/integration/config-store/loadConfigFromFilesystem.php @@ -0,0 +1,110 @@ + 37, + 'eee' => 'Coding is fun!', + ]; + $merged_config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd', + 'eee' => 'Coding is fun!', + ]; + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file, $defaults ) ); + $this->assertEquals( $merged_config, _the_store( 'foo' ) ); + } + + /** + * Test loadConfigFromFilesystem() should store a config and return the store key. + */ + public function test_should_store_a_config_and_return_store_key() { + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; + $config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd', + ]; + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); + $this->assertSame( $config, _the_store( 'foo' ) ); + } + + /** + * Test loadConfigFromFilesystem() should overwrite stored configuration and return store key from + * file configuration. + */ + public function test_should_overwrite_store_and_return_store_key_from_file_config() { + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/test-cpt-config.php'; + $config = [ + 'aaa' => 'bbb', + 'ccc' => 'ddd', + ]; + + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); + $this->assertSame( 'foo', loadConfigFromFilesystem( $path_to_file ) ); + $this->assertSame( $config, _the_store( 'foo' ) ); + } + + /** + * Test loadConfigFromFilesystem() should overwrite stored configuration and return store key from + * file configuration. + */ + public function test_should_throw_exception_when_no_store_key() { + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/config-with-params-only.php'; + $this->expectException( \Exception::class ); + $this->expectExceptionMessage( + sprintf( 'No store key exists in the %s configuration file.', $path_to_file ) + ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_merge_with_defaults' )->never(); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' )->never(); + + loadConfigFromFilesystem( $path_to_file ); + } + + /** + * Test loadConfigFromFilesystem() should throw an Exception when the configuration parameters are empty. + */ + public function test_should_throw_exception_when_config_params_empty() { + $path_to_file = CENTRAL_HUB_ROOT_DIR . '/tests/phpunit/fixtures/config-with-store-key-only.php'; + $this->expectException( \Exception::class ); + $this->expectExceptionMessage( + sprintf( + 'No configuration parameters exist for store key [foo] in the %s configuration file.', + $path_to_file + ) + ); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_merge_with_defaults' )->never(); + Monkey\Functions\expect( '\KnowTheCode\ConfigStore\_the_store' )->never(); + + loadConfigFromFilesystem( $path_to_file ); + } +} diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index d2805b3e..d741d9d7 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -14,8 +14,6 @@ use Brain\Monkey; use function KnowTheCode\ConfigStore\loadConfigFromFilesystem; use spiralWebDb\Cornerstone\Tests\Unit\Test_Case; -use PHPUnit\Framework\Error\Notice; - /** * Class Tests_LoadConfigFromFilesystem From 78c6fd557d37fb3b1212082b66b5cfba78d2a00f Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Fri, 28 Jun 2019 13:57:03 -0500 Subject: [PATCH 13/13] Fixed merged array in unit test. --- .../phpunit/unit/config-store/loadConfigFromFilesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php index d741d9d7..32507fa1 100644 --- a/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php +++ b/mu-plugins/central-hub/tests/phpunit/unit/config-store/loadConfigFromFilesystem.php @@ -46,7 +46,7 @@ public function test_should_merge_defaults_and_return_store_key() { 'ccc' => 'ddd', ]; $merged_config = [ - 'aaa' => 37, + 'aaa' => 'bbb', 'ccc' => 'ddd', 'eee' => 'Coding is fun!', ];