Completed
Push — master ( de9e2d...f59dfb )
by Henry
08:37
created

tests/phpunit/View/ResultListTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\View;
3
4
use Redaxscript\Controller;
5
use Redaxscript\Db;
6
use Redaxscript\Tests\TestCaseAbstract;
7
use Redaxscript\View;
8
9
/**
10
 * ResultListTest
11
 *
12
 * @since 3.0.0
13
 *
14
 * @package Redaxscript
15
 * @category Tests
16
 * @author Henry Ruhs
17
 * @author Balázs Szilágyi
18
 *
19
 * @covers Redaxscript\View\ResultList
20
 * @covers Redaxscript\View\ViewAbstract
21
 */
22
23
class ResultListTest extends TestCaseAbstract
24
{
25
	/**
26
	 * setUp
27
	 *
28
	 * @since 3.1.0
29
	 */
30
31
	public function setUp()
32
	{
33
		parent::setUp();
34
		$optionArray =
35
		[
36
			'adminName' => 'Test',
37
			'adminUser' => 'test',
38
			'adminPassword' => 'test',
39
			'adminEmail' => '[email protected]'
40
		];
41
		$installer = $this->installerFactory();
42
		$installer->init();
43
		$installer->rawCreate();
44
		$installer->insertSettings($optionArray);
45
		$categoryOne = Db::forTablePrefix('categories')->create();
46
		$categoryOne
47
			->set(
48
			[
49
				'title' => 'Category One',
50
				'alias' => 'category-one',
51
				'date' => 1483225200
52
			])
53
			->save();
54
		$articleOne = Db::forTablePrefix('articles')->create();
55
		$articleOne
56
			->set(
57
			[
58
				'title' => 'Article One',
59
				'alias' => 'article-one',
60
				'category' => $categoryOne->id,
61
				'date' => 1483225200
62
			])
63
			->save();
64
		Db::forTablePrefix('comments')
65
			->create()
66
			->set(
67
			[
68
				'author' => 'Comment One',
69
				'text' => 'Comment One',
70
				'article' => $articleOne->id,
71
				'date' => 1451602800
72
			])
73
			->save();
74
	}
75
76
	/**
77
	 * tearDown
78
	 *
79
	 * @since 3.1.0
80
	 */
81
82
	public function tearDown()
83
	{
84
		$this->dropDatabase();
85
	}
86
87
	/**
88
	 * testRender
89
	 *
90
	 * @since 3.0.0
91
	 *
92
	 * @param array $searchArray
93
	 * @param string $expect
94
	 *
95
	 * @dataProvider providerAutoloader
96
	 */
97
98
	public function testRender(array $searchArray = [], string $expect = null)
99
	{
100
		/* setup */
101
102
		$resultList = new View\ResultList($this->_registry, $this->_language);
103
		$controllerSearch = new Controller\Search($this->_registry, $this->_request, $this->_language, $this->_config);
104
		$resultArray = $this->callMethod($controllerSearch, '_search',
105
		[
106
			$searchArray
107
		]);
108
109
		/* actual */
110
111
		$actual = $resultList->render($resultArray);
0 ignored issues
show
It seems like $resultArray defined by $this->callMethod($contr...', array($searchArray)) on line 104 can also be of type object; however, Redaxscript\View\ResultList::render() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
112
113
		/* compare */
114
115
		$this->assertEquals($expect, $actual);
116
	}
117
}
118