Completed
Push — master ( dfede2...367c5a )
by Martin
03:32
created

FrontMatterLoaderTest::testExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/*
4
 * This is part of the webuni/front-matter package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webuni\FrontMatter\Tests\Twig;
13
14
use Webuni\FrontMatter\Document;
15
use Webuni\FrontMatter\FrontMatterInterface;
16
use Webuni\FrontMatter\Twig\FrontMatterLoader;
17
18
class FrontMatterLoaderTest extends \PHPUnit_Framework_TestCase
19
{
20
    private $frontMatter;
21
    private $originalLoader;
22
    private $loader;
23
24
    protected function setUp()
25
    {
26
        $this->frontMatter = $this->createMock(FrontMatterInterface::class);
27
        $this->originalLoader = $this->createMock(\Twig_LoaderInterface::class);
28
29
        $this->loader = new FrontMatterLoader($this->frontMatter, $this->originalLoader);
30
    }
31
32
    public function testGetCacheKey()
33
    {
34
        $this->originalLoader->method('getCacheKey')->with($name = 'name')->willReturn($name);
35
        $this->assertEquals($name, $this->loader->getCacheKey($name));
36
    }
37
38
    public function testIsFresh()
39
    {
40
        $this->originalLoader->method('isFresh')->with($name = 'name', $time = time())->willReturn(true);
41
        $this->assertTrue($this->loader->isFresh($name, $time));
42
    }
43
44
    public function testExists()
45
    {
46
        $this->originalLoader = $this->createMock([\Twig_LoaderInterface::class, \Twig_ExistsLoaderInterface::class]);
0 ignored issues
show
Documentation introduced by
array(\Twig_LoaderInterf...LoaderInterface::class) is of type array<integer,?>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $this->loader = new FrontMatterLoader($this->frontMatter, $this->originalLoader);
48
49
        $this->originalLoader->method('exists')->with($name = 'name')->willReturn(true);
50
        $this->assertTrue($this->loader->exists($name));
51
52
    }
53
54
    public function testGetSource()
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->getSource($name));
61
    }
62
}
63