Completed
Push — master ( c12891...5636df )
by Martin
02:55
created

FrontMatterLoaderTest::testIsFresh()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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
 * (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]);
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...
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