| @@ 7-26 (lines=20) @@ | ||
| 4 | ||
| 5 | use function Prelude\head; |
|
| 6 | ||
| 7 | class HeadTest extends \PHPUnit\Framework\TestCase |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @test |
|
| 11 | */ |
|
| 12 | public function shouldReturnTheFirstArgument() |
|
| 13 | { |
|
| 14 | $this->assertEquals(1, head([1, 2, 3])); |
|
| 15 | $this->assertEquals(1, head(['a' => 1, 'b' => 2, 'c' => 3])); |
|
| 16 | } |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @test |
|
| 20 | * @expectedException \InvalidArgumentException |
|
| 21 | */ |
|
| 22 | public function shouldThrowInvalidArgumentException() |
|
| 23 | { |
|
| 24 | head([]); |
|
| 25 | } |
|
| 26 | } |
|
| 27 | ||
| @@ 7-26 (lines=20) @@ | ||
| 4 | ||
| 5 | use function Prelude\last; |
|
| 6 | ||
| 7 | class LastTest extends \PHPUnit\Framework\TestCase |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @test |
|
| 11 | */ |
|
| 12 | public function test() |
|
| 13 | { |
|
| 14 | $this->assertEquals(3, last([1, 2, 3])); |
|
| 15 | $this->assertEquals(3, last(['a' => 1, 'b' => 2, 'c' => 3])); |
|
| 16 | } |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @test |
|
| 20 | * @expectedException \InvalidArgumentException |
|
| 21 | */ |
|
| 22 | public function shouldThrowInvalidArgumentException() |
|
| 23 | { |
|
| 24 | last([]); |
|
| 25 | } |
|
| 26 | } |
|
| 27 | ||
| @@ 7-24 (lines=18) @@ | ||
| 4 | ||
| 5 | use function Prelude\prop; |
|
| 6 | ||
| 7 | class PropTest extends \PHPUnit\Framework\TestCase |
|
| 8 | { |
|
| 9 | /** |
|
| 10 | * @test |
|
| 11 | */ |
|
| 12 | public function shouldReturnValue() |
|
| 13 | { |
|
| 14 | $this->assertEquals('a', prop('a')(['a' => 'a', 'b' => 'b'])); |
|
| 15 | } |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @test |
|
| 19 | */ |
|
| 20 | public function shouldReturnNull() |
|
| 21 | { |
|
| 22 | $this->assertEquals(null, prop('z')(['a' => 'a', 'b' => 'b'])); |
|
| 23 | } |
|
| 24 | } |
|
| 25 | ||