diff --git a/includes/MslsMain.php b/includes/MslsMain.php index d3a6499d..7bff4583 100644 --- a/includes/MslsMain.php +++ b/includes/MslsMain.php @@ -58,11 +58,12 @@ public static function init() { * * @param mixed $message */ - public function debugger( $message ) { + public function debugger( $message ): void { if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) { if ( is_array( $message ) || is_object( $message ) ) { $message = print_r( $message, true ); } + error_log( 'MSLS Debug: ' . $message ); } } diff --git a/phpunit.xml b/phpunit.xml index 4a147f1e..08aacf4b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,6 +7,7 @@ + ./tests/ diff --git a/tests/test-mslsmain.php b/tests/test-mslsmain.php index 4669fe54..781917ed 100644 --- a/tests/test-mslsmain.php +++ b/tests/test-mslsmain.php @@ -24,13 +24,13 @@ public function get_sut() { return new MslsMain( $options, $collection ); } - function test_get_input_array() { + public function test_get_input_array(): void { $obj = $this->get_sut(); $this->assertIsArray( $obj->get_input_array( 0 ) ); } - function test_is_autosave_method() { + public function test_is_autosave(): void { Functions\when( 'wp_is_post_revision' )->justReturn( true ); $obj = $this->get_sut(); @@ -38,10 +38,34 @@ function test_is_autosave_method() { $this->assertIsBool( $obj->is_autosave( 0 ) ); } - function test_verify_nonce_method() { + public function test_verify_nonce(): void { $obj = $this->get_sut(); $this->assertFalse( $obj->verify_nonce() ); } + public function test_debugger_string(): void { + $capture = tmpfile(); + $backup = ini_set('error_log', stream_get_meta_data( $capture )['uri']); + + $obj = $this->get_sut(); + $obj->debugger( 'Test' ); + + $this->assertStringContainsString( 'MSLS Debug: Test', stream_get_contents( $capture ) ); + + ini_set('error_log', $backup); + } + + public function test_debugger_object(): void { + $capture = tmpfile(); + $backup = ini_set('error_log', stream_get_meta_data( $capture )['uri']); + + $obj = $this->get_sut(); + $obj->debugger( (object) [ 'test' => 'msls' ] ); + + $this->assertStringContainsString( '[test] => msls', stream_get_contents( $capture ) ); + + ini_set('error_log', $backup); + } + }