Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHPUnit warnings on NODB runs #1314

Merged
merged 22 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/encryption/tests/HookManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


use OCA\Encryption\HookManager;
use OCP\IConfig;
use Test\TestCase;

class HookManagerTest extends TestCase {
Expand All @@ -42,7 +43,7 @@ public function testRegisterHookWithArray() {
self::$instance->registerHook([
$this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('OCA\Encryption\Hooks\Contracts\IHook')->disableOriginalConstructor()->getMock(),
$this->getMock('NotIHook')
$this->createMock(IConfig::class)
]);

$hookInstances = self::invokePrivate(self::$instance, 'hookInstances');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function testValidateCode() {
->will($this->returnValue($codes));
$this->hasher->expects($this->once())
->method('verify')
->with('CHALLENGE', 'HASHEDVALUE')
->with('CHALLENGE', 'HASHEDVALUE', $this->anything())
->will($this->returnValue(true));
$this->mapper->expects($this->once())
->method('update')
Expand All @@ -195,7 +195,7 @@ public function testValidateUsedCode() {
->with($user)
->will($this->returnValue($codes));
$this->hasher->expects($this->never())
->method('verifiy');
->method('verify');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this test have failed because of "unmockable method"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phpunit warns about it.

$this->mapper->expects($this->never())
->method('update');

Expand Down
24 changes: 15 additions & 9 deletions tests/Settings/Controller/AuthSettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
use OC\AppFramework\Http;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Settings\Controller\AuthSettingsController;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException;
use Test\TestCase;

Expand All @@ -45,13 +51,13 @@ class AuthSettingsControllerTest extends TestCase {
protected function setUp() {
parent::setUp();

$this->request = $this->getMock('\OCP\IRequest');
$this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
$this->userManager = $this->getMock('\OCP\IUserManager');
$this->session = $this->getMock('\OCP\ISession');
$this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom');
$this->request = $this->createMock(IRequest::class);
$this->tokenProvider = $this->createMock(IProvider::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->session = $this->createMock(ISession::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->uid = 'jane';
$this->user = $this->getMock('\OCP\IUser');
$this->user = $this->createMock(IUser::class);

$this->controller = new AuthSettingsController('core', $this->request, $this->tokenProvider, $this->userManager, $this->session, $this->secureRandom, $this->uid);
}
Expand Down Expand Up @@ -105,8 +111,8 @@ public function testIndex() {

public function testCreate() {
$name = 'Nexus 4';
$sessionToken = $this->getMock('\OC\Authentication\Token\IToken');
$deviceToken = $this->getMock('\OC\Authentication\Token\IToken');
$sessionToken = $this->createMock(IToken::class);
$deviceToken = $this->createMock(IToken::class);
$password = '123456';

$this->session->expects($this->once())
Expand Down Expand Up @@ -175,7 +181,7 @@ public function testCreateInvalidToken() {

public function testDestroy() {
$id = 123;
$user = $this->getMock('\OCP\IUser');
$user = $this->createMock(IUser::class);

$this->userManager->expects($this->once())
->method('get')
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/AppFramework/Db/MapperTestUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp(){
->disableOriginalConstructor()
->getMock();

$this->query = $this->getMock('\PDOStatement');
$this->query = $this->createMock('\PDOStatement');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why didn't you use the ::class property here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah I could now probabaly Just forgot.

$this->queryAt = 0;
$this->prepareAt = 0;
$this->iterators = [];
Expand Down
35 changes: 17 additions & 18 deletions tests/lib/Command/Integrity/SignAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use OC\IntegrityCheck\Checker;
use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OCP\IURLGenerator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;

class SignAppTest extends TestCase {
Expand All @@ -38,12 +40,9 @@ class SignAppTest extends TestCase {

public function setUp() {
parent::setUp();
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
$this->fileAccessHelper = $this->getMockBuilder('\OC\IntegrityCheck\Helpers\FileAccessHelper')
->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
->disableOriginalConstructor()->getMock();
$this->checker = $this->createMock(Checker::class);
$this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->signApp = new SignApp(
$this->checker,
$this->fileAccessHelper,
Expand All @@ -52,8 +51,8 @@ public function setUp() {
}

public function testExecuteWithMissingPath() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand All @@ -80,8 +79,8 @@ public function testExecuteWithMissingPath() {
}

public function testExecuteWithMissingPrivateKey() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand All @@ -108,8 +107,8 @@ public function testExecuteWithMissingPrivateKey() {
}

public function testExecuteWithMissingCertificate() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand All @@ -136,8 +135,8 @@ public function testExecuteWithMissingCertificate() {
}

public function testExecuteWithNotExistingPrivateKey() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down Expand Up @@ -170,8 +169,8 @@ public function testExecuteWithNotExistingPrivateKey() {
}

public function testExecuteWithNotExistingCertificate() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down Expand Up @@ -209,8 +208,8 @@ public function testExecuteWithNotExistingCertificate() {
}

public function testExecute() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down
28 changes: 14 additions & 14 deletions tests/lib/Command/Integrity/SignCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use OC\Core\Command\Integrity\SignCore;
use OC\IntegrityCheck\Checker;
use OC\IntegrityCheck\Helpers\FileAccessHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;

class SignCoreTest extends TestCase {
Expand All @@ -35,19 +37,17 @@ class SignCoreTest extends TestCase {

public function setUp() {
parent::setUp();
$this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
->disableOriginalConstructor()->getMock();
$this->fileAccessHelper = $this->getMockBuilder('\OC\IntegrityCheck\Helpers\FileAccessHelper')
->disableOriginalConstructor()->getMock();
$this->checker = $this->createMock(Checker::class);
$this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
$this->signCore = new SignCore(
$this->checker,
$this->fileAccessHelper
);
}

public function testExecuteWithMissingPrivateKey() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand All @@ -69,8 +69,8 @@ public function testExecuteWithMissingPrivateKey() {
}

public function testExecuteWithMissingCertificate() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand All @@ -92,8 +92,8 @@ public function testExecuteWithMissingCertificate() {
}

public function testExecuteWithNotExistingPrivateKey() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down Expand Up @@ -126,8 +126,8 @@ public function testExecuteWithNotExistingPrivateKey() {
}

public function testExecuteWithNotExistingCertificate() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down Expand Up @@ -165,8 +165,8 @@ public function testExecuteWithNotExistingCertificate() {
}

public function testExecute() {
$inputInterface = $this->getMock('\Symfony\Component\Console\Input\InputInterface');
$outputInterface = $this->getMock('\Symfony\Component\Console\Output\OutputInterface');
$inputInterface = $this->createMock(InputInterface::class);
$outputInterface = $this->createMock(OutputInterface::class);

$inputInterface
->expects($this->at(0))
Expand Down
11 changes: 7 additions & 4 deletions tests/lib/Encryption/EncryptionWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@


use OC\Encryption\EncryptionWrapper;
use OC\Encryption\Manager;
use OC\Memcache\ArrayCache;
use OCP\ILogger;
use Test\TestCase;

class EncryptionWrapperTest extends TestCase {
Expand All @@ -43,10 +46,10 @@ class EncryptionWrapperTest extends TestCase {
public function setUp() {
parent::setUp();

$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$this->manager = $this->getMockBuilder('OC\Encryption\Manager')
->disableOriginalConstructor()->getMock();
$this->logger = $this->getMock('OCP\ILogger');
$this->arrayCache = $this->createMock(ArrayCache::class);
$this->manager = $this->createMock(Manager::class);
$this->logger = $this->createMock(ILogger::class);
$this->logger = $this->createMock(ILogger::class);

$this->instance = new EncryptionWrapper($this->arrayCache, $this->manager, $this->logger);
}
Expand Down
23 changes: 15 additions & 8 deletions tests/lib/Encryption/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
namespace Test\Encryption;

use OC\Encryption\Manager;
use OC\Encryption\Util;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use Test\TestCase;

class ManagerTest extends TestCase {
Expand Down Expand Up @@ -30,12 +37,12 @@ class ManagerTest extends TestCase {

public function setUp() {
parent::setUp();
$this->config = $this->getMock('\OCP\IConfig');
$this->logger = $this->getMock('\OCP\ILogger');
$this->l10n = $this->getMock('\OCP\Il10n');
$this->view = $this->getMock('\OC\Files\View');
$this->util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock();
$this->arrayCache = $this->getMock('OC\Memcache\ArrayCache');
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(ILogger::class);
$this->l10n = $this->createMock(IL10N::class);
$this->view = $this->createMock(View::class);
$this->util = $this->createMock(Util::class);
$this->arrayCache = $this->createMock(ArrayCache::class);
$this->manager = new Manager($this->config, $this->logger, $this->l10n, $this->view, $this->util, $this->arrayCache);
}

Expand All @@ -50,7 +57,7 @@ public function testManagerIsDisabledIfEnabledButNoModules() {

public function testManagerIsDisabledIfDisabledButModules() {
$this->config->expects($this->any())->method('getAppValue')->willReturn(false);
$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn('id');
$em->expects($this->any())->method('getDisplayName')->willReturn('TestDummyModule0');
$this->manager->registerEncryptionModule('id', 'TestDummyModule0', function() use ($em) {return $em;});
Expand Down Expand Up @@ -235,7 +242,7 @@ public function testSetDefaultEncryptionModule() {
// }

protected function addNewEncryptionModule(Manager $manager, $id) {
$encryptionModule = $this->getMock('\OCP\Encryption\IEncryptionModule');
$encryptionModule = $this->createMock(IEncryptionModule::class);
$encryptionModule->expects($this->any())
->method('getId')
->willReturn('ID' . $id);
Expand Down
5 changes: 3 additions & 2 deletions tests/lib/Encryption/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Test\Encryption;

use OC\Encryption\Util;
use OCP\Encryption\IEncryptionModule;
use Test\TestCase;

class UtilTest extends TestCase {
Expand Down Expand Up @@ -77,7 +78,7 @@ public function providesHeadersForEncryptionModule() {
*/
public function testCreateHeader($expected, $header, $moduleId) {

$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn($moduleId);

$result = $this->util->createHeader($header, $em);
Expand All @@ -100,7 +101,7 @@ public function testCreateHeaderFailed() {

$header = array('header1' => 1, 'header2' => 2, 'oc_encryption_module' => 'foo');

$em = $this->getMock('\OCP\Encryption\IEncryptionModule');
$em = $this->createMock(IEncryptionModule::class);
$em->expects($this->any())->method('getId')->willReturn('moduleId');

$this->util->createHeader($header, $em);
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/FileChunkingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
namespace Test;

use OCP\ICache;

class FileChunkingTest extends \Test\TestCase {

public function dataIsComplete() {
Expand Down Expand Up @@ -54,7 +56,7 @@ public function testIsComplete($total, array $present, $expected) {
]])
->getMock();

$cache = $this->getMock('\OCP\ICache');
$cache = $this->createMock(ICache::class);

$cache->expects($this->atLeastOnce())
->method('hasKey')
Expand Down
Loading