1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This is part of the webuni/front-matter package. |
5
|
|
|
* |
6
|
|
|
* (c) Martin Hasoň <[email protected]> |
7
|
|
|
* (c) Webuni s.r.o. <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Webuni\FrontMatter\Tests\Haml; |
14
|
|
|
|
15
|
|
|
use MtHaml\Filter\FilterInterface; |
16
|
|
|
use MtHaml\Node\Filter; |
17
|
|
|
use MtHaml\NodeVisitor\RendererAbstract; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
use Webuni\FrontMatter\Document; |
20
|
|
|
use Webuni\FrontMatter\FrontMatterInterface; |
21
|
|
|
use Webuni\FrontMatter\Haml\FrontMatterFilter; |
22
|
|
|
|
23
|
|
|
class FrontMatterFilterTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
private $frontMatter; |
26
|
|
|
private $originalFilter; |
27
|
|
|
private $filter; |
28
|
|
|
|
29
|
|
|
protected function setUp(): void |
30
|
|
|
{ |
31
|
|
|
$this->frontMatter = $this->createMock(FrontMatterInterface::class); |
32
|
|
|
$this->originalFilter = $this->createMock(FilterInterface::class); |
33
|
|
|
$this->filter = new FrontMatterFilter($this->frontMatter, $this->originalFilter); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function testIsOptimizable() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$renderer = $this->createMock(RendererAbstract::class); |
39
|
|
|
$node = $this->createMock(Filter::class); |
40
|
|
|
|
41
|
|
|
$this->originalFilter->method('isOptimizable')->with($renderer, $node, $options = [])->willReturn(true); |
42
|
|
|
$this->assertTrue($this->filter->isOptimizable($renderer, $node, $options)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testOptimize() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$renderer = $this->createMock(RendererAbstract::class); |
48
|
|
|
$node = $this->createMock(Filter::class); |
49
|
|
|
|
50
|
|
|
$this->originalFilter->method('optimize')->with($renderer, $node, $options = [])->willReturn('foo'); |
51
|
|
|
$this->assertEquals('foo', $this->filter->optimize($renderer, $node, $options)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testFilter() |
55
|
|
|
{ |
56
|
|
|
$document = new Document(''); |
57
|
|
|
|
58
|
|
|
$this->frontMatter->method('parse')->with($content = "---\n----\nstring")->willReturn($document); |
59
|
|
|
$this->originalFilter->method('filter')->with($document, $context = [], $options = [])->willReturn('string'); |
60
|
|
|
|
61
|
|
|
$this->assertEquals($document, $this->filter->filter($content, $context, $options)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.