diff options
Diffstat (limited to 'apps/workflowengine/tests/Check')
4 files changed, 66 insertions, 139 deletions
diff --git a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php index 774f866bf12..26d4ccb8553 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], @@ -46,21 +50,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 { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteStringCheck')] + 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/'], @@ -69,12 +67,8 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheck - * @param string $operator - * @param string $value - */ - public function testValidateCheck($operator, $value): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] + public function testValidateCheck(string $operator, string $value): void { $check = $this->getCheckMock(); /** @var AbstractStringCheck $check */ @@ -83,7 +77,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'], @@ -92,14 +86,8 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheckInvalid - * @param $operator - * @param $value - * @param $exceptionCode - * @param $exceptionMessage - */ - public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] + public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { $check = $this->getCheckMock(); try { @@ -111,21 +99,15 @@ 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 ]; } - /** - * @dataProvider dataMatch - * @param string $pattern - * @param string $subject - * @param array[] $matches - * @param bool $expected - */ - public function testMatch($pattern, $subject, $matches, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataMatch')] + 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..c0e56daefa8 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], @@ -47,13 +44,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv4 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckMatchesIPv4($value, $ip, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] + public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -63,13 +55,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value)); } - /** - * @dataProvider dataExecuteCheckIPv4 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckNotMatchesIPv4($value, $ip, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] + public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -79,7 +66,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], @@ -91,13 +78,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv6 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckMatchesIPv6($value, $ip, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] + public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); $this->request->expects($this->once()) @@ -107,13 +89,8 @@ class RequestRemoteAddressTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value)); } - /** - * @dataProvider dataExecuteCheckIPv6 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckNotMatchesIPv6($value, $ip, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] + 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..a8439b8b9f4 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 @@ -67,13 +63,8 @@ class RequestTimeTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheck - * @param string $value - * @param int $timestamp - * @param bool $expected - */ - public function testExecuteCheckIn($value, $timestamp, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] + public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $this->timeFactory->expects($this->once()) @@ -83,13 +74,8 @@ class RequestTimeTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('in', $value)); } - /** - * @dataProvider dataExecuteCheck - * @param string $value - * @param int $timestamp - * @param bool $expected - */ - public function testExecuteCheckNotIn($value, $timestamp, $expected): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] + public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $this->timeFactory->expects($this->once()) @@ -99,7 +85,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"]'], @@ -107,18 +93,14 @@ class RequestTimeTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheck - * @param string $operator - * @param string $value - */ - public function testValidateCheck($operator, $value): void { + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] + 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'], @@ -130,14 +112,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 { + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] + 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..09eaea6555b 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], @@ -84,14 +82,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 { + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] + public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { $this->request->expects($this->once()) ->method('getHeader') ->willReturn($actualValue); |