-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e44327
commit 3cee9c1
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Imanghafoori\EloquentMockery\Tests; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Imanghafoori\EloquentMockery\FakeDB; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GroupByModel extends Model | ||
{ | ||
protected $table = 'my_tbl'; | ||
} | ||
|
||
class GroupByTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
FakeDB::mockQueryBuilder(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
FakeDB::dontMockQueryBuilder(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function groupByBasicTest() | ||
{ | ||
FakeDB::addRow('my_tbl', ['id' => 1,'col1' => 'v1']); | ||
FakeDB::addRow('my_tbl', ['id' => 2,'col1' => 'v2']); | ||
FakeDB::addRow('my_tbl', ['id' => 3,'col1' => 'v1']); | ||
FakeDB::addRow('my_tbl', ['id' => 4,'col1' => 'v3']); | ||
FakeDB::addRow('my_tbl', ['id' => 5,'col1' => 'v2']); | ||
|
||
$rows = GroupByModel::query()->groupBy('col1')->get(); | ||
|
||
$this->assertCount(3, $rows); | ||
|
||
$this->assertEquals(3, $rows[0]->id); | ||
$this->assertEquals(5, $rows[1]->id); | ||
$this->assertEquals(4, $rows[2]->id); | ||
} | ||
} |