-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIsAStrictDataTypeTest.php
87 lines (70 loc) · 3.15 KB
/
IsAStrictDataTypeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php declare(strict_types=1);
/**
* This file is part of DataTypeValidator, a PHP Experts, Inc., Project.
*
* Copyright © 2019 PHP Experts, Inc.
* Author: Theodore R. Smith <theodore@phpexperts.pro>
* GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
* https://www.phpexperts.pro/
* https://github.com/phpexpertsinc/DataTypeValidator
*
* This file is licensed under the MIT License.
*/
namespace PHPExperts\DataTypeValidator\Tests;
use PHPExperts\DataTypeValidator\IsAStrictDataType;
use PHPUnit\Framework\TestCase;
/** @testdox PHPExperts\DataTypeValidator\IsAStrictDataType */
class IsAStrictDataTypeTest extends TestCase
{
/** @var IsAStrictDataType */
private $isA;
protected function setUp(): void
{
$this->isA = new IsAStrictDataType();
parent::setUp();
}
public function testWillSayThatItIsAStrictValidator()
{
self::assertTrue($this->isA->isStrictValidator());
}
public function testWillReturnTrueForValidValues()
{
$strictTypePairs = DataTypesLists::getValidStrictDataAndTypes();
foreach ($strictTypePairs as $idx => [$expectedType, $value]) {
self::assertTrue($this->isA->isType($value, $expectedType), json_encode($value) . " ($idx) did not report as a(n) valid $expectedType.");
}
}
public function testWillReturnFalseForInvalidValues()
{
$strictTypePairs = DataTypesLists::getInvalidStrictDataAndTypes();
foreach ($strictTypePairs as $idx => [$expectedType, $value]) {
self::assertFalse($this->isA->isType($value, $expectedType), json_encode($value) . " ($idx) did not report as a(n) invalid $expectedType.");
}
}
public function testWillMatchShortClasses()
{
$object = new IsAStrictDataType();
self::assertTrue($this->isA->isType($object, 'IsAStrictDataType'));
self::assertFalse($this->isA->isType($object, 'DoesntExist'));
self::assertFalse($this->isA->isType('string', 'IsAStrictDataType'));
self::assertTrue($this->isA->isFuzzyObject($object, 'IsAStrictDataType'));
self::assertFalse($this->isA->isFuzzyObject($object, IsAStrictDataType::class));
}
public function testWillMatchSpecificClasses()
{
$object = new IsAStrictDataType();
self::assertTrue($this->isA->isType($object, IsAStrictDataType::class));
self::assertFalse($this->isA->isType($object, 'DoesntExist'));
self::assertFalse($this->isA->isSpecificObject('string', IsAStrictDataType::class));
self::assertTrue($this->isA->isSpecificObject($object, IsAStrictDataType::class));
self::assertFalse($this->isA->isSpecificObject($object, 'IsAStrictDataType'));
}
public function testWillWorkWithAnArrayOfSomething()
{
self::assertTrue($this->isA->isArrayOfSomething([1, 2, 3], 'int'));
self::assertFalse($this->isA->isArrayOfSomething([1.0, 2, 3], 'int'));
self::assertTrue($this->isA->isArrayOfSomething([1.0, 2.1, 3.3], 'float'));
self::assertFalse($this->isA->isArrayOfSomething([1, 2, 3], 'float'));
self::assertFalse($this->isA->isArrayOfSomething('asdf', 'string'));
}
}