Completed
Pull Request — master (#822)
by
unknown
19:08
created

SettingsControllerTest::testSetFirstRunWithException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2016 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Controller;
23
24
class SettingsControllerTest extends \PHPUnit_Framework_TestCase {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type OCA\Calendar\Controller\SettingsControllerTest has been defined more than once; this definition is ignored, only the first definition in tests/php/controller/OtoLayerControllerTest.php (L5-55) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
25
26
	private $appName;
27
	private $request;
28
	private $userSession;
29
	private $config;
30
31
	private $dummyUser;
32
33
	private $controller;
34
35 View Code Duplication
	public function setUp() {
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...
36
		$this->appName = 'calendar';
37
		$this->request = $this->getMockBuilder('\OCP\IRequest')
38
			->disableOriginalConstructor()
39
			->getMock();
40
		$this->userSession = $this->getMockBuilder('OCP\IUserSession')
41
			->disableOriginalConstructor()
42
			->getMock();
43
		$this->config = $this->getMockBuilder('OCP\IConfig')
44
			->disableOriginalConstructor()
45
			->getMock();
46
47
		$this->dummyUser = $this->getMockBuilder('OCP\IUser')
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$this->userSession->expects($this->once())
52
			->method('getUser')
53
			->will($this->returnValue($this->dummyUser));
54
55
		$this->dummyUser->expects($this->once())
56
			->method('getUID')
57
			->will($this->returnValue('user123'));
58
59
		$this->controller = new SettingsController($this->appName,
60
			$this->request, $this->userSession, $this->config);
61
	}
62
63
	/**
64
	 * @dataProvider setViewWithAllowedViewDataProvider
65
	 */
66 View Code Duplication
	public function testSetViewWithAllowedView($view) {
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...
67
		$this->config->expects($this->once())
68
			->method('setUserValue')
69
			->with('user123', $this->appName, 'currentView', $view);
70
71
		$actual = $this->controller->setConfig('view', $view);
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
72
73
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
74
		$this->assertEquals([], $actual->getData());
75
		$this->assertEquals(200, $actual->getStatus());
76
	}
77
78
	public function setViewWithAllowedViewDataProvider() {
79
		return [
80
			['agendaDay'],
81
			['agendaWeek'],
82
			['month'],
83
		];
84
	}
85
86 View Code Duplication
	public function testSetViewWithForbiddenView() {
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...
87
		$actual = $this->controller->setConfig('view','someForbiddenView');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
88
89
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
90
		$this->assertEquals([], $actual->getData());
91
		$this->assertEquals(422, $actual->getStatus());
92
	}
93
94 View Code Duplication
	public function testSetViewWithConfigException() {
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...
95
		$this->config->expects($this->once())
96
			->method('setUserValue')
97
			->with('user123', $this->appName, 'currentView', 'month')
98
			->will($this->throwException(new \Exception));
99
100
		$actual = $this->controller->setConfig('view', 'month');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
101
102
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
103
		$this->assertEquals([], $actual->getData());
104
		$this->assertEquals(500, $actual->getStatus());
105
	}
106
107
	public function testGetView() {
108
		$this->config->expects($this->once())
109
			->method('getUserValue')
110
			->with('user123', $this->appName, 'currentView', 'month')
111
			->will($this->returnValue('agendaWeek'));
112
113
		$actual = $this->controller->getConfig('view');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
114
115
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
116
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
117
		$this->assertEquals(200, $actual->getStatus());
118
	}
119
120 View Code Duplication
	public function testGetViewWithConfigException() {
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...
121
		$this->config->expects($this->once())
122
			->method('getUserValue')
123
			->with('user123', $this->appName, 'currentView', 'month')
124
			->will($this->throwException(new \Exception));
125
126
		$actual = $this->controller->getConfig('view');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
128
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
129
		$this->assertEquals([], $actual->getData());
130
		$this->assertEquals(500, $actual->getStatus());
131
	}
132
133
	/**
134
	 * @dataProvider setPopoverWithAllowedValueDataProvider
135
	 */
136 View Code Duplication
	public function testSetPopoverWithAllowedValue($value) {
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...
137
		$this->config->expects($this->once())
138
			->method('setUserValue')
139
			->with('user123', $this->appName, 'skipPopover', $value);
140
141
		$actual = $this->controller->setConfig('skipPopover', $value);
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
142
143
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
144
		$this->assertEquals([], $actual->getData());
145
		$this->assertEquals(200, $actual->getStatus());
146
	}
147
148
	public function setPopoverWithAllowedValueDataProvider() {
149
		return [
150
			['yes'],
151
			['no']
152
		];
153
	}
154
155 View Code Duplication
	public function testSetPopoverWithForbiddenValue() {
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...
156
		$actual = $this->controller->setConfig('skipPopover','someForbiddenValue');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
157
158
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
159
		$this->assertEquals([], $actual->getData());
160
		$this->assertEquals(422, $actual->getStatus());
161
	}
162
163
	public function testSetPopoverWithConfigException() {
164
		$this->config->expects($this->once())
165
			->method('setUserValue')
166
			->with('user123', $this->appName, 'skipPopover', 'no')
167
			->will($this->throwException(new \Exception));
168
169
		$actual = $this->controller->setConfig('skipPopover', 'no');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
171
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
172
		$this->assertEquals([], $actual->getData());
173
		$this->assertEquals(500, $actual->getStatus());
174
	}
175
176
	public function testGetPopover() {
177
		$this->config->expects($this->once())
178
			->method('getUserValue')
179
			->with('user123', $this->appName, 'skipPopover', 'no')
180
			->will($this->returnValue('agendaWeek'));
181
182
		$actual = $this->controller->getConfig('skipPopover');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
183
184
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
185
		$this->assertEquals(['value' => 'agendaWeek'], $actual->getData());
186
		$this->assertEquals(200, $actual->getStatus());
187
	}
188
189 View Code Duplication
	public function testGetPopoverWithConfigException() {
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...
190
		$this->config->expects($this->once())
191
			->method('getUserValue')
192
			->with('user123', $this->appName, 'skipPopover', 'no')
193
			->will($this->throwException(new \Exception));
194
195
		$actual = $this->controller->getConfig('skipPopover');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
196
197
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
198
		$this->assertEquals([], $actual->getData());
199
		$this->assertEquals(500, $actual->getStatus());
200
	}
201
202 View Code Duplication
	public function testSetFirstRun() {
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...
203
		$this->config->expects($this->once())
204
			->method('setUserValue')
205
			->with('user123', $this->appName, 'firstRun', 'no');
206
207
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
208
209
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
210
		$this->assertEquals([], $actual->getData());
211
		$this->assertEquals(200, $actual->getStatus());
212
	}
213
214
	public function testSetFirstRunWithException() {
215
		$this->config->expects($this->once())
216
			->method('setUserValue')
217
			->with('user123', $this->appName, 'firstRun', 'no')
218
			->will($this->throwException(new \Exception));
219
220
		$actual = $this->controller->setConfig('firstRun', 'some_random_ignored_value');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
221
222
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
223
		$this->assertEquals([], $actual->getData());
224
		$this->assertEquals(500, $actual->getStatus());
225
	}
226
227
	public function testGetFirstRun() {
228
		$this->config->expects($this->once())
229
			->method('getUserValue')
230
			->with('user123', $this->appName, 'firstRun', 'yes')
231
			->will($this->returnValue('no'));
232
233
		$actual = $this->controller->getConfig('firstRun');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
234
235
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
236
		$this->assertEquals(['value' => 'no'], $actual->getData());
237
		$this->assertEquals(200, $actual->getStatus());
238
	}
239
240 View Code Duplication
	public function testGetFirstRunWithException() {
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...
241
		$this->config->expects($this->once())
242
			->method('getUserValue')
243
			->with('user123', $this->appName, 'firstRun', 'yes')
244
			->will($this->throwException(new \Exception));
245
246
		$actual = $this->controller->getConfig('firstRun');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
247
248
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
249
		$this->assertEquals([], $actual->getData());
250
		$this->assertEquals(500, $actual->getStatus());
251
	}
252
253
	public function testSetTimezone() {
254
		$this->config->expects($this->once())
255
			->method('setUserValue')
256
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin');
257
258
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
259
260
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
261
		$this->assertEquals([], $actual->getData());
262
		$this->assertEquals(200, $actual->getStatus());
263
	}
264
265
	public function testSetTimezoneWithException() {
266
		$this->config->expects($this->once())
267
			->method('setUserValue')
268
			->with('user123', $this->appName, 'timezone', 'Europe/Berlin')
269
			->will($this->throwException(new \Exception));
270
271
		$actual = $this->controller->setConfig('timezone', 'Europe/Berlin');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
272
273
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
274
		$this->assertEquals([], $actual->getData());
275
		$this->assertEquals(500, $actual->getStatus());
276
	}
277
278
	public function testGetTimezone() {
279
		$this->config->expects($this->once())
280
			->method('getUserValue')
281
			->with('user123', $this->appName, 'timezone', 'automatic')
282
			->will($this->returnValue('Europe/Berlin'));
283
284
		$actual = $this->controller->getConfig('timezone');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
285
286
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
287
		$this->assertEquals(['value' => 'Europe/Berlin'], $actual->getData());
288
		$this->assertEquals(200, $actual->getStatus());
289
	}
290
291 View Code Duplication
	public function testGetTimezoneWithException() {
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...
292
		$this->config->expects($this->once())
293
			->method('getUserValue')
294
			->with('user123', $this->appName, 'timezone', 'automatic')
295
			->will($this->throwException(new \Exception));
296
297
		$actual = $this->controller->getConfig('timezone');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
298
299
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
300
		$this->assertEquals([], $actual->getData());
301
		$this->assertEquals(500, $actual->getStatus());
302
	}
303
304 View Code Duplication
	public function testGetNotExistingConfig() {
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...
305
		$actual = $this->controller->getConfig('foo');
0 ignored issues
show
Bug introduced by
The method getConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
306
		
307
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
308
		$this->assertEquals([], $actual->getData());
309
		$this->assertEquals(400, $actual->getStatus());
310
	}
311
312 View Code Duplication
	public function testSetNotExistingConfig() {
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...
313
		$actual = $this->controller->setConfig('foo', 'bar');
0 ignored issues
show
Bug introduced by
The method setConfig does only exist in OCA\Calendar\Controller\SettingsController, but not in OCA\Calendar\Controller\OtoLayerController.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
314
315
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
316
		$this->assertEquals([], $actual->getData());
317
		$this->assertEquals(400, $actual->getStatus());
318
	}
319
}
320