PHP code example of homedistil / eloquent-mockery
1. Go to this page and download the library: Download homedistil/eloquent-mockery library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
homedistil / eloquent-mockery example snippets
return [
...
'connections' => [
'fake' => [
'driver' => 'arrayDB',
'database' => '',
],
...
],
...
]
public function test_basic()
{
config()->set('database.default', 'my_test_connection');
# ::Arrange:: (Setup Sample Data)
FakeDB::addRow('users', ['id' => 1, 'username' => 'faky', 'password' => '...']);
FakeDB::addRow('users', ['id' => 1, 'username' => 'maky', 'password' => '...']);
# ::Act:: (This query resides in your controller)
$user = User::where('username', 'faky')->first(); # <=== This does NOT connect to a real DB.
# ::Assert::
$this->assert($user->id === 1);
$this->assert($user->username === 'faky');
}
public function test_basic()
{
# In setUp:
FakeDB::mockEloquentBuilder();
# ::Act::
$this->post('/create-url', ['some' => 'data' ])
# ::Assert::
$user = User::first();
$this->assertEquals('iman', $user->username);
# In tearDown
FakeDB::dontMockEloquentBuilder();
}