Skip to content

Commit

Permalink
Added "dblib" driver option
Browse files Browse the repository at this point in the history
Added DBlibConfig class for "dblib" driver

Update README.md

Update README.md

Added forgotten brackets

Unit test case for DBlibConfig

Changed wrong class name in DBlibConfigTest

Update DBlibConfigTest.php

Update DBlibConfigTest.php

fix expected values in DBLibConfig unit test
  • Loading branch information
cristianp6 authored and csanquer committed Jul 2, 2014
1 parent 05fa6b4 commit 24b48d0
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $app->register(
new PdoServiceProvider('pdo'),
array(
'pdo.server' => array(
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
'driver' => 'mysql',
'host' => 'mysql',
'dbname' => 'rfactori',
Expand Down Expand Up @@ -84,7 +84,7 @@ $app->register(
array(
// use previous custom prefix pdo.db1
'pdo.db1.server' => array(
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
'driver' => 'mysql',
'host' => '127.0.0.1',
'dbname' => 'db1',
Expand Down
40 changes: 40 additions & 0 deletions src/Config/DBlibConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace CSanquer\Silex\PdoServiceProvider\Config;

/**
* DBlibConfig
*
* @author Cristian Pascottini <[email protected]>
*/
class DBlibConfig extends PdoConfig
{
protected $driver = 'dblib';

protected $defaults = array(
'host' => 'localhost',
'port' => 1433,
'MultipleActiveResultSets' => null,
'password' => null,
);

protected $allowedTypes = array(
'host' => array('string'),
'port' => array('integer', 'null'),
'dbname' => array('string'),
'user' => array('string'),
'password' => array('string', 'null'),
'MultipleActiveResultSets' => array('boolean', 'null'),
);

protected function resolve(array $params)
{
$params = parent::resolve($params);

if (is_null($params['MultipleActiveResultSets'])){
unset($params['MultipleActiveResultSets']);
}

return $params;
}
}
3 changes: 3 additions & 0 deletions src/Config/PdoConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function createConfig($driver)
case 'oracle':
$cfg = new OracleConfig();
break;
case 'dblib':
$cfg = new DBlibConfig();
break;
case 'sqlsrv':
case 'sqlserver':
case 'mssqlserver':
Expand Down
70 changes: 70 additions & 0 deletions tests/Config/DBlibConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace CSanquer\Silex\PdoServiceProvider\Tests\Config;

use CSanquer\Silex\PdoServiceProvider\Config\DBlibConfig;

/**
* TestCase for DBlibConfig
*
* @author Cristian Pascottini <[email protected]>
*
*/
class DBlibConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* @var DBlibConfig
*/
protected $pdoConfig;

public function setUp()
{
$this->pdoConfig = new DBlibConfig();
}

/**
* @dataProvider dataProviderPrepareParameters
*/
public function testPrepareParameters($params, $expected)
{
$result = $this->pdoConfig->prepareParameters($params);
$this->assertEquals($expected, $result);
}

public function dataProviderPrepareParameters()
{
return array(
array(
array(
'dbname' => 'fake-db',
'user' => 'fake-user',
'password' => 'fake-password',
),
array(
'dsn' => 'dblib:host=localhost;port=1433;dbname=fake-db',
'user' => 'fake-user',
'password' => 'fake-password',
'options' => array(),
'attributes' => array(),
),
),
array(
array(
'host' => '127.0.0.1',
'port' => null,
'dbname' => 'fake-db',
'user' => 'fake-user',
'password' => 'fake-password',
'attributes' => array(),
),
array(
'dsn' => 'dblib:host=127.0.0.1;dbname=fake-db',
'user' => 'fake-user',
'password' => 'fake-password',
'options' => array(),
'attributes' => array(),
),
),
);
}
}

0 comments on commit 24b48d0

Please sign in to comment.