Skip to content

Commit a8b34b7

Browse files
committed
test(hom): add stub, test call/get
1 parent e455c99 commit a8b34b7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/UnderscoreBaseTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ public function jsonSerialize()
3030
}
3131
}
3232

33+
class Hom
34+
{
35+
public $n;
36+
public $square;
37+
38+
public function __construct($n)
39+
{
40+
$this->n = $n;
41+
$this->square = $n * $n;
42+
}
43+
44+
public function even()
45+
{
46+
return $this->n % 2 === 0;
47+
}
48+
}
49+
3350
class UnderscoreBaseTest extends TestCase
3451
{
3552
public function test_asArray()
@@ -135,4 +152,28 @@ public function test_valueOf()
135152
$this->assertSame('[1,2]', underscore([1, 2])->valueOf());
136153
$this->assertSame('["a","b"]', underscore(['a', 'b'])->valueOf());
137154
}
155+
156+
public function test_hom()
157+
{
158+
$i = 10;
159+
160+
while ($i--) {
161+
$u[] = new Hom($i);
162+
}
163+
164+
$u = underscore($u);
165+
$sq = $u->filter->even()->map->square->get();
166+
167+
// keys are kept intact :)
168+
$this->assertSame([1 => 64, 3 => 36, 5 => 16, 7 => 4, 9 => 0], $sq);
169+
}
170+
171+
/**
172+
* @expectedException \Ahc\Underscore\UnderscoreException
173+
* @expectedExceptionMessage The 'anon' is not defined
174+
*/
175+
public function test_hom_throws()
176+
{
177+
underscore()->anon->value();
178+
}
138179
}

0 commit comments

Comments
 (0)