Skip to content

Commit 318ecdb

Browse files
apermoclaude
andcommitted
test: cover msls_get_switcher() argument handling
Add an isolated test for includes/api.php covering the no-arg call, an explicit attribute array, and coercion of a non-array value (the '' the [sc_msls] shortcode passes). Runs in a separate process so loading api.php does not collide with the Brain Monkey function stubs used elsewhere in the suite. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1aae76c commit 318ecdb

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

tests/phpunit/TestApi.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare( strict_types=1 );
2+
3+
namespace lloc\MslsTests;
4+
5+
use Brain\Monkey\Functions;
6+
use PHPUnit\Framework\Attributes\PreserveGlobalState;
7+
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
8+
9+
#[RunTestsInSeparateProcesses]
10+
#[PreserveGlobalState( false )]
11+
final class TestApi extends MslsUnitTestCase {
12+
13+
protected function setUp(): void {
14+
parent::setUp();
15+
16+
require_once __DIR__ . '/../../includes/api.php';
17+
}
18+
19+
public function test_msls_get_switcher_without_arguments(): void {
20+
Functions\expect( 'apply_filters' )->once()->with( 'msls_get_output', null )->andReturn( null );
21+
22+
$this->assertSame( '', msls_get_switcher() );
23+
}
24+
25+
public function test_msls_get_switcher_with_array(): void {
26+
$attr = array( 'before_item' => '<li>' );
27+
28+
$output = \Mockery::mock();
29+
$output->shouldReceive( 'set_tags' )->once()->with( $attr )->andReturn( 'switcher' );
30+
31+
Functions\expect( 'apply_filters' )->once()->with( 'msls_get_output', null )->andReturn( $output );
32+
33+
$this->assertSame( 'switcher', msls_get_switcher( $attr ) );
34+
}
35+
36+
public function test_msls_get_switcher_coerces_non_array_to_empty_array(): void {
37+
$output = \Mockery::mock();
38+
$output->shouldReceive( 'set_tags' )->once()->with( array() )->andReturn( 'switcher' );
39+
40+
Functions\expect( 'apply_filters' )->once()->with( 'msls_get_output', null )->andReturn( $output );
41+
42+
// The [sc_msls] shortcode passes '' when used without attributes.
43+
$this->assertSame( 'switcher', msls_get_switcher( '' ) );
44+
}
45+
}

0 commit comments

Comments
 (0)