Skip to content

Commit

Permalink
Merge pull request #282 from nextcloud/fix-tests
Browse files Browse the repository at this point in the history
Fix unit test compatibility issues with phpunit 5.2+
  • Loading branch information
schiessle authored Jul 1, 2016
2 parents 7e4366e + ce6009e commit 756b0c0
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 50 deletions.
10 changes: 0 additions & 10 deletions apps/dav/tests/unit/comments/commentsplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,6 @@ public function testCreateCommentInvalidPayload() {
->with('users', 'alice', 'files', '42')
->will($this->returnValue($comment));

$this->commentsManager->expects($this->any())
->method('setMessage')
->with('')
->will($this->throwException(new \InvalidArgumentException()));

$this->commentsManager->expects($this->any())
->method('setVerb')
->with('')
->will($this->throwException(new \InvalidArgumentException()));

$this->userSession->expects($this->once())
->method('getUser')
->will($this->returnValue($user));
Expand Down
48 changes: 26 additions & 22 deletions apps/dav/tests/unit/connector/sabre/filesplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,37 @@ public function setUp() {

/**
* @param string $class
* @param bool $hasAllMethods
* @return \PHPUnit_Framework_MockObject_MockObject|\Sabre\DAV\IFile
*/
private function createTestNode($class) {
private function createTestNode($class, $hasAllMethods = true)
{
$node = $this->getMockBuilder($class)
->disableOriginalConstructor()
->getMock();
$node->expects($this->any())
->method('getId')
->will($this->returnValue(123));

$this->tree->expects($this->any())
->method('getNodeForPath')
->with('/dummypath')
->will($this->returnValue($node));

$node->expects($this->any())
->method('getFileId')
->will($this->returnValue('00000123instanceid'));
$node->expects($this->any())
->method('getInternalFileId')
->will($this->returnValue('123'));
$node->expects($this->any())
->method('getEtag')
->will($this->returnValue('"abc"'));
$node->expects($this->any())
->method('getDavPermissions')
->will($this->returnValue('DWCKMSR'));
if ($hasAllMethods) {
$node->expects($this->any())
->method('getId')
->will($this->returnValue(123));
$node->expects($this->any())
->method('getFileId')
->will($this->returnValue('00000123instanceid'));
$node->expects($this->any())
->method('getInternalFileId')
->will($this->returnValue('123'));
$node->expects($this->any())
->method('getEtag')
->will($this->returnValue('"abc"'));
$node->expects($this->any())
->method('getDavPermissions')
->will($this->returnValue('DWCKMSR'));
}

return $node;
}
Expand Down Expand Up @@ -169,7 +174,7 @@ public function testGetPropertiesForFile() {
}

public function testGetPropertiesForFileHome() {
$node = $this->createTestNode('\OCA\DAV\Files\FilesHome');
$node = $this->createTestNode('\OCA\DAV\Files\FilesHome', false);

$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
Expand All @@ -190,9 +195,9 @@ public function testGetPropertiesForFileHome() {
->disableOriginalConstructor()->getMock();
$user->expects($this->never())->method('getUID');
$user->expects($this->never())->method('getDisplayName');
$node->expects($this->never())->method('getDirectDownload');
$node->expects($this->never())->method('getOwner');
$node->expects($this->never())->method('getSize');
// Method does not exist: $node->expects($this->never())->method('getDirectDownload');
// Method does not exist: $node->expects($this->never())->method('getOwner');
// Method does not exist: $node->expects($this->never())->method('getSize');

$this->plugin->handleGetProperties(
$propFind,
Expand Down Expand Up @@ -285,8 +290,7 @@ public function testGetPropertiesForDirectory() {
0
);

$node->expects($this->never())
->method('getDirectDownload');
// Method does not exist: $node->expects($this->never())->method('getDirectDownload');
$node->expects($this->once())
->method('getSize')
->will($this->returnValue(1025));
Expand Down
10 changes: 6 additions & 4 deletions apps/encryption/tests/lib/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
use OCA\Encryption\Migration;
use OCP\ILogger;

/**
* Class MigrationTest
* @package OCA\Encryption\Tests
* @group DB
*/
class MigrationTest extends \Test\TestCase {

const TEST_ENCRYPTION_MIGRATION_USER1='test_encryption_user1';
Expand All @@ -39,7 +44,7 @@ class MigrationTest extends \Test\TestCase {
private $recovery_key_id = 'recovery_key_id';
private $moduleId;

/** @var PHPUnit_Framework_MockObject_MockObject | ILogger */
/** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */
private $logger;

public static function setUpBeforeClass() {
Expand Down Expand Up @@ -512,12 +517,9 @@ public function prepareFileCache() {
*/
public function testGetTargetDir($user, $keyPath, $filename, $trash, $systemMounts, $expected) {

$updater = $this->getMockBuilder('\OC\Files\Cache\Updater')
->disableOriginalConstructor()->getMock();
$view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()->getMock();
$view->expects($this->any())->method('file_exists')->willReturn(true);
$view->expects($this->any())->method('getUpdater')->willReturn($updater);


$m = $this->getMockBuilder('OCA\Encryption\Migration')
Expand Down
3 changes: 0 additions & 3 deletions apps/encryption/tests/lib/crypto/encryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ public function endTest() {
$this->cryptMock->expects($this->any())
->method('multiKeyEncrypt')
->willReturn(true);
$this->cryptMock->expects($this->any())
->method('setAllFileKeys')
->willReturn(true);

$this->instance->end('/foo/bar');
}
Expand Down
6 changes: 3 additions & 3 deletions apps/files_sharing/tests/api/share20ocstest.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public function testCreateShareUser() {
$user = $this->getMock('\OCP\IUser');
$this->userManager->method('userExists')->with('validUser')->willReturn(true);

$share->method('setPath')->with($path);
$share->method('setNode')->with($path);
$share->method('setPermissions')
->with(
\OCP\Constants::PERMISSION_ALL &
Expand Down Expand Up @@ -773,7 +773,7 @@ public function testCreateShareGroup() {
->method('allowGroupSharing')
->willReturn(true);

$share->method('setPath')->with($path);
$share->method('setNode')->with($path);
$share->method('setPermissions')->with(\OCP\Constants::PERMISSION_ALL);
$share->method('setShareType')->with(\OCP\Share::SHARE_TYPE_GROUP);
$share->method('setSharedWith')->with('validGroup');
Expand Down Expand Up @@ -822,7 +822,7 @@ public function testCreateShareGroupNotAllowed() {
->method('allowGroupSharing')
->willReturn(false);

$share->method('setPath')->with($path);
$share->method('setNode')->with($path);

$expected = new \OC_OCS_Result(null, 404, 'group sharing is disabled by the administrator');
$result = $this->ocs->createShare();
Expand Down
6 changes: 1 addition & 5 deletions apps/files_sharing/tests/controller/sharecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ protected function setUp() {
$this->userManager = $this->getMock('\OCP\IUserManager');
$this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
->disableOriginalConstructor()->getMock();
$this->federatedShareProvider->expects($this->any())
->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
$this->federatedShareProvider->expects($this->any())
->method('isIncomingServer2serverShareEnabled')->willReturn(true);

$this->shareController = new \OCA\Files_Sharing\Controllers\ShareController(
$this->appName,
Expand Down Expand Up @@ -476,4 +472,4 @@ public function testDownloadShareWithCreateOnlyShare() {
$this->assertEquals($expectedResponse, $response);
}

}
}
2 changes: 1 addition & 1 deletion tests/core/controller/avatarcontrollertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function setUp() {
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);

$this->avatarFile = $this->getMock('OCP\Files\File');
$this->avatarFile->method('getContnet')->willReturn('image data');
$this->avatarFile->method('getContent')->willReturn('image data');
$this->avatarFile->method('getMimeType')->willReturn('image type');
$this->avatarFile->method('getEtag')->willReturn('my etag');
}
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/appframework/db/mappertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ public function testUpdateNothingChangedNoQuery(){
$entity->resetUpdatedFields();

$this->db->expects($this->never())
->method('prepareQuery');
->method('prepare');
$this->db->expects($this->never())
->method('prepare');

$this->mapper->update($entity);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/notification/notificationtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ public function testIsValid($isValidCommon, $subject, $expected) {
->setMethods([
'isValidCommon',
'getSubject',
'getParsedSubject',
])
->getMock();

Expand Down Expand Up @@ -547,6 +548,7 @@ public function testIsParsedValid($isValidCommon, $subject, $expected) {
$notification = $this->getMockBuilder('\OC\Notification\Notification')
->setMethods([
'isValidCommon',
'getSubject',
'getParsedSubject',
])
->getMock();
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/preview/movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

namespace Test\Preview;

/**
* Class Movie
* @package Test\Preview
* @group DB
*/
class Movie extends Provider {

public function setUp() {
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/preview/office.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

namespace Test\Preview;

/**
* Class Office
* @package Test\Preview
* @group DB
*/
class Office extends Provider {

public function setUp() {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/share20/managertest.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwn
$share->method('getShareType')->willReturn($type);
$share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getSharedOwner')->willReturn($shareOwner);
$share->method('getShareOwner')->willReturn($shareOwner);
$share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions);
$share->method('getExpirationDate')->willReturn($expireDate);
Expand Down

0 comments on commit 756b0c0

Please sign in to comment.