File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -641,6 +641,16 @@ public function setDatabaseName($database)
641641 $ this ->database = $ database ;
642642 }
643643
644+ /**
645+ * Get the table prefix for the connection.
646+ *
647+ * @return string
648+ */
649+ public function getTablePrefix ()
650+ {
651+ return $ this ->tablePrefix ;
652+ }
653+
644654 /**
645655 * Set the table prefix and return the grammar.
646656 *
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ public function hasTable($table)
4242 {
4343 $ sql = $ this ->grammar ->compileTableExists ();
4444
45+ $ table = $ this ->connection ->getTablePrefix ().$ table ;
46+
4547 return count ($ this ->connection ->select ($ sql , array ($ table ))) > 0 ;
4648 }
4749
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Mockery as m ;
4+ use Illuminate \Database \Schema \Builder ;
5+
6+ class DatabaseSchemaBuilderTest extends PHPUnit_Framework_TestCase {
7+
8+ public function tearDown ()
9+ {
10+ m::close ();
11+ }
12+
13+
14+ public function testHasTableCorrectlyCallsGrammar ()
15+ {
16+ $ connection = m::mock ('Illuminate\Database\Connection ' );
17+ $ grammar = m::mock ('StdClass ' );
18+ $ connection ->shouldReceive ('getSchemaGrammar ' )->andReturn ($ grammar );
19+ $ builder = new Builder ($ connection );
20+ $ grammar ->shouldReceive ('compileTableExists ' )->once ()->andReturn ('sql ' );
21+ $ connection ->shouldReceive ('getTablePrefix ' )->once ()->andReturn ('prefix_ ' );
22+ $ connection ->shouldReceive ('select ' )->once ()->with ('sql ' , array ('prefix_table ' ))->andReturn (array ('prefix_table ' ));
23+
24+ $ this ->assertTrue ($ builder ->hasTable ('table ' ));
25+ }
26+
27+ }
You can’t perform that action at this time.
0 commit comments