|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* EGroupware Api: Application test base class |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://www.stylite.de |
|
6
|
|
|
* @package api |
|
7
|
|
|
* @subpackage test |
|
8
|
|
|
* @author Nathan Gray |
|
9
|
|
|
* @copyright (c) 2016 Nathan Gray |
|
10
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
|
11
|
|
|
* @version $Id$ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace EGroupware\Api; |
|
15
|
|
|
|
|
16
|
|
|
// test base providing Egw environment |
|
17
|
|
|
require_once 'LoggedInTest.php'; |
|
18
|
|
|
|
|
19
|
|
|
use EGroupware\Api; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Base class for application tests, loads the egroupware environment and provides |
|
23
|
|
|
* some handy helpers. |
|
24
|
|
|
* |
|
25
|
|
|
* Extend this class into <appname>/tests/ to test one |
|
26
|
|
|
* small aspect of an application. For more basic (actual unit) tests that deal |
|
27
|
|
|
* with a single function, consider extending TestCase directly instead of this |
|
28
|
|
|
* class to avoid the overhead of creating the session. |
|
29
|
|
|
*/ |
|
30
|
|
|
abstract class AppTest extends LoggedInTest |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Sets the tracking object to a mock object, so we don't try to send real |
|
34
|
|
|
* notifications while testing. |
|
35
|
|
|
* |
|
36
|
|
|
* After calling this to mock the tracking object, you can set expectations |
|
37
|
|
|
* for tracking: |
|
38
|
|
|
* <code> |
|
39
|
|
|
* $this->mockTracking($this->bo, 'app_tracker'); |
|
40
|
|
|
* |
|
41
|
|
|
* // we do not expect track to get called for a new entry |
|
42
|
|
|
* $this->bo->tracking->expects($this->never()) |
|
43
|
|
|
* ->method('track'); |
|
44
|
|
|
* |
|
45
|
|
|
* $this->bo->save($entry); |
|
46
|
|
|
* </code> |
|
47
|
|
|
* @param Object $bo_object Instance of the BO object |
|
48
|
|
|
* @param String $tracker_class The name of the tracker class to mock |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function mockTracking(&$bo_object, $tracker_class) |
|
51
|
|
|
{ |
|
52
|
|
|
if(!is_object($bo_object)) |
|
53
|
|
|
{ |
|
54
|
|
|
throw new \BadMethodCallException('Invalid BO object'); |
|
55
|
|
|
} |
|
56
|
|
|
if(!property_exists($bo_object, 'tracking')) |
|
57
|
|
|
{ |
|
58
|
|
|
throw new \BadMethodCallException('Invalid BO object - needs tracking property'); |
|
59
|
|
|
} |
|
60
|
|
|
$bo_object->tracking = $this->getMockBuilder($tracker_class) |
|
61
|
|
|
->disableOriginalConstructor() |
|
62
|
|
|
->setMethods(['track']) |
|
63
|
|
|
->getMock($bo_object); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.