Skip to content

Commit 8b33a8c

Browse files
committed
IHF: db_mysql_variable helper fully covered by tests.
1 parent a1db161 commit 8b33a8c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/db/DbMysqlVariableTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Mockery as m;
4+
5+
class DbMysqlVariableTest extends TestCase
6+
{
7+
/** @test */
8+
public function it_returns_false_for_unexisting_mysql_variable()
9+
{
10+
$mock = m::mock('alias:Illuminate\Support\Facades\DB');
11+
$mock->shouldReceive('selectOne')
12+
->withArgs(['show variables where variable_name = ?', ['fake']])
13+
->once()
14+
->andReturnNull()
15+
;
16+
$this->assertFalse(db_mysql_variable('fake'));
17+
}
18+
19+
/** @test */
20+
public function it_returns_value_for_known_mysql_variable()
21+
{
22+
$mock = m::mock('alias:Illuminate\Support\Facades\DB');
23+
$mock->shouldReceive('selectOne')
24+
->withArgs(['show variables where variable_name = ?', ['hostname']])
25+
->once()
26+
->andReturnUsing(function () {
27+
$object = new StdClass();
28+
$object->Variable_name = 'hostname';
29+
$object->Value = 'localhost';
30+
return $object;
31+
})
32+
;
33+
$this->assertEquals('localhost', db_mysql_variable('hostname'));
34+
}
35+
}

0 commit comments

Comments
 (0)