Skip to content

Commit 818d61f

Browse files
committed
MslsLink tested
1 parent 1692d7e commit 818d61f

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

includes/MslsLink.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,26 @@ public static function get_types_description(): array {
6666
* @return MslsLink
6767
*/
6868
public static function create( ?int $display ): MslsLink {
69+
$types = self::get_types();
70+
if ( ! in_array( $display, array_keys( $types ), true ) ) {
71+
$display = 0;
72+
}
73+
74+
$obj = new $types[ $display ]();
75+
6976
if ( has_filter( 'msls_link_create' ) ) {
7077
/**
71-
* Returns custom MslsLink-Object
72-
*
7378
* @param int $display
7479
*
7580
* @return MslsLink
76-
* @since 0.9.9
7781
*/
78-
$obj = apply_filters( 'msls_link_create', $display );
79-
if ( is_subclass_of( $obj, __CLASS__ ) ) {
82+
$obj = apply_filters( 'msls_link_create', $obj, $display );
83+
if ( in_array( __CLASS__, $types ) || is_subclass_of( $obj, __CLASS__ ) ) {
8084
return $obj;
8185
}
8286
}
8387

84-
$types = self::get_types();
85-
if ( ! in_array( $display, array_keys( $types ), true ) ) {
86-
$display = 0;
87-
}
88-
89-
return new $types[ $display ]();
88+
return $obj;
9089
}
9190

9291
/**

tests/phpunit/TestMslsLink.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33
namespace lloc\MslsTests;
44

55
use Brain\Monkey\Functions;
6+
use Brain\Monkey\Filters;
7+
use Hoa\Iterator\Filter;
68
use lloc\Msls\MslsLink;
79

810
class TestMslsLink extends MslsUnitTestCase {
911

12+
public function test_create(): void {
13+
Functions\expect( 'has_filter' )->once()->with( 'msls_link_create' )->andReturn( true );
14+
15+
$obj = new MslsLink();
16+
$display = 0;
17+
18+
Filters\expectApplied( 'msls_link_create' )->once()->andReturn( $obj );
19+
20+
$obj = MslsLink::create( $display );
21+
22+
$this->assertInstanceOf( MslsLink::class, $obj );
23+
}
24+
1025
public function test_get_types(): void {
1126
$this->assertCount( 4, MslsLink::get_types() );
1227
}

0 commit comments

Comments
 (0)