Last active
June 15, 2019 03:37
-
-
Save blackymetal/b8abda3eae17f10b7bc29d4a76aad260 to your computer and use it in GitHub Desktop.
Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Feature; | |
use Tests\TestCase; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
use App\User; | |
class ExampleTest extends TestCase | |
{ | |
/** | |
* A basic test example. | |
* | |
* @return void | |
*/ | |
public function testBasicTest() | |
{ | |
$response = $this->get('/'); | |
$response->assertStatus(200); | |
$sort = [ | |
4 => 1, | |
3 => 2, | |
2 => 3, | |
1 => 4 | |
]; | |
/* | |
factory('App\User')->create(['id' => 1, 'sort' => 4]); | |
factory('App\User')->create(['id' => 2, 'sort' => 3]); | |
factory('App\User')->create(['id' => 3, 'sort' => 2]); | |
factory('App\User')->create(['id' => 4, 'sort' => 1]); | |
*/ | |
$response->assertStatus(200); | |
$sort = User::all()->pluck('sort', 'id'); | |
$users = User::where('id', '>', 0)->orderBy('id')->get(['id', 'name', 'email']); | |
foreach ($users as $i => $user) { | |
$users[$i]->{'sort'} = $sort[$user->id]; | |
} | |
$sorted = $users->sortBy('sort'); | |
$this->assertEquals($sort, $sorted->pluck('sort', 'id')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment