Skip to content

Instantly share code, notes, and snippets.

@phanlyhuynh
Created October 14, 2020 04:31
Show Gist options
  • Save phanlyhuynh/3fa829b2e37fd7af9855e66e6b8c3c7d to your computer and use it in GitHub Desktop.
Save phanlyhuynh/3fa829b2e37fd7af9855e66e6b8c3c7d to your computer and use it in GitHub Desktop.
Mocking connection DB
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