diff --git a/tests/DatabaseMysqlTest.php b/tests/DatabaseMysqlTest.php index 43fbc1c3..83d8399d 100644 --- a/tests/DatabaseMysqlTest.php +++ b/tests/DatabaseMysqlTest.php @@ -2,6 +2,9 @@ use Nano\NanoBaseTest; +/** + * Requires MySQL server running on 0.0.0.0:3306 + */ class DatabaseMysqlTest extends NanoBaseTest { /** @@ -12,7 +15,7 @@ class DatabaseMysqlTest extends NanoBaseTest protected function setUp(): void { parent::setUp(); - $this->database = Database::connect($this->app, ['driver' => 'mysql', 'host' => '0.0.0.0', 'user' => 'root', 'pass' => '', 'database' => 'mysql']); + $this->database = Database::connect($this->app, ['driver' => 'mysql', 'host' => '0.0.0.0', 'user' => 'root', 'pass' => '']); } public function testLazyConnect() @@ -29,13 +32,11 @@ public function testLazyConnect() $this->assertTrue($this->database->isConnected(), 'We should be connected now'); } - // requires server running on localhost:3306 public function testMySqlDatabase() { // test performance data $performanceData = $this->database->getPerformanceData(); $this->assertEquals(0, $performanceData['queries']); - $this->assertEquals(0, $performanceData['time']); try { $this->database->query('SELECT 1'); @@ -43,29 +44,13 @@ public function testMySqlDatabase() $this->markTestSkipped('Requires server running on localhost:3306 - ' . $e->getMessage()); } - $res = $this->database->select('test', '*'); - foreach ($res as $i => $row) { - #var_dump($row); - } - $res->free(); - - $res = $this->database->select('test', '*'); - while ($row = $res->fetchRow()) { - #var_dump($row); - } - $res->free(); - - $row = $this->database->selectRow('test', '*', ['id' => 2]); - #var_dump($row); - - $row = $this->database->selectField('test', 'count(*)'); - #var_dump($row); - - $res = $this->database->query('SELECT VERSION()'); - #var_dump($res->fetchField()); + // DUAL is purely for the convenience of people who require that all SELECT statements + // should have FROM and possibly other clauses. MySQL may ignore the clauses. + // MySQL does not require FROM DUAL if no tables are referenced. + $this->assertEquals('1', $this->database->selectField('dual', '1')); + $this->assertEquals(1, $this->database->select('dual', '1')->count()); $performanceData = $this->database->getPerformanceData(); - $this->assertEquals(5, $performanceData['queries']); - $this->assertTrue($performanceData['time'] > 0); + $this->assertEquals(3, $performanceData['queries']); } }