Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger tested #265

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion includes/MslsMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</coverage>
<php>
<const name="MSLS_PLUGIN_PATH" value="multisite-language-switcher/MultisiteLanguageSwitcher.php"/>
<const name="WP_DEBUG" value="true"/>
</php>
<testsuite name="Internal tests">
<directory prefix="test-" suffix=".php">./tests/</directory>
Expand Down
30 changes: 27 additions & 3 deletions tests/test-mslsmain.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,48 @@ 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();

$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);
}

}
Loading