diff options
Diffstat (limited to 'apps/workflowengine/tests')
4 files changed, 53 insertions, 100 deletions
diff --git a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php index 774f866bf12..d10fcfb4cc3 100644 --- a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php +++ b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,9 +10,10 @@ namespace OCA\WorkflowEngine\Tests\Check; use OCA\WorkflowEngine\Check\AbstractStringCheck; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; class AbstractStringCheckTest extends \Test\TestCase { - protected function getCheckMock() { + protected function getCheckMock(): AbstractStringCheck|MockObject { $l = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); @@ -19,7 +23,7 @@ class AbstractStringCheckTest extends \Test\TestCase { return sprintf($string, $args); }); - $check = $this->getMockBuilder('OCA\WorkflowEngine\Check\AbstractStringCheck') + $check = $this->getMockBuilder(AbstractStringCheck::class) ->setConstructorArgs([ $l, ]) @@ -32,7 +36,7 @@ class AbstractStringCheckTest extends \Test\TestCase { return $check; } - public function dataExecuteStringCheck() { + public static function dataExecuteStringCheck(): array { return [ ['is', 'same', 'same', true], ['is', 'different', 'not the same', false], @@ -48,19 +52,15 @@ class AbstractStringCheckTest extends \Test\TestCase { /** * @dataProvider dataExecuteStringCheck - * @param string $operation - * @param string $checkValue - * @param string $actualValue - * @param bool $expected */ - public function testExecuteStringCheck($operation, $checkValue, $actualValue, $expected): void { + public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { $check = $this->getCheckMock(); /** @var AbstractStringCheck $check */ $this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue])); } - public function dataValidateCheck() { + public static function dataValidateCheck(): array { return [ ['is', '/Invalid(Regex/'], ['!is', '/Invalid(Regex/'], @@ -71,10 +71,8 @@ class AbstractStringCheckTest extends \Test\TestCase { /** * @dataProvider dataValidateCheck - * @param string $operator - * @param string $value */ - public function testValidateCheck($operator, $value): void { + public function testValidateCheck(string $operator, string $value): void { $check = $this->getCheckMock(); /** @var AbstractStringCheck $check */ @@ -83,7 +81,7 @@ class AbstractStringCheckTest extends \Test\TestCase { $this->addToAssertionCount(1); } - public function dataValidateCheckInvalid() { + public static function dataValidateCheckInvalid(): array { return [ ['!!is', '', 1, 'The given operator is invalid'], ['less', '', 1, 'The given operator is invalid'], @@ -94,12 +92,8 @@ class AbstractStringCheckTest extends \Test\TestCase { /** * @dataProvider dataValidateCheckInvalid - * @param $operator - * @param $value - * @param $exceptionCode - * @param $exceptionMessage */ - public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage): void { + public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { $check = $this->getCheckMock(); try { @@ -111,7 +105,7 @@ class AbstractStringCheckTest extends \Test\TestCase { } } - public function dataMatch() { + public static function dataMatch(): array { return [ ['/valid/', 'valid', [], true], ['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit @@ -120,12 +114,8 @@ class AbstractStringCheckTest extends \Test\TestCase { /** * @dataProvider dataMatch - * @param string $pattern - * @param string $subject - * @param array[] $matches - * @param bool $expected */ - public function testMatch($pattern, $subject, $matches, $expected): void { + public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void { $check = $this->getCheckMock(); $this->invokePrivate($check, 'matches', [$matches]); diff --git a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php index 47b9138819e..f2f8026e666 100644 --- a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php +++ b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -8,19 +11,14 @@ namespace OCA\WorkflowEngine\Tests\Check; use OCA\WorkflowEngine\Check\RequestRemoteAddress; use OCP\IL10N; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; class RequestRemoteAddressTest extends \Test\TestCase { - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ - protected $request; + protected IRequest&MockObject $request; - /** - * @return IL10N|\PHPUnit\Framework\MockObject\MockObject - */ - protected function getL10NMock() { - $l = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor() - ->getMock(); + protected function getL10NMock(): IL10N&MockObject { + $l = $this->createMock(IL10N::class); $l->expects($this->any()) ->method('t') ->willReturnCallback(function ($string, $args) { @@ -32,11 +30,10 @@ class RequestRemoteAddressTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->request = $this->getMockBuilder(IRequest::class) - ->getMock(); + $this->request = $this->createMock(IRequest::class); } - public function dataExecuteCheckIPv4() { + public static function dataExecuteCheckIPv4(): array { return [ ['127.0.0.1/32', '127.0.0.1', true], ['127.0.0.1/32', '127.0.0.0', false], @@ -49,11 +46,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheckIPv4 - * @param string $value - * @param string $ip - * @param bool $expected */ - public function testExecuteCheckMatchesIPv4($value, $ip, $expected): void { + public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -65,11 +59,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheckIPv4 - * @param string $value - * @param string $ip - * @param bool $expected */ - public function testExecuteCheckNotMatchesIPv4($value, $ip, $expected): void { + public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -79,7 +70,7 @@ class RequestRemoteAddressTest extends \Test\TestCase { $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value)); } - public function dataExecuteCheckIPv6() { + public static function dataExecuteCheckIPv6(): array { return [ ['::1/128', '::1', true], ['::2/128', '::3', false], @@ -93,11 +84,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheckIPv6 - * @param string $value - * @param string $ip - * @param bool $expected */ - public function testExecuteCheckMatchesIPv6($value, $ip, $expected): void { + public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -109,11 +97,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheckIPv6 - * @param string $value - * @param string $ip - * @param bool $expected */ - public function testExecuteCheckNotMatchesIPv6($value, $ip, $expected): void { + public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) diff --git a/apps/workflowengine/tests/Check/RequestTimeTest.php b/apps/workflowengine/tests/Check/RequestTimeTest.php index 6b56bb9427a..21127d4d56e 100644 --- a/apps/workflowengine/tests/Check/RequestTimeTest.php +++ b/apps/workflowengine/tests/Check/RequestTimeTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -8,19 +11,13 @@ namespace OCA\WorkflowEngine\Tests\Check; use OCA\WorkflowEngine\Check\RequestTime; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; class RequestTimeTest extends \Test\TestCase { + protected ITimeFactory&MockObject $timeFactory; - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ - protected $timeFactory; - - /** - * @return IL10N|\PHPUnit\Framework\MockObject\MockObject - */ - protected function getL10NMock() { - $l = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor() - ->getMock(); + protected function getL10NMock(): IL10N&MockObject { + $l = $this->createMock(IL10N::class); $l->expects($this->any()) ->method('t') ->willReturnCallback(function ($string, $args) { @@ -32,11 +29,10 @@ class RequestTimeTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory') - ->getMock(); + $this->timeFactory = $this->createMock(ITimeFactory::class); } - public function dataExecuteCheck() { + public static function dataExecuteCheck(): array { return [ [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00 [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00 @@ -69,11 +65,8 @@ class RequestTimeTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheck - * @param string $value - * @param int $timestamp - * @param bool $expected */ - public function testExecuteCheckIn($value, $timestamp, $expected): void { + public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $this->timeFactory->expects($this->once()) @@ -85,11 +78,8 @@ class RequestTimeTest extends \Test\TestCase { /** * @dataProvider dataExecuteCheck - * @param string $value - * @param int $timestamp - * @param bool $expected */ - public function testExecuteCheckNotIn($value, $timestamp, $expected): void { + public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $this->timeFactory->expects($this->once()) @@ -99,7 +89,7 @@ class RequestTimeTest extends \Test\TestCase { $this->assertEquals(!$expected, $check->executeCheck('!in', $value)); } - public function dataValidateCheck() { + public static function dataValidateCheck(): array { return [ ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'], ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'], @@ -109,16 +99,14 @@ class RequestTimeTest extends \Test\TestCase { /** * @dataProvider dataValidateCheck - * @param string $operator - * @param string $value */ - public function testValidateCheck($operator, $value): void { + public function testValidateCheck(string $operator, string $value): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $check->validateCheck($operator, $value); $this->addToAssertionCount(1); } - public function dataValidateCheckInvalid() { + public static function dataValidateCheckInvalid(): array { return [ ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'], ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'], @@ -132,12 +120,8 @@ class RequestTimeTest extends \Test\TestCase { /** * @dataProvider dataValidateCheckInvalid - * @param string $operator - * @param string $value - * @param int $exceptionCode - * @param string $exceptionMessage */ - public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage): void { + public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); try { diff --git a/apps/workflowengine/tests/Check/RequestUserAgentTest.php b/apps/workflowengine/tests/Check/RequestUserAgentTest.php index 30e389c8236..2fe96bf3bdb 100644 --- a/apps/workflowengine/tests/Check/RequestUserAgentTest.php +++ b/apps/workflowengine/tests/Check/RequestUserAgentTest.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -9,24 +12,19 @@ use OCA\WorkflowEngine\Check\AbstractStringCheck; use OCA\WorkflowEngine\Check\RequestUserAgent; use OCP\IL10N; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RequestUserAgentTest extends TestCase { - - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ - protected $request; - - /** @var RequestUserAgent */ - protected $check; + protected IRequest&MockObject $request; + protected RequestUserAgent $check; protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l */ - $l = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor() - ->getMock(); + /** @var IL10N&MockObject $l */ + $l = $this->createMock(IL10N::class); $l->expects($this->any()) ->method('t') ->willReturnCallback(function ($string, $args) { @@ -36,7 +34,7 @@ class RequestUserAgentTest extends TestCase { $this->check = new RequestUserAgent($l, $this->request); } - public function dataExecuteCheck() { + public static function dataExecuteCheck(): array { return [ ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true], ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false], @@ -86,12 +84,8 @@ class RequestUserAgentTest extends TestCase { /** * @dataProvider dataExecuteCheck - * @param string $operation - * @param string $checkValue - * @param string $actualValue - * @param bool $expected */ - public function testExecuteCheck($operation, $checkValue, $actualValue, $expected): void { + public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { $this->request->expects($this->once()) ->method('getHeader') ->willReturn($actualValue); |