Completed
Push — master ( 4a9b36...8c5fb1 )
by Vladimir
02:20
created

PHPUnit_Stakx_TestCase::bookCollectionProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright 2016 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
use allejo\stakx\Manager\CollectionManager;
9
use allejo\stakx\System\Filesystem;
10
use org\bovigo\vfs\vfsStream;
11
use org\bovigo\vfs\vfsStreamDirectory;
12
use org\bovigo\vfs\vfsStreamFile;
13
use Psr\Log\LoggerInterface;
14
use Symfony\Component\Yaml\Yaml;
15
16
abstract class PHPUnit_Stakx_TestCase extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
17
{
18
    const FM_OBJ_TEMPLATE = "---\n%s\n---\n\n%s";
19
20
    /**
21
     * @var vfsStreamFile
22
     */
23
    protected $dummyFile;
24
25
    /**
26
     * @var vfsStreamDirectory
27
     */
28
    protected $rootDir;
29
30
    /**
31
     * @var Filesystem
32
     */
33
    protected $fs;
34
35
    public function setUp()
36
    {
37
        $this->dummyFile    = vfsStream::newFile('stakx.html.twig');
38
        $this->rootDir      = vfsStream::setup();
39
        $this->fs           = new Filesystem();
40
    }
41
42
    //
43
    // Assert Functions
44
    //
45
46
    public function assertFileExistsAndContains ($filePath, $needle, $message = '')
47
    {
48
        $this->assertFileExists($filePath, $message);
49
50
        $contents = file_get_contents($filePath);
51
52
        $this->assertContains($needle, $contents, $message);
53
    }
54
55
    //
56
    // Utility Functions
57
    //
58
59
    protected function bookCollectionProvider ()
60
    {
61
        $cm = new CollectionManager();
62
        $cm->setLogger($this->loggerMock());
63
        $cm->parseCollections(array(
64
            array(
65
                'name'   => 'books',
66
                'folder' => 'tests/assets/MyBookCollection/'
67
            )
68
        ));
69
70
        return $cm->getJailedCollections();
71
    }
72
73
    /**
74
     * @param  string $classType
75
     * @param  array  $frontMatter
76
     * @param  string $body
77
     *
78
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
79
     */
80
    protected function createVirtualFile ($classType, $frontMatter = array(), $body = "Body Text")
81
    {
82
        $fm = (empty($frontMatter)) ? '' : Yaml::dump($frontMatter, 2);
83
84
        $this->dummyFile
85
            ->setContent(sprintf("---\n%s\n---\n\n%s", $fm, $body))
86
            ->at($this->rootDir);
87
88
        return (new $classType($this->dummyFile->url()));
89
    }
90
91
    /**
92
     * @return LoggerInterface
93
     */
94
    protected function loggerMock ()
95
    {
96
        return $this->getMock(LoggerInterface::class);
97
    }
98
}