@@ -64,17 +64,49 @@ public function testToIntReturnsDefaultWhenValueIsNotInt(): void
6464
6565 public function testToBoolReturnsBoolWhenValueIsBool (): void
6666 {
67- $ value = true ;
68- $ result = boolify ($ value );
69- $ this ->assertEquals ($ value , $ result );
67+ $ result = boolify (true );
68+ $ this ->assertTrue ($ result );
7069 }
7170
7271 public function testToBoolReturnsDefaultWhenValueIsNotBool (): void
7372 {
7473 $ value = 'not a bool ' ;
75- $ default = true ;
76- $ result = boolify ($ value , $ default );
77- $ this ->assertEquals (true , $ result );
74+ $ result = boolify ($ value , true );
75+ $ this ->assertTrue ($ result );
76+ }
77+
78+ public function testBoolifyParsesStringPositives (): void
79+ {
80+ $ this ->assertTrue (boolify ('1 ' ));
81+ $ this ->assertTrue (boolify ('true ' ));
82+ $ this ->assertTrue (boolify ('TRUE ' ));
83+ $ this ->assertTrue (boolify ('on ' ));
84+ $ this ->assertTrue (boolify ('ON ' ));
85+ $ this ->assertTrue (boolify ('yes ' ));
86+ $ this ->assertTrue (boolify ('Y ' ));
87+ $ this ->assertTrue (boolify ('yEs ' ));
88+ }
89+
90+ public function testBoolifyParsesStringNegatives (): void
91+ {
92+ $ this ->assertFalse (boolify ('0 ' ));
93+ $ this ->assertFalse (boolify ('false ' ));
94+ $ this ->assertFalse (boolify ('FALSE ' ));
95+ $ this ->assertFalse (boolify ('off ' ));
96+ $ this ->assertFalse (boolify ('OFF ' ));
97+ $ this ->assertFalse (boolify ('no ' ));
98+ $ this ->assertFalse (boolify ('n ' ));
99+ $ this ->assertFalse (boolify ('' ));
100+ }
101+
102+ public function testBoolifyHandlesNumericValues (): void
103+ {
104+ $ this ->assertTrue (boolify (1 ));
105+ $ this ->assertFalse (boolify (0 ));
106+ $ this ->assertTrue (boolify (10 ));
107+ $ this ->assertTrue (boolify (-3 ));
108+ $ this ->assertTrue (boolify ('2 ' ));
109+ $ this ->assertFalse (boolify ('0 ' ));
78110 }
79111
80112 public function testFloatifyReturnsFloatWhenValueIsFloat (): void
@@ -113,21 +145,38 @@ public function testMapifyConvertsObjectToArray(): void
113145 $ object ->name = 'John ' ;
114146 $ object ->age = 30 ;
115147 $ result = mapify ($ object );
116- $ this ->assertEquals (['name ' => 'John ' , 'age ' => 30 ], $ result );
148+ $ this ->assertEquals (
149+ [
150+ 'name ' => 'John ' ,
151+ 'age ' => 30 ,
152+ ],
153+ $ result
154+ );
117155 }
118156
119157 public function testMapifyReturnsArrayWhenValueIsArray (): void
120158 {
121- $ array = ['key ' => 'value ' , 'number ' => 42 ];
159+ $ array = [
160+ 'key ' => 'value ' ,
161+ 'number ' => 42 ,
162+ ];
122163 $ result = mapify ($ array );
123164 $ this ->assertEquals ($ array , $ result );
124165 }
125166
126167 public function testMapifyHandlesNumericKeys (): void
127168 {
128- $ array = [0 => 'first ' , 1 => 'second ' , 'name ' => 'test ' ];
169+ $ array = [
170+ 0 => 'first ' ,
171+ 1 => 'second ' ,
172+ 'name ' => 'test ' ,
173+ ];
129174 $ result = mapify ($ array );
130- $ expected = ['key_0 ' => 'first ' , 'key_1 ' => 'second ' , 'name ' => 'test ' ];
175+ $ expected = [
176+ 'key_0 ' => 'first ' ,
177+ 'key_1 ' => 'second ' ,
178+ 'name ' => 'test ' ,
179+ ];
131180 $ this ->assertEquals ($ expected , $ result );
132181 }
133182
0 commit comments