Skip to content

Commit fbf97ab

Browse files
committed
IHF: Fixed to check driver instead of connection name.
1 parent 5d09a4a commit fbf97ab

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/db.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<?php
22

3+
use Illuminate\Support\Facades\Config;
34
use Illuminate\Support\Facades\DB;
45

56
if (!function_exists('db_is_mysql')) {
67
function db_is_mysql()
78
{
8-
return (DB::getDefaultConnection() == 'mysql');
9+
$connection = DB::getDefaultConnection();
10+
$driver = Config::get("database.connections.{$connection}.driver");
11+
12+
return ($driver == 'mysql');
913
}
1014
}
1115

tests/HelperFunctions/db/DbIsMysqlTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
namespace Illuminated\Helpers\HelperFunctions\Tests\Db;
44

5+
use Illuminate\Support\Facades\Config;
6+
use Illuminate\Support\Facades\DB;
57
use Illuminated\Helpers\HelperFunctions\Tests\TestCase;
6-
use Mockery;
78

9+
/**
10+
* @runTestsInSeparateProcesses
11+
* @preserveGlobalState disabled
12+
*/
813
class DbIsMysqlTest extends TestCase
914
{
1015
/** @test */
1116
public function it_returns_true_if_laravel_database_default_connection_is_mysql()
1217
{
13-
$mock = Mockery::mock('alias:Illuminate\Support\Facades\DB');
14-
$mock->shouldReceive('getDefaultConnection')->withNoArgs()->once()->andReturn('mysql');
18+
DB::shouldReceive('getDefaultConnection')->withNoArgs()->once()->andReturn('mysql');
19+
Config::shouldReceive('get')->with("database.connections.mysql.driver")->once()->andReturn('mysql');
1520

1621
$this->assertTrue(db_is_mysql());
1722
}
1823

1924
/** @test */
2025
public function it_returns_false_if_laravel_database_default_connection_is_not_mysql()
2126
{
22-
$mock = Mockery::mock('alias:Illuminate\Support\Facades\DB');
23-
$mock->shouldReceive('getDefaultConnection')->withNoArgs()->once()->andReturn('sqlite');
27+
DB::shouldReceive('getDefaultConnection')->withNoArgs()->once()->andReturn('sqlite');
28+
Config::shouldReceive('get')->with("database.connections.sqlite.driver")->once()->andReturn('sqlite');
2429

2530
$this->assertFalse(db_is_mysql());
2631
}

0 commit comments

Comments
 (0)