Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ability for SQlite to execute init commands con connect
- Loading branch information
Showing
3 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/SqliteTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* PHP Version 5.4 | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @package Cake.Model | ||
* @since CakePHP(tm) v 3.0.0 | ||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | ||
*/ | ||
namespace Cake\Test\TestCase\Model\Datasource\Database\Driver; | ||
|
||
use \PDO; | ||
|
||
/** | ||
* Tests Sqlite driver | ||
* | ||
*/ | ||
class SqliteTest extends \Cake\TestSuite\TestCase { | ||
|
||
/** | ||
* Test connecting to Sqlite with default configuration | ||
* | ||
* @return void | ||
*/ | ||
public function testConnectionConfigDefault() { | ||
$driver = $this->getMock('Cake\Model\Datasource\Database\driver\Sqlite', ['_connect']); | ||
$expected = [ | ||
'persistent' => false, | ||
'database' => ':memory:', | ||
'encoding' => 'utf8', | ||
'login' => null, | ||
'password' => null, | ||
'flags' => [], | ||
'init' => [], | ||
'dsn' => 'sqlite::memory:' | ||
]; | ||
|
||
$expected['flags'] += [ | ||
PDO::ATTR_PERSISTENT => false, | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION | ||
]; | ||
$driver->expects($this->once())->method('_connect') | ||
->with($expected); | ||
$driver->connect([]); | ||
} | ||
|
||
/** | ||
* Test connecting to Sqlite with custom configuration | ||
* | ||
* @return void | ||
*/ | ||
public function testConnectionConfigCustom() { | ||
$driver = $this->getMock('Cake\Model\Datasource\Database\driver\Sqlite', ['_connect', 'connection']); | ||
$config = [ | ||
'persistent' => true, | ||
'host' => 'foo', | ||
'database' => 'bar.db', | ||
'flags' => [1 => true, 2 => false], | ||
'encoding' => 'a-language', | ||
'init' => ['Execute this', 'this too'] | ||
]; | ||
|
||
$expected = $config; | ||
$expected += ['login' => null, 'password' => null]; | ||
$expected['dsn'] = 'sqlite:bar.db'; | ||
$expected['flags'] += [ | ||
PDO::ATTR_PERSISTENT => true, | ||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION | ||
]; | ||
|
||
$connection = $this->getMock('StdClass', ['exec']); | ||
$connection->expects($this->at(0))->method('exec')->with('Execute this'); | ||
$connection->expects($this->at(1))->method('exec')->with('this too'); | ||
$connection->expects($this->exactly(2))->method('exec'); | ||
|
||
$driver->expects($this->once())->method('_connect') | ||
->with($expected); | ||
$driver->expects($this->any())->method('connection') | ||
->will($this->returnValue($connection)); | ||
$driver->connect($config); | ||
} | ||
|
||
} | ||
|
||
|
Ah this is very similar to the settings feature in 2.x that I referred to earlier.