diff options
Diffstat (limited to 'apps/workflowengine/tests/Check/RequestRemoteAddressTest.php')
-rw-r--r-- | apps/workflowengine/tests/Check/RequestRemoteAddressTest.php | 91 |
1 files changed, 25 insertions, 66 deletions
diff --git a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php index e0ea2269e35..c0e56daefa8 100644 --- a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php +++ b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php @@ -1,44 +1,24 @@ <?php + +declare(strict_types=1); + /** - * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> - * - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ 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 \OCP\IRequest|\PHPUnit\Framework\MockObject\MockObject */ - protected $request; + protected IRequest&MockObject $request; - /** - * @return \OCP\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) { @@ -50,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], @@ -65,14 +44,9 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv4 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckMatchesIPv4($value, $ip, $expected) { - $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->getL10NMock(), $this->request); + #[\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()) ->method('getRemoteAddress') @@ -81,14 +55,9 @@ 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) { - $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->getL10NMock(), $this->request); + #[\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()) ->method('getRemoteAddress') @@ -97,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], @@ -109,14 +78,9 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv6 - * @param string $value - * @param string $ip - * @param bool $expected - */ - public function testExecuteCheckMatchesIPv6($value, $ip, $expected) { - $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->getL10NMock(), $this->request); + #[\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()) ->method('getRemoteAddress') @@ -125,14 +89,9 @@ 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) { - $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->getL10NMock(), $this->request); + #[\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()) ->method('getRemoteAddress') |