Completed
Push — master ( b1b8c7...b37043 )
by Timo
06:43
created

UnitTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Tests\Unit;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2015 Timo Schmidt <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use TYPO3\CMS\Core\Tests\UnitTestCase as TYPO3UnitTest;
28
29
/**
30
 * Base class for all unit tests in the solr project
31
 *
32
 * @author Timo Schmidt
33
 * @package TYPO3
34
 * @subpackage solr
35
 */
36
abstract class UnitTest extends TYPO3UnitTest
37
{
38
39
    /**
40
     * Returns a mock class where every behaviour is mocked, just to full fill
41
     * the datatype and have the possibility to mock the behaviour.
42
     *
43
     * @param string $className
44
     * @return \PHPUnit_Framework_MockObject_MockObject
45
     */
46
    protected function getDumbMock($className)
47
    {
48
        return $this->getMockBuilder($className)->setMethods([])->disableOriginalConstructor()->getMock();
49
    }
50
51
    /**
52
     * Returns the absolute root path to the fixtures.
53
     *
54
     * @return string
55
     */
56
    protected function getFixtureRootPath()
57
    {
58
        return $this->getRuntimeDirectory() . '/Fixtures/';
59
    }
60
61
    /**
62
     * Returns the absolute path to a fixture file.
63
     *
64
     * @param $fixtureName
65
     * @return string
66
     */
67
    protected function getFixturePath($fixtureName)
68
    {
69
        return $this->getFixtureRootPath() . $fixtureName;
70
    }
71
72
    /**
73
     * Returns the content of a fixture file.
74
     *
75
     * @param string $fixtureName
76
     * @return string
77
     */
78
    protected function getFixtureContent($fixtureName)
79
    {
80
        return file_get_contents($this->getFixturePath($fixtureName));
81
    }
82
83
    /**
84
     * Returns the directory on runtime.
85
     *
86
     * @return string
87
     */
88
    protected function getRuntimeDirectory()
89
    {
90
        $rc = new \ReflectionClass(get_class($this));
91
        return dirname($rc->getFileName());
92
    }
93
94
    /**
95
     * @param string $version
96
     */
97
    protected function skipInVersionBelow($version)
98
    {
99
        if (version_compare(TYPO3_branch, $version, '<')) {
100
            $this->markTestSkipped('This test requires at least version '.$version);
101
        }
102
    }
103
}
104