Completed
Push — master ( 43a266...382a9d )
by Cheren
07:50
created

TestCase::assertIsEmptyArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\TestSuite;
17
18
use Core\Plugin;
19
use JBZoo\Utils\Str;
20
use Cake\Cache\Cache;
21
use Cake\TestSuite\TestCase as CakeTestCase;
22
23
/**
24
 * Class TestCase
25
 *
26
 * @package Core\TestSuite
27
 */
28
class TestCase extends CakeTestCase
29
{
30
31
    /**
32
     * Default plugin name.
33
     *
34
     * @var string
35
     */
36
    protected $_plugin = 'Core';
37
38
    /**
39
     * Core plugin.
40
     *
41
     * @var string
42
     */
43
    protected $_corePlugin = 'Core';
44
45
    /**
46
     * Setup the test case, backup the static object values so they can be restored.
47
     * Specifically backs up the contents of Configure and paths in App if they have
48
     * not already been backed up.
49
     *
50
     * @return void
51
     */
52
    public function setUp()
53
    {
54
        parent::setUp();
55
56
        if ($this->_plugin !== $this->_corePlugin) {
57
            $options = [
58
                'bootstrap' => true,
59
                'routes'    => true,
60
                'autoload'  => true,
61
            ];
62
63
            Plugin::load($this->_plugin, $options);
64
            Plugin::routes($this->_plugin);
65
        }
66
67 View Code Duplication
        if (!Plugin::loaded($this->_corePlugin)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
            $loadParams = [
69
                'bootstrap' => true,
70
                'routes'    => true,
71
                'path'      => ROOT . DS,
72
            ];
73
74
            Plugin::load($this->_corePlugin, $loadParams);
75
            Plugin::routes($this->_corePlugin);
76
        }
77
    }
78
79
    /**
80
     * Clears the state used for requests.
81
     *
82
     * @return void
83
     */
84 View Code Duplication
    public function tearDown()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        parent::tearDown();
87
        Plugin::unload($this->_corePlugin);
88
        if ($this->_plugin !== $this->_corePlugin) {
89
            Plugin::unload($this->_plugin);
90
        }
91
        Cache::drop('test_cached');
92
    }
93
94
    /**
95
     * Assert check is empty array.
96
     *
97
     * @param array $array
98
     */
99
    public function assertIsEmptyArray(array $array)
100
    {
101
        $this->assertSame([], $array);
102
    }
103
104
    /**
105
     * @param string $string
106
     * @return array
107
     */
108
    protected function _getStrArray($string)
109
    {
110
        $output  = [];
111
        $details = explode("\n", $string);
112
        foreach ($details as $string) {
113
            $string   = Str::trim($string);
114
            $output[] = $string;
115
        }
116
117
        return $output;
118
    }
119
}
120