Completed
Push — master ( 4d87e8...6f96cd )
by Henry
06:30
created

ContentTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 9.0472
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Redaxscript\Tests\Bootstrap;
3
4
use Redaxscript\Bootstrap;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * ContentTest
10
 *
11
 * @since 3.1.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Bootstrap\BootstrapAbstract
18
 * @covers Redaxscript\Bootstrap\Content
19
 *
20
 * @runTestsInSeparateProcesses
21
 */
22
23
class ContentTest extends TestCaseAbstract
24
{
25
	/**
26
	 * setUp
27
	 *
28
	 * @since 3.1.0
29
	 */
30
31
	public function setUp() : void
32
	{
33
		parent::setUp();
34
		$optionArray = $this->getOptionArray();
35
		$installer = $this->installerFactory();
36
		$installer->init();
37
		$installer->rawCreate();
38
		$installer->insertSettings($optionArray);
39
		$categoryOne = Db::forTablePrefix('categories')->create();
40
		$categoryOne
41
			->set(
42
			[
43
				'title' => 'Category One',
44
				'alias' => 'category-one',
45
				'rank' => 1,
46
				'status' => 1
47
			])
48
			->save();
49
		$categoryTwo = Db::forTablePrefix('categories')->create();
50
		$categoryTwo
51
			->set(
52
			[
53
				'title' => 'Category Two',
54
				'alias' => 'category-two',
55
				'rank' => 2,
56
				'parent' => $categoryOne->id,
57
				'status' => 1
58
			])
59
			->save();
60
		Db::forTablePrefix('articles')
61
			->create()
62
			->set(
63
			[
64
				'title' => 'Article One',
65
				'alias' => 'article-one',
66
				'category' => $categoryOne->id,
67
				'rank' => 1,
68
				'status' => 1
69
			])
70
			->save();
71
		Db::forTablePrefix('articles')
72
			->create()
73
			->set(
74
			[
75
				'title' => 'Article Two',
76
				'alias' => 'article-two',
77
				'category' => $categoryTwo->id,
78
				'rank' => 2,
79
				'status' => 1
80
			])
81
			->save();
82
	}
83
84
	/**
85
	 * tearDown
86
	 *
87
	 * @since 3.1.0
88
	 */
89
90
	public function tearDown() : void
91
	{
92
		$this->dropDatabase();
93
	}
94
95
	/**
96
	 * testContent
97
	 *
98
	 * @since 3.1.0
99
	 *
100
	 * @param array $registryArray
101
	 * @param array $settingArray
102
	 * @param array $expectArray
103
	 *
104
	 * @dataProvider providerAutoloader
105
	 */
106
107
	public function testContent(array $registryArray = [], array $settingArray = [], array $expectArray = []) : void
108
	{
109
		/* setup */
110
111
		$this->_registry->init($registryArray);
112
		$setting = $this->settingFactory();
113
		$setting->set('homepage', $settingArray['homepage']);
114
		$setting->set('order', $settingArray['order']);
115
		new Bootstrap\Content($this->_registry, $this->_request);
116
117
		/* actual */
118
119
		$actualArray =
120
		[
121
			'firstTable' => $this->_registry->get('firstTable'),
122
			'secondTable' => $this->_registry->get('secondTable'),
123
			'thirdTable' => $this->_registry->get('thirdTable'),
124
			'lastTable' => $this->_registry->get('lastTable'),
125
			'categoryId' => $this->_registry->get('categoryId'),
126
			'articleId' => $this->_registry->get('articleId'),
127
			'lastId' => $this->_registry->get('lastId')
128
		];
129
130
		/* compare */
131
132
		$this->assertEquals($expectArray, $actualArray);
133
	}
134
}
135