1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<?php
/**
* @author Thomas Müller
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
* later.
* See the COPYING-README file.
*/
namespace Test\App;
use OC;
use OC\App\Platform;
use OCP\IL10N;
class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
/**
* @var Platform
*/
private $platformMock;
/**
* @var IL10N
*/
private $l10nMock;
public function setUp() {
$this->platformMock = $this->getMockBuilder('\OC\App\Platform')
->disableOriginalConstructor()
->getMock();
$this->platformMock->expects($this->any())
->method('getPhpVersion')
->will( $this->returnValue('5.4.3'));
$this->platformMock->expects($this->any())
->method('getDatabase')
->will( $this->returnValue('mysql'));
$this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()
->getMock();
$this->l10nMock->expects($this->any())
->method('t')
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
}
/**
* @dataProvider providesPhpVersion
*/
public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) {
$app = array(
'dependencies' => array(
'php' => array()
)
);
if (!is_null($minVersion)) {
$app['dependencies']['php']['min-version'] = $minVersion;
}
if (!is_null($maxVersion)) {
$app['dependencies']['php']['max-version'] = $maxVersion;
}
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze();
$this->assertTrue(is_array($missing));
$this->assertEquals(count($expectedMissing), count($missing));
$this->assertEquals($expectedMissing, $missing);
}
/**
* @dataProvider providesDatabases
*/
public function testDatabases($expectedMissing, $databases) {
$app = array(
'dependencies' => array(
)
);
if (!is_null($databases)) {
$app['dependencies']['database'] = $databases;
}
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze();
$this->assertTrue(is_array($missing));
$this->assertEquals(count($expectedMissing), count($missing));
$this->assertEquals($expectedMissing, $missing);
}
function providesDatabases() {
return array(
// non BC - in case on databases are defined -> all are supported
array(array(), null),
array(array(), array()),
array(array('Following databases are supported: sqlite, postgres'), array('sqlite', 'postgres')),
);
}
function providesPhpVersion() {
return array(
array(array(), null, null),
array(array(), '5.4', null),
array(array(), null, '5.5'),
array(array(), '5.4', '5.5'),
array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'),
);
}
}
|