summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLEDfan <tobia@ledfan.be>2014-12-07 14:10:41 +0100
committerLEDfan <tobia@ledfan.be>2014-12-07 14:10:41 +0100
commitc05ff0965198c61068924e81d35cba3549452ce3 (patch)
treeb4738660aef21bcdf9c388b89cf30147102d873e
parent88ad095cc797dd0590b1bceaa79447f67ce480c1 (diff)
downloadnextcloud-server-c05ff0965198c61068924e81d35cba3549452ce3.tar.gz
nextcloud-server-c05ff0965198c61068924e81d35cba3549452ce3.zip
Use PHPUnit mocks
-rw-r--r--config/config-mysql.php21
-rw-r--r--tests/lib/contactsmanager.php57
2 files changed, 51 insertions, 27 deletions
diff --git a/config/config-mysql.php b/config/config-mysql.php
new file mode 100644
index 00000000000..898dfb95b21
--- /dev/null
+++ b/config/config-mysql.php
@@ -0,0 +1,21 @@
+<?php
+$CONFIG = array (
+ 'instanceid' => 'oclip61vhpsy',
+ 'passwordsalt' => 'M8h9O5EuS/tpqehZDb.C18yIBWd9HO',
+ 'secret' => 'rBz4iMuGwItwHf0qA9q5DeLG73NONGaRCztPQWUDSbjkqCj7',
+ 'trusted_domains' =>
+ array (
+ 0 => '33.33.33.33',
+ ),
+ 'datadirectory' => '/var/www/owncloud/data',
+ 'overwrite.cli.url' => 'http://33.33.33.33',
+ 'dbtype' => 'mysql',
+ 'version' => '7.8.1.0',
+ 'dbname' => 'owncloud',
+ 'dbhost' => 'localhost',
+ 'dbtableprefix' => 'oc_',
+ 'dbuser' => 'owncloud',
+ 'dbpassword' => 'random',
+ 'installed' => true,
+);
+define("DEBUG",1); \ No newline at end of file
diff --git a/tests/lib/contactsmanager.php b/tests/lib/contactsmanager.php
index 1deeb818f0f..20341ea455a 100644
--- a/tests/lib/contactsmanager.php
+++ b/tests/lib/contactsmanager.php
@@ -47,13 +47,10 @@ class Test_ContactsManager extends \Test\TestCase {
);
$expectedResult = array_merge($search1, $search2);
-
return array(
array(
- array(
- new SimpleAddressbook('simple:1', 'Simeple Addressbook 1', $search1, \OCP\Constants::PERMISSION_ALL),
- new SimpleAddressbook('simple:2', 'Simeple Addressbook 2', $search2, \OCP\Constants::PERMISSION_ALL),
- ),
+ $search1,
+ $search2,
$expectedResult
)
);
@@ -62,10 +59,34 @@ class Test_ContactsManager extends \Test\TestCase {
/**
* @dataProvider searchProvider
*/
- public function testSearch(array $addressBooks,$expectedResult ){
- foreach ($addressBooks as $addressBook) {
- $this->cm->registerAddressBook($addressBook);
- }
+ public function testSearch($search1, $search2, $expectedResult ){
+ $addressbook1 = $this->getMockBuilder('SimpleAddressbook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook1->expects($this->once())
+ ->method('search')
+ ->willReturn($search1);
+
+ $addressbook1->expects($this->any())
+ ->method('getKey')
+ ->willReturn('simple:1');
+
+ $addressbook2 = $this->getMockBuilder('SimpleAddressbook')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $addressbook2->expects($this->once())
+ ->method('search')
+ ->willReturn($search2);
+
+ $addressbook2->expects($this->any())
+ ->method('getKey')
+ ->willReturn('simple:2');
+
+
+ $this->cm->registerAddressBook($addressbook1);
+ $this->cm->registerAddressBook($addressbook2);
$result = $this->cm->search('');
$this->assertEquals($expectedResult, $result);
}
@@ -185,41 +206,23 @@ class Test_ContactsManager extends \Test\TestCase {
$this->assertTrue($result);
}
-
-
-
-
-
}
-
class SimpleAddressbook implements \OCP\IAddressBook {
- public function __construct($key, $displayName, $contacts, $permissions){
- $this->key = $key;
- $this->contacts = $contacts;
- $this->displayName = $displayName;
- $this->permissions = $permissions;
- }
-
-
public function getKey(){
- return $this->key;
}
public function getDisplayName(){
- return $this->displayName;
}
public function search($pattern, $searchProperties, $options){
- return $this->contacts;
}
public function createOrUpdate($properties){
}
public function getPermissions(){
- return $this->permissions;
}
public function delete($id){