-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinTest.php
50 lines (38 loc) · 1.06 KB
/
MinTest.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
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class MinTest extends TestCase
{
/** @test */
public function get_the_minimum_age()
{
$users = [
['id' => 200, 'name' => 'Glenn', 'age' => 32],
['id' => 300, 'name' => 'James', 'age' => 31],
['id' => 400, 'name' => 'John', 'age' => 40],
];
// $lowestAge = $this->useRegularPhp($users);
$lowestAge = $this->useCollections($users);
$this->assertEquals(31, $lowestAge);
}
private function useRegularPhp($users)
{
$lowestAge = null;
if (count($users)) {
$lowestAge = $users[0]['age'];
}
foreach ($users as $user) {
if ($lowestAge < $user['age']) {
continue;
}
$lowestAge = $user['age'];
}
return $lowestAge;
}
private function useCollections($users)
{
return collect($users)->min->age;
}
}