summaryrefslogtreecommitdiff
path: root/tests/app/ValidatorTest.php
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2021-10-14 10:59:30 +0100
committerGreg Roach <greg@subaqua.co.uk>2021-10-14 11:44:44 +0100
commit2b1a9a98f423f20edfd3f92975534262a33f46f2 (patch)
treee82137169266ff82e06cdbb5044d1f60344b6270 /tests/app/ValidatorTest.php
parent545e0ff3b255df54a6f936bbb424bbddd1b648ff (diff)
downloadwebtrees-2b1a9a98f423f20edfd3f92975534262a33f46f2.tar.gz
webtrees-2b1a9a98f423f20edfd3f92975534262a33f46f2.tar.bz2
webtrees-2b1a9a98f423f20edfd3f92975534262a33f46f2.zip
Simplify type-checks in validator
Diffstat (limited to 'tests/app/ValidatorTest.php')
-rw-r--r--tests/app/ValidatorTest.php33
1 files changed, 11 insertions, 22 deletions
diff --git a/tests/app/ValidatorTest.php b/tests/app/ValidatorTest.php
index 2ab240aed8..b18a8273ea 100644
--- a/tests/app/ValidatorTest.php
+++ b/tests/app/ValidatorTest.php
@@ -114,15 +114,16 @@ class ValidatorTest extends TestCase
*/
public function testIsBetweenParameter(): void
{
- $parameters = ['param' => '42', 'invalid' => '10', 'wrongtype' => 'not_integer'];
+ $parameters = [
+ 'param' => '42',
+ 'invalid' => '10',
+ 'wrongtype' => 'not_integer',
+ ];
$validator = (new Validator($parameters))->isBetween(40, 45);
self::assertSame(42, $validator->integer('param'));
self::assertNull($validator->integer('invalid'));
self::assertNull($validator->integer('wrongtype'));
-
- $this->expectException(LogicException::class);
- $validator->string('wrongtype');
}
/**
@@ -132,21 +133,12 @@ class ValidatorTest extends TestCase
{
$parameters = [
'param' => 'X1',
- 'param2' => ['X2', 'X3'],
'invalid' => '@X1@',
- 'invalid2' => ['X2', '#X4!'],
- 'wrongtype' => '42'
];
$validator = (new Validator($parameters))->isXref();
self::assertSame('X1', $validator->string('param'));
- self::assertSame(['X2', 'X3'], $validator->array('param2'));
- self::assertNull($validator->string('param2'));
self::assertNull($validator->string('invalid'));
- self::assertNull($validator->array('invalid2'));
-
- $this->expectException(LogicException::class);
- $validator->integer('wrongtype');
}
/**
@@ -155,11 +147,11 @@ class ValidatorTest extends TestCase
public function testIsLocalUrlParameter(): void
{
$parameters = [
- 'param' => 'http://example.local/wt/page',
- 'noscheme' => '//example.local/wt/page',
- 'https' => 'https://example.local/wt/page',
- 'invalid' => 'http://example.com/wt/page',
- 'wrongtype' => '42'
+ 'param' => 'http://example.local/wt/page',
+ 'noscheme' => '//example.local/wt/page',
+ 'https' => 'https://example.local/wt/page',
+ 'invalid' => 'http://example.com/wt/page',
+ 'wrongtype' => ['42']
];
$validator = (new Validator($parameters))->isLocalUrl('http://example.local/wt');
@@ -167,10 +159,7 @@ class ValidatorTest extends TestCase
self::assertSame('//example.local/wt/page', $validator->string('noscheme'));
self::assertNull($validator->string('https'));
self::assertNull($validator->string('invalid'));
- self::assertNull($validator->integer('param'));
-
- $this->expectException(LogicException::class);
- $validator->integer('wrongtype');
+ self::assertNull($validator->string('wrongtype'));
}
/**