mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Merge pull request #336 from hkdobrev/late-static-binding
Use late static binding for Parsedown::instance()
This commit is contained in:
commit
fa005fdb95
@ -1476,7 +1476,7 @@ class Parsedown
|
|||||||
return self::$instances[$name];
|
return self::$instances[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
$instance = new self();
|
$instance = new static();
|
||||||
|
|
||||||
self::$instances[$name] = $instance;
|
self::$instances[$name] = $instance;
|
||||||
|
|
||||||
|
@ -136,4 +136,24 @@ EXPECTED_HTML;
|
|||||||
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
$parsedownWithNoMarkup->setMarkupEscaped(true);
|
||||||
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
$this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLateStaticBinding()
|
||||||
|
{
|
||||||
|
include 'test/TestParsedown.php';
|
||||||
|
|
||||||
|
$parsedown = Parsedown::instance();
|
||||||
|
$this->assertInstanceOf('Parsedown', $parsedown);
|
||||||
|
|
||||||
|
// After instance is already called on Parsedown
|
||||||
|
// subsequent calls with the same arguments return the same instance
|
||||||
|
$sameParsedown = TestParsedown::instance();
|
||||||
|
$this->assertInstanceOf('Parsedown', $sameParsedown);
|
||||||
|
$this->assertSame($parsedown, $sameParsedown);
|
||||||
|
|
||||||
|
$testParsedown = TestParsedown::instance('test late static binding');
|
||||||
|
$this->assertInstanceOf('TestParsedown', $testParsedown);
|
||||||
|
|
||||||
|
$sameInstanceAgain = TestParsedown::instance('test late static binding');
|
||||||
|
$this->assertSame($testParsedown, $sameInstanceAgain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
5
test/TestParsedown.php
Normal file
5
test/TestParsedown.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TestParsedown extends Parsedown
|
||||||
|
{
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user