|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
require_once dirname(__FILE__, 2) . '/src/function-constants.php'; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use PinkCrab\FunctionConstructors\Functions; |
|
9
|
|
|
|
|
10
|
|
|
class FunctionConstantsTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** @testdox It should be possible to use a constant for Comparisons\notEmpty() as a callable */ |
|
13
|
|
|
public function testNotEmptyConstant() |
|
14
|
|
|
{ |
|
15
|
|
|
// With arrays |
|
16
|
|
|
$this->assertTrue(call_user_func(Functions::NOT_EMPTY, array( 'test' ))); |
|
17
|
|
|
$this->assertFalse(call_user_func(Functions::NOT_EMPTY, array())); |
|
18
|
|
|
|
|
19
|
|
|
// With strings |
|
20
|
|
|
$this->assertTrue(call_user_func(Functions::NOT_EMPTY, 'test')); |
|
21
|
|
|
$this->assertFalse(call_user_func(Functions::NOT_EMPTY, '')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** @testdox It should be possible to use a constant for Arrays\head() as a callable */ |
|
25
|
|
|
public function testArrayHead(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->assertEquals('1', call_user_func(Functions::ARRAY_HEAD, array( '1', '2' ))); |
|
28
|
|
|
$this->assertNull(call_user_func(Functions::ARRAY_HEAD, array())); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** @testdox It should be possible to use a constant for Arrays\tail() as a callable */ |
|
32
|
|
|
public function testArrayTail(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertEquals('2', call_user_func(Functions::ARRAY_TAIL, array( '1', '2' ))); |
|
35
|
|
|
$this->assertNull(call_user_func(Functions::ARRAY_TAIL, array())); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** @testdox It should be possible to use a constant for Comparisons\isTrue() as a callable */ |
|
39
|
|
|
public function testIsTrue(): void |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
// Only a true should pass |
|
43
|
|
|
$this->assertTrue(call_user_func(Functions::IS_TRUE, true)); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, false)); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, 0)); |
|
48
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, 1)); |
|
49
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, 8)); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, '')); |
|
52
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, '1')); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, array())); |
|
55
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, array( 1, 2, 3 ))); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertFalse(call_user_func(Functions::IS_TRUE, null)); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** @testdox It should be possible to use a constant for Comparisons\isFalse() as a callable */ |
|
61
|
|
|
public function testIsFalse(): void |
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
|
|
// Only a false should pass |
|
65
|
|
|
$this->assertTrue(call_user_func(Functions::IS_FALSE, false)); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, true)); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, 0)); |
|
70
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, 1)); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, '')); |
|
73
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, '0')); |
|
74
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, '1')); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, array())); |
|
77
|
|
|
|
|
78
|
|
|
$this->assertFalse(call_user_func(Functions::IS_FALSE, null)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** @testdox It should be possible to use a constant for Comparisons\isNumber() as a callable */ |
|
82
|
|
|
public function testIsNumber(): void |
|
83
|
|
|
{ |
|
84
|
|
|
|
|
85
|
|
|
// Only a number should pass |
|
86
|
|
|
$this->assertTrue(call_user_func(Functions::IS_NUMBER, 1)); |
|
87
|
|
|
$this->assertTrue(call_user_func(Functions::IS_NUMBER, 1.0)); |
|
88
|
|
|
$this->assertTrue(call_user_func(Functions::IS_NUMBER, 1.1)); |
|
89
|
|
|
$this->assertTrue(call_user_func(Functions::IS_NUMBER, 1.2)); |
|
90
|
|
|
$this->assertTrue(call_user_func(Functions::IS_NUMBER, 1.3)); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, '1')); |
|
93
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, '1.0')); |
|
94
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, '1.1')); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, array())); |
|
97
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, array( 1, 2, 3 ))); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertFalse(call_user_func(Functions::IS_NUMBER, null)); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** @testdox It should be possible to use a constant for Strings\isBlank() as a callable */ |
|
103
|
|
|
public function testIsBlank(): void |
|
104
|
|
|
{ |
|
105
|
|
|
// With string values |
|
106
|
|
|
$this->assertTrue(call_user_func(Functions::IS_BLANK, '')); |
|
107
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, 'a')); |
|
108
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, ' ')); |
|
109
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, ' ')); |
|
110
|
|
|
|
|
111
|
|
|
// With other types |
|
112
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, array())); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, null)); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, new \stdClass())); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, 1)); |
|
119
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, 1.0)); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, true)); |
|
122
|
|
|
$this->assertFalse(call_user_func(Functions::IS_BLANK, false)); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|