Skip to content

Commit

Permalink
MslsLink tested
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Aug 30, 2024
1 parent 1692d7e commit 818d61f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
21 changes: 10 additions & 11 deletions includes/MslsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,26 @@ public static function get_types_description(): array {
* @return MslsLink
*/
public static function create( ?int $display ): MslsLink {
$types = self::get_types();
if ( ! in_array( $display, array_keys( $types ), true ) ) {
$display = 0;
}

$obj = new $types[ $display ]();

if ( has_filter( 'msls_link_create' ) ) {
/**
* Returns custom MslsLink-Object
*
* @param int $display
*
* @return MslsLink
* @since 0.9.9
*/
$obj = apply_filters( 'msls_link_create', $display );
if ( is_subclass_of( $obj, __CLASS__ ) ) {
$obj = apply_filters( 'msls_link_create', $obj, $display );
if ( in_array( __CLASS__, $types ) || is_subclass_of( $obj, __CLASS__ ) ) {
return $obj;
}
}

$types = self::get_types();
if ( ! in_array( $display, array_keys( $types ), true ) ) {
$display = 0;
}

return new $types[ $display ]();
return $obj;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/TestMslsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
namespace lloc\MslsTests;

use Brain\Monkey\Functions;
use Brain\Monkey\Filters;
use Hoa\Iterator\Filter;
use lloc\Msls\MslsLink;

class TestMslsLink extends MslsUnitTestCase {

public function test_create(): void {
Functions\expect( 'has_filter' )->once()->with( 'msls_link_create' )->andReturn( true );

$obj = new MslsLink();
$display = 0;

Filters\expectApplied( 'msls_link_create' )->once()->andReturn( $obj );

$obj = MslsLink::create( $display );

$this->assertInstanceOf( MslsLink::class, $obj );
}

public function test_get_types(): void {
$this->assertCount( 4, MslsLink::get_types() );
}
Expand Down

0 comments on commit 818d61f

Please sign in to comment.