summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/Jobs/CleanUpTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/tests/Jobs/CleanUpTest.php')
-rw-r--r--apps/user_ldap/tests/Jobs/CleanUpTest.php97
1 files changed, 40 insertions, 57 deletions
diff --git a/apps/user_ldap/tests/Jobs/CleanUpTest.php b/apps/user_ldap/tests/Jobs/CleanUpTest.php
index 1e88694f7bf..533bb041f75 100644
--- a/apps/user_ldap/tests/Jobs/CleanUpTest.php
+++ b/apps/user_ldap/tests/Jobs/CleanUpTest.php
@@ -26,44 +26,49 @@
namespace OCA\User_LDAP\Tests\Jobs;
+use Exception;
use OCA\User_LDAP\Helper;
+use OCA\User_LDAP\Jobs\CleanUp;
+use OCA\User_LDAP\User\DeletedUsersIndex;
+use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
use OCP\IDBConnection;
+use Test\TestCase;
-class CleanUpTest extends \Test\TestCase {
- public function getMocks() {
- $mocks = [];
- $mocks['userBackend'] =
- $this->getMockBuilder('\OCA\User_LDAP\User_Proxy')
- ->disableOriginalConstructor()
- ->getMock();
- $mocks['deletedUsersIndex'] =
- $this->getMockBuilder('\OCA\User_LDAP\User\DeletedUsersIndex')
- ->disableOriginalConstructor()
- ->getMock();
- $mocks['ocConfig'] = $this->createMock(IConfig::class);
- $mocks['db'] = $this->createMock(IDBConnection::class);
- $mocks['helper'] = $this->createMock(Helper::class);
-
- return $mocks;
+class CleanUpTest extends TestCase {
+ /** @var CleanUp */
+ protected $bgJob;
+
+ /** @var array */
+ protected $mocks;
+
+ public function setUp(): void {
+ $this->createMocks();
+ $this->bgJob = new CleanUp($this->mocks['userBackend']);
+ $this->bgJob->setArguments($this->mocks);
+ }
+
+ protected function createMocks(): void {
+ $this->mocks = [];
+ $this->mocks['userBackend'] = $this->createMock(User_Proxy::class);
+ $this->mocks['deletedUsersIndex'] = $this->createMock(DeletedUsersIndex::class);
+ $this->mocks['ocConfig'] = $this->createMock(IConfig::class);
+ $this->mocks['db'] = $this->createMock(IDBConnection::class);
+ $this->mocks['helper'] = $this->createMock(Helper::class);
}
/**
* clean up job must not run when there are disabled configurations
*/
public function test_runNotAllowedByDisabledConfigurations() {
- $args = $this->getMocks();
- $args['helper']->expects($this->once())
+ $this->mocks['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->willReturn(true);
- $args['ocConfig']->expects($this->never())
+ $this->mocks['ocConfig']->expects($this->never())
->method('getSystemValue');
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isCleanUpAllowed();
+ $result = $this->bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
@@ -72,18 +77,14 @@ class CleanUpTest extends \Test\TestCase {
* returning unexpected results
*/
public function test_runNotAllowedByBrokenHelper() {
- $args = $this->getMocks();
- $args['helper']->expects($this->once())
+ $this->mocks['helper']->expects($this->once())
->method('haveDisabledConfigurations')
- ->will($this->throwException(new \Exception()));
+ ->will($this->throwException(new Exception()));
- $args['ocConfig']->expects($this->never())
+ $this->mocks['ocConfig']->expects($this->never())
->method('getSystemValue');
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isCleanUpAllowed();
+ $result = $this->bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
@@ -91,19 +92,15 @@ class CleanUpTest extends \Test\TestCase {
* clean up job must not run when it is not enabled
*/
public function test_runNotAllowedBySysConfig() {
- $args = $this->getMocks();
- $args['helper']->expects($this->once())
+ $this->mocks['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->willReturn(false);
- $args['ocConfig']->expects($this->once())
+ $this->mocks['ocConfig']->expects($this->once())
->method('getSystemValue')
->willReturn(false);
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isCleanUpAllowed();
+ $result = $this->bgJob->isCleanUpAllowed();
$this->assertSame(false, $result);
}
@@ -111,19 +108,15 @@ class CleanUpTest extends \Test\TestCase {
* clean up job is allowed to run
*/
public function test_runIsAllowed() {
- $args = $this->getMocks();
- $args['helper']->expects($this->once())
+ $this->mocks['helper']->expects($this->once())
->method('haveDisabledConfigurations')
->willReturn(false);
- $args['ocConfig']->expects($this->once())
+ $this->mocks['ocConfig']->expects($this->once())
->method('getSystemValue')
->willReturn(true);
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isCleanUpAllowed();
+ $result = $this->bgJob->isCleanUpAllowed();
$this->assertSame(true, $result);
}
@@ -131,12 +124,7 @@ class CleanUpTest extends \Test\TestCase {
* check whether offset will be reset when it needs to
*/
public function test_OffsetResetIsNecessary() {
- $args = $this->getMocks();
-
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isOffsetResetNecessary($bgJob->getChunkSize() - 1);
+ $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize() - 1);
$this->assertSame(true, $result);
}
@@ -144,12 +132,7 @@ class CleanUpTest extends \Test\TestCase {
* make sure offset is not reset when it is not due
*/
public function test_OffsetResetIsNotNecessary() {
- $args = $this->getMocks();
-
- $bgJob = new \OCA\User_LDAP\Jobs\CleanUp();
- $bgJob->setArguments($args);
-
- $result = $bgJob->isOffsetResetNecessary($bgJob->getChunkSize());
+ $result = $this->bgJob->isOffsetResetNecessary($this->bgJob->getChunkSize());
$this->assertSame(false, $result);
}
}