-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
429f742
commit 50ca8ad
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the league/commonmark package. | ||
* | ||
* (c) Colin O'Dell <colinodell@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\CommonMark\Event; | ||
|
||
use League\CommonMark\Block\Element\Document; | ||
|
||
/** | ||
* Event dispatched when the document is about to be parsed | ||
*/ | ||
final class DocumentPreParsedEvent extends AbstractEvent | ||
{ | ||
/** @var Document */ | ||
private $document; | ||
|
||
/** | ||
* @param Document $document | ||
*/ | ||
public function __construct(Document $document) | ||
{ | ||
$this->document = $document; | ||
} | ||
|
||
/** | ||
* @return Document | ||
*/ | ||
public function getDocument(): Document | ||
{ | ||
return $this->document; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the league/commonmark package. | ||
* | ||
* (c) Colin O'Dell <colinodell@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace League\CommonMark\Tests\Unit\Event; | ||
|
||
use League\CommonMark\Block\Element\Document; | ||
use League\CommonMark\DocParser; | ||
use League\CommonMark\Environment; | ||
use League\CommonMark\Event\DocumentPreParsedEvent; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DocumentPreParsedEventTest extends TestCase | ||
{ | ||
public function testGetDocument() | ||
{ | ||
$document = new Document(); | ||
|
||
$event = new DocumentPreParsedEvent($document); | ||
|
||
$this->assertSame($document, $event->getDocument()); | ||
} | ||
|
||
public function testEventDispatchedAtCorrectTime() | ||
{ | ||
$wasCalled = false; | ||
|
||
$environment = Environment::createCommonMarkEnvironment(); | ||
$environment->addEventListener(DocumentPreParsedEvent::class, function (DocumentPreParsedEvent $event) use (&$wasCalled) { | ||
$wasCalled = true; | ||
}); | ||
|
||
$parser = new DocParser($environment); | ||
$parser->parse('hello world'); | ||
|
||
$this->assertTrue($wasCalled); | ||
} | ||
} |