Skip to content

Commit

Permalink
Merge pull request #239 from healsdata/issue-233-add-invoke-to-convertor
Browse files Browse the repository at this point in the history
Enable calling convertToHtml as a function
  • Loading branch information
colinodell committed Mar 27, 2016
2 parents 34c45b6 + d30e265 commit b3198bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ public function convertToHtml($commonMark)

return $this->htmlRenderer->renderBlock($documentAST);
}

/**
* Converts CommonMark to HTML.
*
* @see Converter::convertToHtml
*
* @param $commonMark
*
* @return string
*/
public function __invoke($commonMark)
{
return $this->convertToHtml($commonMark);
}
}
24 changes: 24 additions & 0 deletions tests/unit/ConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace League\CommonMark\Tests\Unit;

use League\CommonMark\Converter;
use PHPUnit_Framework_MockObject_MockObject;

class ConverterTest extends \PHPUnit_Framework_TestCase
{
public function testInvokeReturnsSameOutputAsConvertToHtml()
{
$inputMarkdown = '**Strong**';
$expectedHtml = '<strong>Strong</strong>';

/** @var Converter|PHPUnit_Framework_MockObject_MockObject $converter */
$converter = $this->getMockBuilder('League\CommonMark\Converter')
->disableOriginalConstructor()
->setMethods(['convertToHtml'])
->getMock();
$converter->method('convertToHtml')->with($inputMarkdown)->willReturn($expectedHtml);

$this->assertSame($expectedHtml, $converter($inputMarkdown));
}
}

0 comments on commit b3198bb

Please sign in to comment.