diff --git a/src/FakeQueryBuilder.php b/src/FakeQueryBuilder.php index 3cf847b..2133121 100644 --- a/src/FakeQueryBuilder.php +++ b/src/FakeQueryBuilder.php @@ -10,9 +10,4 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul { return $this; } - - public function addFakeRow(string $table, $val, $key) - { - FakeDB::changeFakeRow($table, $val, $key); - } } diff --git a/tests/AggregateTest.php b/tests/AggregateTest.php index 149e54d..5420cd5 100644 --- a/tests/AggregateTest.php +++ b/tests/AggregateTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class AggregateUser extends Model { - use MockableModel; + protected $table = 'users'; } class AggregateTest extends TestCase @@ -18,10 +17,10 @@ public function setUp(): void { FakeDB::mockQueryBuilder(); - AggregateUser::addFakeRow(['id' => 1, 'name' => null, 'age' => 20,]); - AggregateUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - AggregateUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => null,]); - AggregateUser::addFakeRow(['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); + FakeDB::addRow('users', ['id' => 1, 'name' => null, 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => null,]); + FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); } public function tearDown(): void diff --git a/tests/DeleteTest.php b/tests/DeleteTest.php index a011373..2921a6c 100644 --- a/tests/DeleteTest.php +++ b/tests/DeleteTest.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Events\Dispatcher; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class DeleteUser extends Model { - use MockableModel; + protected $table = 'users'; } class DeleteTest extends TestCase @@ -30,11 +29,11 @@ public function setUp(): void */ public function destroy() { - DeleteUser::addFakeRow(['id' => 1]); - DeleteUser::addFakeRow(['id' => 2]); - DeleteUser::addFakeRow(['id' => 3]); - DeleteUser::addFakeRow(['id' => 4]); - DeleteUser::fakeSoftDelete(); + FakeDB::addRow('users', ['id' => 1]); + FakeDB::addRow('users', ['id' => 2]); + FakeDB::addRow('users', ['id' => 3]); + FakeDB::addRow('users', ['id' => 4]); + //DeleteUser::fakeSoftDelete(); $count = DeleteUser::destroy(1, 2); $this->assertEquals(2, $count); //$this->assertNotNull(DeleteUser::getDeletedModel(1)); @@ -58,11 +57,11 @@ public function destroy() */ public function delete() { - DeleteUser::addFakeRow(['id' => 1]); + FakeDB::addRow('users', ['id' => 1]); $user = DeleteUser::find(1); $result = $user->delete(); - $user2 = DeleteUser::getDeletedModel(); + //$user2 = DeleteUser::getDeletedModel(); //$this->assertEquals(spl_object_hash($user), spl_object_hash($user2)); $this->assertTrue($result); @@ -77,7 +76,7 @@ public function delete() */ public function delete_non_existent() { - DeleteUser::addFakeRow(['id' => 1]); + FakeDB::addRow('users', ['id' => 1]); DeleteUser::setEventDispatcher(new Dispatcher); $std = new \stdClass(); @@ -93,9 +92,9 @@ public function delete_non_existent() $user->exists = false; $result = $user->delete(); - $model = DeleteUser::getDeletedModel(); + //$model = DeleteUser::getDeletedModel(); - $this->assertNull($model); + //$this->assertNull($model); $this->assertNull($result); $this->assertFalse($user->exists); $this->assertFalse($std->deleting); @@ -107,7 +106,7 @@ public function delete_non_existent() public function delete_on_deleting() { DeleteUser::setEventDispatcher(new Dispatcher); - DeleteUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 1, 'name' => 'mocky', ]); @@ -128,9 +127,9 @@ public function delete_on_deleting() $user = DeleteUser::first(); $result = $user->delete(); - $model = DeleteUser::getDeletedModel(); + //$model = DeleteUser::getDeletedModel(); - $this->assertNull($model); + //$this->assertNull($model); $this->assertFalse($result); $this->assertTrue($user->exists); $this->assertTrue($std->deleting); @@ -144,7 +143,7 @@ public function delete_on_deleting() public function delete_events() { DeleteUser::setEventDispatcher(new Dispatcher); - DeleteUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 1, 'name' => 'mocky', ]); @@ -161,7 +160,7 @@ public function delete_events() $user = DeleteUser::find(1); $result = $user->delete(); - $model = DeleteUser::getDeletedModel(); + //$model = DeleteUser::getDeletedModel(); //$this->assertSame($user, $model); $this->assertTrue($result); @@ -177,11 +176,11 @@ public function force_delete() { DeleteUser::setEventDispatcher(new Dispatcher); - DeleteUser::addFakeRow(['id' => 1]); + FakeDB::addRow('users', ['id' => 1]); $user = DeleteUser::query()->find(1); $result = $user->forceDelete(); - $deletedModel = DeleteUser::getDeletedModel(); + //$deletedModel = DeleteUser::getDeletedModel(); //$this->assertEquals(1, $deletedModel->id); $this->assertTrue($result); @@ -194,14 +193,14 @@ public function force_delete() public function delete_or_fail() { DeleteUser::setEventDispatcher(new Dispatcher); - DeleteUser::addFakeRow(['id' => 1]); + FakeDB::addRow('users', ['id' => 1]); $user = DeleteUser::find(1); if (! method_exists($user, 'deleteOrFail')) { $this->markTestSkipped(); } $result = $user->deleteOrFail(); - $deletedModel = DeleteUser::getDeletedModel(); + //$deletedModel = DeleteUser::getDeletedModel(); //$this->assertEquals(1, $deletedModel->id); //$this->assertSame($deletedModel, $user); @@ -217,10 +216,10 @@ public function raw_delete_empty_table() DeleteUser::setEventDispatcher(new Dispatcher); $count = DeleteUser::where('id', 1)->delete(); - $model = DeleteUser::getDeletedModel(); + //$model = DeleteUser::getDeletedModel(); $this->assertEquals(0, $count); - $this->assertNull($model); + //$this->assertNull($model); } /** @@ -229,14 +228,14 @@ public function raw_delete_empty_table() public function raw_delete2() { DeleteUser::setEventDispatcher(new Dispatcher); - DeleteUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 1, 'name' => 'mocky', ]); $count = DeleteUser::where('id', 2)->delete(); - $model = DeleteUser::getDeletedModel(); + //$model = DeleteUser::getDeletedModel(); $this->assertEquals(0, $count); - $this->assertNull($model); + //$this->assertNull($model); } } diff --git a/tests/ExistsTest.php b/tests/ExistsTest.php index b891174..5cb3773 100644 --- a/tests/ExistsTest.php +++ b/tests/ExistsTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class ExistsUser extends Model { - use MockableModel; + protected $table = 'users'; } class ExistsTest extends TestCase @@ -29,10 +28,10 @@ public function setUp(): void */ public function basic_exists() { - ExistsUser::addFakeRow(['id' => 1, 'name' => null, 'age' => 20,]); - ExistsUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - ExistsUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => null,]); - ExistsUser::addFakeRow(['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); + FakeDB::addRow('users',['id' => 1, 'name' => null, 'age' => 20,]); + FakeDB::addRow('users',['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users',['id' => 3, 'name' => 'Iman 3', 'age' => null,]); + FakeDB::addRow('users',['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); $this->assertTrue(ExistsUser::query()->exists()); $this->assertTrue(ExistsUser::query()->exists()); diff --git a/tests/FakeDB/FakeDbTest.php b/tests/FakeDB/FakeDbTest.php index d985f49..393b128 100644 --- a/tests/FakeDB/FakeDbTest.php +++ b/tests/FakeDB/FakeDbTest.php @@ -3,22 +3,24 @@ namespace Imanghafoori\EloquentMockery\Tests\FakeDB; use Illuminate\Database\Eloquent\Model; -use Imanghafoori\EloquentMockery\FakeConnection; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class FakeDbUser extends Model { - use MockableModel; - - public $table = 'users'; + protected $table = 'users'; } class FakeDbTest extends TestCase { + public function setUp(): void + { + FakeDB::mockQueryBuilder(); + } + public function tearDown(): void { + FakeDB::dontMockQueryBuilder(); FakeDB::truncate(); } diff --git a/tests/IgnoreWheresTest_.php b/tests/IgnoreWheresTest_.php index 936e50f..443023d 100644 --- a/tests/IgnoreWheresTest_.php +++ b/tests/IgnoreWheresTest_.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class IgnoreWheresUser extends Model { - use MockableModel; + protected $table = 'users'; } class IgnoreWheresTest_ extends TestCase @@ -30,9 +29,9 @@ public function setUp(): void */ public function where__whereIn() { - IgnoreWheresUser::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - IgnoreWheresUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - IgnoreWheresUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); +FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); +FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); +FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); IgnoreWheresUser::ignoreWheres(); @@ -87,10 +86,10 @@ public function where__whereIn() */ public function test_get() { - IgnoreWheresUser::addFakeRow(['id' => 1, 'name' => null, 'age' => 20,]); - IgnoreWheresUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - IgnoreWheresUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => null,]); - IgnoreWheresUser::addFakeRow(['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); +FakeDB::addRow('users', ['id' => 1, 'name' => null, 'age' => 20,]); +FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); +FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => null,]); +FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); IgnoreWheresUser::ignoreWheres(); diff --git a/tests/Relations/HasManyTest.php b/tests/Relations/HasManyTest.php index 088ba32..beccb6e 100644 --- a/tests/Relations/HasManyTest.php +++ b/tests/Relations/HasManyTest.php @@ -4,14 +4,13 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class HasManyUser extends Model { public $fillable = ['name']; - use MockableModel; + protected $table = 'users'; public function comments() { @@ -21,7 +20,7 @@ public function comments() class HasManyComment extends Model { - use MockableModel; + protected $table = 'users'; public $fillable = ['comment']; @@ -38,16 +37,16 @@ class HasManyTest extends TestCase */ public function has_many() { - HasManyUser::addFakeRow(['id' => 1, 'name' => 'Iman 1']); - HasManyUser::addFakeRow(['id' => 2, 'name' => 'Iman 2']); - HasManyUser::addFakeRow(['id' => 3, 'name' => 'Iman 3']); - HasManyUser::addFakeRow(['id' => 4, 'name' => 'Iman 4']); - - HasManyComment::addFakeRow(['id' => 1, 'user_id' => 1, 'comment' => 'sss']); - HasManyComment::addFakeRow(['id' => 2, 'user_id' => 1, 'comment' => 'aaa']); - HasManyComment::addFakeRow(['id' => 3, 'user_id' => 2, 'comment' => 'bbb']); - HasManyComment::addFakeRow(['id' => 4, 'user_id' => 2, 'comment' => 'ccc']); - HasManyComment::addFakeRow(['id' => 5, 'user_id' => 3, 'comment' => 'ddd']); +FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1']); +FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2']); +FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3']); +FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4']); + +FakeDB::addRow('users', ['id' => 1, 'user_id' => 1, 'comment' => 'sss']); +FakeDB::addRow('users', ['id' => 2, 'user_id' => 1, 'comment' => 'aaa']); +FakeDB::addRow('users', ['id' => 3, 'user_id' => 2, 'comment' => 'bbb']); +FakeDB::addRow('users', ['id' => 4, 'user_id' => 2, 'comment' => 'ccc']); +FakeDB::addRow('users', ['id' => 5, 'user_id' => 3, 'comment' => 'ddd']); $user = HasManyUser::with('comments')->where('id', 1)->first(); diff --git a/tests/Relations/HasOneTest.php b/tests/Relations/HasOneTest.php index 2273fbd..00f8522 100644 --- a/tests/Relations/HasOneTest.php +++ b/tests/Relations/HasOneTest.php @@ -4,14 +4,13 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Carbon; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class HasOneUser extends Model { public $fillable = ['name']; - use MockableModel; + protected $table = 'users'; public function comments() { @@ -21,7 +20,7 @@ public function comments() class HasOneComment extends Model { - use MockableModel; + protected $table = 'users'; public $fillable = ['comment']; @@ -38,14 +37,14 @@ class HasOneTest extends TestCase */ public function has_one() { - HasOneUser::addFakeRow(['id' => 1, 'name' => 'Iman 1']); - HasOneUser::addFakeRow(['id' => 2, 'name' => 'Iman 2']); - HasOneUser::addFakeRow(['id' => 3, 'name' => 'Iman 3']); - HasOneUser::addFakeRow(['id' => 4, 'name' => 'Iman 4']); - - HasOneComment::addFakeRow(['id' => 1, 'user_id' => 1, 'comment' => 'sss']); - HasOneComment::addFakeRow(['id' => 2, 'user_id' => 1, 'comment' => 'aaa']); - HasOneComment::addFakeRow(['id' => 3, 'user_id' => 3, 'comment' => 'bbb']); +FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1']); +FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2']); +FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3']); +FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4']); + +FakeDB::addRow('users', ['id' => 1, 'user_id' => 1, 'comment' => 'sss']); +FakeDB::addRow('users', ['id' => 2, 'user_id' => 1, 'comment' => 'aaa']); +FakeDB::addRow('users', ['id' => 3, 'user_id' => 3, 'comment' => 'bbb']); $user = HasOneUser::with('comments')->where('id', 1)->first(); diff --git a/tests/Relations/ManyToManyTest.php b/tests/Relations/ManyToManyTest.php index fe29269..92bf9c8 100644 --- a/tests/Relations/ManyToManyTest.php +++ b/tests/Relations/ManyToManyTest.php @@ -5,14 +5,13 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class Mser extends Model { public $fillable = ['username']; - use MockableModel; + protected $table = 'users'; public function city() { @@ -22,7 +21,7 @@ public function city() class Mity extends Model { - use MockableModel; + protected $table = 'users'; public $fillable = ['name']; @@ -39,21 +38,21 @@ class ManyToManyTest extends TestCase */ public function belongs_to_many() { - Mser::addFakeRow(['id' => 1, 'name' => 'Iman 1']); - Mser::addFakeRow(['id' => 2, 'name' => 'Iman 2']); - Mser::addFakeRow(['id' => 3, 'name' => 'Iman 3']); - Mser::addFakeRow(['id' => 4, 'name' => 'Iman 4']); +FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1']); +FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2']); +FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3']); +FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4']); FakeDB::table('pivot')->addRow(['mity_id' => 1, 'mser_id' => 1]); FakeDB::table('pivot')->addRow(['mity_id' => 1, 'mser_id' => 2]); FakeDB::table('pivot')->addRow(['mity_id' => 2, 'mser_id' => 2]); FakeDB::table('pivot')->addRow(['mity_id' => 2, 'mser_id' => 3]); - Mity::addFakeRow(['id' => 1, 'name' => 'sss']); - Mity::addFakeRow(['id' => 2, 'name' => 'aaa']); - Mity::addFakeRow(['id' => 3, 'name' => 'bbb']); - Mity::addFakeRow(['id' => 4, 'name' => 'ccc']); - Mity::addFakeRow(['id' => 5, 'name' => 'ddd']); +FakeDB::addRow('users', ['id' => 1, 'name' => 'sss']); +FakeDB::addRow('users', ['id' => 2, 'name' => 'aaa']); +FakeDB::addRow('users', ['id' => 3, 'name' => 'bbb']); +FakeDB::addRow('users', ['id' => 4, 'name' => 'ccc']); +FakeDB::addRow('users', ['id' => 5, 'name' => 'ddd']); $user = Mser::where('id', 1)->first(); diff --git a/tests/SelectTest.php b/tests/SelectTest.php index 884c64e..0503927 100644 --- a/tests/SelectTest.php +++ b/tests/SelectTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class SelectyUser extends Model { - use MockableModel; + protected $table = 'users'; } class SelectTest extends TestCase @@ -29,10 +28,10 @@ public function setUp(): void */ public function test_get() { - SelectyUser::addFakeRow(['id' => 1, 'name' => null, 'age' => 20,]); - SelectyUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - SelectyUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => null,]); - SelectyUser::addFakeRow(['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); + FakeDB::addRow('users',['id' => 1, 'name' => null, 'age' => 20,]); + FakeDB::addRow('users',['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users',['id' => 3, 'name' => 'Iman 3', 'age' => null,]); + FakeDB::addRow('users',['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); $users = SelectyUser::whereNull('name')->get(['age']); $this->assertEquals(null, ($users[0])->id); diff --git a/tests/UpdateTest.php b/tests/UpdateTest.php index b5f1741..a45ac63 100644 --- a/tests/UpdateTest.php +++ b/tests/UpdateTest.php @@ -6,14 +6,13 @@ use Illuminate\Events\Dispatcher; use Illuminate\Support\Carbon; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class UpdateyModel extends Model { protected $fillable = ['name']; - use MockableModel; + protected $table = 'users'; } class UpdateTest extends TestCase @@ -34,8 +33,8 @@ public function setUp(): void public function calling_update_method_on_model_object() { UpdateyModel::setEventDispatcher(new Dispatcher()); - UpdateyModel::addFakeRow(['id' => 1, 'name' => 'hi 1']); - UpdateyModel::addFakeRow(['id' => 2, 'name' => 'hi 2']); + FakeDB::addRow('users', ['id' => 1, 'name' => 'hi 1']); + FakeDB::addRow('users', ['id' => 2, 'name' => 'hi 2']); UpdateyModel::saved(function () { $_SERVER['saved'] = true; @@ -59,14 +58,14 @@ public function calling_update_method_on_model_object() $this->assertTrue($_SERVER['updated']); $this->assertTrue($_SERVER['updating']); - $foo = UpdateyModel::getUpdatedModel(); + //$foo = UpdateyModel::getUpdatedModel(); //$this->assertEquals(1, $foo->id); //$this->assertEquals('hello', $foo->name); //$this->assertEquals($foo->updated_at->timestamp, $time); //$this->assertTrue($foo->exists); - $this->assertNull(UpdateyModel::getUpdatedModel(1)); + //$this->assertNull(UpdateyModel::getUpdatedModel(1)); //$this->assertSame(UpdateyModel::getUpdatedModel(), UpdateyModel::getSavedModel()); unset($_SERVER['saved']); @@ -81,8 +80,8 @@ public function calling_update_method_on_model_object() public function update_with_no_dispatcher() { UpdateyModel::unsetEventDispatcher(); - UpdateyModel::addFakeRow(['id' => 1, 'name' => 'hi 1']); - UpdateyModel::addFakeRow(['id' => 2, 'name' => 'hi 2']); + FakeDB::addRow('users', ['id' => 1, 'name' => 'hi 1']); + FakeDB::addRow('users', ['id' => 2, 'name' => 'hi 2']); $_SERVER['saved'] = false; $_SERVER['updating'] = false; @@ -111,7 +110,7 @@ public function update_with_no_dispatcher() $this->assertFalse($_SERVER['updated']); $this->assertFalse($_SERVER['updating']); - $foo = UpdateyModel::getUpdatedModel(0); + //$foo = UpdateyModel::getUpdatedModel(0); //$this->assertEquals(1, $foo->id); //$this->assertEquals('hello', $foo->name); @@ -132,8 +131,8 @@ public function update_with_no_dispatcher() public function updating_event() { UpdateyModel::setEventDispatcher(new Dispatcher()); - UpdateyModel::addFakeRow(['id' => 1, 'name' => 'hi 1']); - UpdateyModel::addFakeRow(['id' => 2, 'name' => 'hi 2']); + FakeDB::addRow('users', ['id' => 1, 'name' => 'hi 1']); + FakeDB::addRow('users', ['id' => 2, 'name' => 'hi 2']); UpdateyModel::updating(function () { return false; @@ -158,8 +157,8 @@ public function updating_event() public function update_raw() { UpdateyModel::setEventDispatcher(new Dispatcher()); - UpdateyModel::addFakeRow(['id' => 1, 'name' => 'hi 1']); - UpdateyModel::addFakeRow(['id' => 2, 'name' => 'hi 2']); + FakeDB::addRow('users', ['id' => 1, 'name' => 'hi 1']); + FakeDB::addRow('users', ['id' => 2, 'name' => 'hi 2']); $_SERVER['saved'] = false; $_SERVER['updating'] = false; @@ -188,8 +187,8 @@ public function update_raw() $this->assertFalse($_SERVER['updated']); $this->assertFalse($_SERVER['updating']); - $foo = UpdateyModel::getUpdatedModel(); - $this->assertNull($foo); + //$foo = UpdateyModel::getUpdatedModel(); + //$this->assertNull($foo); // No event has been fired. unset($_SERVER['saved']); diff --git a/tests/WhenTest.php b/tests/WhenTest.php index 7507635..583b1d1 100644 --- a/tests/WhenTest.php +++ b/tests/WhenTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class WhenUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhenTest extends TestCase @@ -29,9 +28,9 @@ public function setUp(): void */ public function when_test() { - WhenUser::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - WhenUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - WhenUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = WhenUser::query()->when(true, function ($q) { $q->where('id', '<', 2); diff --git a/tests/Wheres/ArrayAsConditionsTest.php b/tests/Wheres/ArrayAsConditionsTest.php index a1ac26a..0984f27 100644 --- a/tests/Wheres/ArrayAsConditionsTest.php +++ b/tests/Wheres/ArrayAsConditionsTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class WhereArrayUser extends Model { - use MockableModel; + protected $table = 'users'; } class ArrayAsConditionsTest extends TestCase @@ -29,21 +28,21 @@ public function setUp(): void */ public function whereArray() { - WhereArrayUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 1, 'name' => 'test-name', 'email' => 'test-email1', 'address' => 'test-address0', ]); - WhereArrayUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 2, 'name' => 'test-name1', 'email' => 'test-email1', 'address' => 'test-address1', ]); - WhereArrayUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 3, 'name' => 'test-name1', 'email' => 'test-email', diff --git a/tests/Wheres/OrWhereTest.php b/tests/Wheres/OrWhereTest.php index 165f7d2..26d71d7 100644 --- a/tests/Wheres/OrWhereTest.php +++ b/tests/Wheres/OrWhereTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class OrWhereUser extends Model { - use MockableModel; + protected $table = 'users'; } class OrWhereTest extends TestCase @@ -31,28 +30,28 @@ public function orWhere() { FakeDB::mockQueryBuilder(); - OrWhereUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 1, 'name' => 'name0', 'email' => 'email0', 'address' => 'address-0', ]); - OrWhereUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 2, 'name' => 'name1', 'email' => 'email1', 'address' => 'address-1', ]); - OrWhereUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 3, 'name' => 'name2', 'email' => 'email2', 'address' => 'address-2', ]); - OrWhereUser::addFakeRow([ + FakeDB::addRow('users', [ 'id' => 4, 'name' => 'name4', 'email' => 'email4', diff --git a/tests/Wheres/WhereBetweenTest.php b/tests/Wheres/WhereBetweenTest.php index 93e154d..6fad6c2 100644 --- a/tests/Wheres/WhereBetweenTest.php +++ b/tests/Wheres/WhereBetweenTest.php @@ -4,24 +4,23 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class BetweenUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhereBetweenTest extends TestCase { - public function tearDown(): void + public function setUp(): void { - FakeDB::dontMockQueryBuilder(); + FakeDB::mockQueryBuilder(); } - public function setUp(): void + public function tearDown(): void { - FakeDB::mockQueryBuilder(); + FakeDB::dontMockQueryBuilder(); } /** @@ -29,9 +28,9 @@ public function setUp(): void */ public function whereBetween() { - BetweenUser::addFakeRow(['id' => 1, 'name' => 'Hello', 'age' => 20,]); - BetweenUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - BetweenUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Hello', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = BetweenUser::query()->whereBetween('age', [25, 31])->get(); $this->assertEquals('Iman 2', ($users[0])->name); @@ -43,9 +42,9 @@ public function whereBetween() */ public function whereNotBetween() { - BetweenUser::addFakeRow(['id' => 1, 'name' => 'Hello', 'age' => 20,]); - BetweenUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - BetweenUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Hello', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = BetweenUser::query()->whereNotBetween('age', [25, 31])->get(); $this->assertEquals('Hello', ($users[0])->name); diff --git a/tests/Wheres/WhereClosureTest.php b/tests/Wheres/WhereClosureTest.php index e56c11e..3aa6f23 100644 --- a/tests/Wheres/WhereClosureTest.php +++ b/tests/Wheres/WhereClosureTest.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class UserClosure extends Model { - use MockableModel; + protected $table = 'users'; } class WhereClosureTest extends TestCase @@ -30,11 +29,11 @@ public function setUp(): void */ public function where_closure() { - UserClosure::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - UserClosure::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - UserClosure::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); - UserClosure::addFakeRow(['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); - UserClosure::addFakeRow(['id' => 5, 'name' => 'Iman 4', 'age' => 10,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 4, 'name' => 'Iman 4', 'age' => 40,]); + FakeDB::addRow('users', ['id' => 5, 'name' => 'Iman 4', 'age' => 10,]); $users = UserClosure::query() ->where('age', '<', 31) diff --git a/tests/Wheres/WhereColumnTest.php b/tests/Wheres/WhereColumnTest.php index 6d14c23..5c2c774 100644 --- a/tests/Wheres/WhereColumnTest.php +++ b/tests/Wheres/WhereColumnTest.php @@ -9,7 +9,7 @@ class WhereColumnUser extends Model { - // + protected $table = 'users'; } class WhereColumnTest extends TestCase diff --git a/tests/Wheres/WhereInTest12.php b/tests/Wheres/WhereInTest12.php index 46f0220..8145940 100644 --- a/tests/Wheres/WhereInTest12.php +++ b/tests/Wheres/WhereInTest12.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class WhereInUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhereInTest extends TestCase @@ -30,9 +29,9 @@ public function setUp(): void */ public function where_in() { - WhereInUser::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - WhereInUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - WhereInUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); // ################ where In / first ################ $user = WhereInUser::whereIn('id', [2])->first(); @@ -65,9 +64,9 @@ public function where_in() */ public function where_not_in() { - WhereInUser::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - WhereInUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - WhereInUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); // ################ where not In / first ################ $user = WhereInUser::whereNotIn('id', [1, 3])->first(); @@ -100,9 +99,9 @@ public function where_not_in() */ public function where_in_can_accept_arrayable() { - WhereInUser::addFakeRow(['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); - WhereInUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - WhereInUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Iman 1', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); // ################ where In / first ################ $count = WhereInUser::whereIn('id', collect([1, 2]))->count(); diff --git a/tests/Wheres/WhereKeyTest.php b/tests/Wheres/WhereKeyTest.php index c9ddfd6..7440310 100644 --- a/tests/Wheres/WhereKeyTest.php +++ b/tests/Wheres/WhereKeyTest.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class KeyUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhereKeyTest extends TestCase @@ -30,9 +29,9 @@ public function setUp(): void */ public function whereKey() { - KeyUser::addFakeRow(['id' => 1, 'name' => 'Hello', 'age' => 20,]); - KeyUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - KeyUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Hello', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = KeyUser::query()->whereKey(1)->get(); $this->assertEquals('Hello', ($users[0])->name); @@ -51,9 +50,9 @@ public function whereKey() */ public function whereKeyNot() { - KeyUser::addFakeRow(['id' => 1, 'name' => 'Hello', 'age' => 20,]); - KeyUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - KeyUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Hello', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = KeyUser::query()->whereKeyNot(1)->get(); $this->assertEquals('Iman 2', ($users[0])->name); diff --git a/tests/Wheres/WhereLikeTest.php b/tests/Wheres/WhereLikeTest.php index eafe81e..0acaaee 100644 --- a/tests/Wheres/WhereLikeTest.php +++ b/tests/Wheres/WhereLikeTest.php @@ -4,12 +4,11 @@ use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class LikeUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhereLikeTest extends TestCase @@ -29,9 +28,9 @@ public function setUp(): void */ public function whereLike() { - LikeUser::addFakeRow(['id' => 1, 'name' => 'Hello', 'age' => 20,]); - LikeUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - LikeUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); + FakeDB::addRow('users', ['id' => 1, 'name' => 'Hello', 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => 34,]); $users = LikeUser::where('name', 'like', '%man 3')->get(); $this->assertEquals('Iman 3', ($users[0])->name); diff --git a/tests/Wheres/WhereNullTest.php b/tests/Wheres/WhereNullTest.php index c73b3df..8004de6 100644 --- a/tests/Wheres/WhereNullTest.php +++ b/tests/Wheres/WhereNullTest.php @@ -5,12 +5,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Imanghafoori\EloquentMockery\FakeDB; -use Imanghafoori\EloquentMockery\MockableModel; use PHPUnit\Framework\TestCase; class WhereNullUser extends Model { - use MockableModel; + protected $table = 'users'; } class WhereNullTest extends TestCase @@ -18,9 +17,9 @@ class WhereNullTest extends TestCase public function setUp(): void { FakeDB::mockQueryBuilder(); - WhereNullUser::addFakeRow(['id' => 1, 'name' => null, 'age' => 20,]); - WhereNullUser::addFakeRow(['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); - WhereNullUser::addFakeRow(['id' => 3, 'name' => 'Iman 3', 'age' => null,]); + FakeDB::addRow('users', ['id' => 1, 'name' => null, 'age' => 20,]); + FakeDB::addRow('users', ['id' => 2, 'name' => 'Iman 2', 'age' => 30,]); + FakeDB::addRow('users', ['id' => 3, 'name' => 'Iman 3', 'age' => null,]); } public function tearDown(): void