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\Twig; |
14
|
|
|
|
15
|
|
|
use Webuni\FrontMatter\Document; |
16
|
|
|
use Webuni\FrontMatter\FrontMatterInterface; |
17
|
|
|
use Webuni\FrontMatter\Twig\FrontMatterLoader; |
18
|
|
|
|
19
|
|
|
class FrontMatterLoaderTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
private $frontMatter; |
22
|
|
|
private $originalLoader; |
23
|
|
|
private $loader; |
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->frontMatter = $this->createMock(FrontMatterInterface::class); |
28
|
|
|
$this->originalLoader = $this->createMock(\Twig_LoaderInterface::class); |
29
|
|
|
|
30
|
|
|
$this->loader = new FrontMatterLoader($this->frontMatter, $this->originalLoader); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGetCacheKey() |
34
|
|
|
{ |
35
|
|
|
$this->originalLoader->method('getCacheKey')->with($name = 'name')->willReturn($name); |
36
|
|
|
$this->assertEquals($name, $this->loader->getCacheKey($name)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testIsFresh() |
40
|
|
|
{ |
41
|
|
|
$this->originalLoader->method('isFresh')->with($name = 'name', $time = time())->willReturn(true); |
42
|
|
|
$this->assertTrue($this->loader->isFresh($name, $time)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testExists() |
46
|
|
|
{ |
47
|
|
|
$this->originalLoader = $this->createMock([\Twig_LoaderInterface::class, \Twig_ExistsLoaderInterface::class]); |
|
|
|
|
48
|
|
|
$this->loader = new FrontMatterLoader($this->frontMatter, $this->originalLoader); |
49
|
|
|
|
50
|
|
|
$this->originalLoader->method('exists')->with($name = 'name')->willReturn(true); |
51
|
|
|
$this->assertTrue($this->loader->exists($name)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetSourceContext() |
55
|
|
|
{ |
56
|
|
|
$document = new Document('{{ foo }}', ['foo' => 'bar']); |
57
|
|
|
$this->originalLoader->method('getSource')->with($name = 'name')->willReturn($source = "---\nfoo: bar\n---\n{{ foo }}"); |
58
|
|
|
$this->frontMatter->method('parse')->with($source, ['filename' => $name])->willReturn($document); |
59
|
|
|
|
60
|
|
|
$this->assertEquals($document, $this->loader->getSourceContext($name)->getCode()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: