1
0
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:
Emanuil Rusev 2015-08-13 15:16:23 +03:00
commit fa005fdb95
3 changed files with 26 additions and 1 deletions

View File

@ -1476,7 +1476,7 @@ class Parsedown
return self::$instances[$name];
}
$instance = new self();
$instance = new static();
self::$instances[$name] = $instance;

View File

@ -136,4 +136,24 @@ EXPECTED_HTML;
$parsedownWithNoMarkup->setMarkupEscaped(true);
$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
View File

@ -0,0 +1,5 @@
<?php
class TestParsedown extends Parsedown
{
}