Completed
Push — master ( 3a2228...7af779 )
by Julius
02:27
created

AppControllerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 22 1
A testIndex() 0 8 1
A testIndexEmpty() 0 8 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\AppOrder\Tests\Unit\Controller;
25
26
use OCA\AppOrder\Util;
27
use OCP\AppFramework\Http;
28
use OCA\AppOrder\Controller\AppController;
29
use OCP\IConfig;
30
use OCP\IRequest;
31
use OCP\IURLGenerator;
32
33
class AppControllerTest extends \PHPUnit_Framework_TestCase {
34
35
	/** @var IRequest */
36
	private $request;
37
	/** @var IURLGenerator */
38
	private $urlGenerator;
39
	/** @var string */
40
	private $userId;
41
	/** @var string */
42
	private $appName;
43
	/** @var AppController */
44
	private $controller;
45
	/** @var IConfig */
46
	private $config;
47
	/** @var Util */
48
	private $util;
49
50
	public function setUp() {
51
		parent::setUp();
52
		$this->request = $this->getMockBuilder('OCP\IRequest')
53
			->disableOriginalConstructor()
54
			->getMock();
55
		$this->config = $this->getMockBuilder('OCP\IConfig')
56
			->disableOriginalConstructor()
57
			->getMock();
58
		$this->util = $this->getMockBuilder('\OCA\AppOrder\Util')
59
			->disableOriginalConstructor()
60
			->getMock();
61
		$this->urlGenerator = \OC::$server->getURLGenerator();
62
		$this->userId = 'admin';
63
		$this->appName = 'apporder';
64
		$this->controller = new AppController(
65
			$this->appName,
66
			$this->request,
67
			$this->urlGenerator,
68
			$this->util,
69
			$this->userId
70
		);
71
	}
72
73
	public function testIndex() {
74
		$this->util->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Util>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
			->method('getAppOrder')
76
			->willReturn(json_encode(['/index.php/foo/bar', '/index.php/bar/foo']));
77
		$expected = new Http\RedirectResponse('/index.php/foo/bar');
78
		$result = $this->controller->index();
79
		$this->assertEquals($expected, $result);
80
	}
81
82
	public function testIndexEmpty() {
83
		$this->util->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<OCA\AppOrder\Util>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
			->method('getAppOrder')
85
			->willReturn("");
86
		$result = $this->controller->index();
87
		$expected = new Http\RedirectResponse('http://localhost/index.php/apps/files/');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 82 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
88
		$this->assertEquals($expected, $result);
89
	}
90
91
92
}
93