Created
October 14, 2020 04:31
-
-
Save phanlyhuynh/3fa829b2e37fd7af9855e66e6b8c3c7d to your computer and use it in GitHub Desktop.
Mocking connection DB
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
public function setUp() : void | |
{ | |
$this->afterApplicationCreated(function () { | |
$this->db = m::mock( | |
Connection::class . '[select,update,insert,delete]', | |
[m::mock(PDO::class)] | |
); | |
$manager = $this->app['db']; | |
$manager->setDefaultConnection('mock'); | |
$r = new \ReflectionClass($manager); | |
$p = $r->getProperty('connections'); | |
$p->setAccessible(true); | |
$list = $p->getValue($manager); | |
$list['mock'] = $this->db; | |
$p->setValue($manager, $list); | |
}); | |
parent::setUp(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment