Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
917d4cb1
Commit
917d4cb1
authored
Sep 16, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testing database.
parent
4167a295
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
4 deletions
+108
-4
connection.php
laravel/database/connection.php
+4
-1
manager.php
laravel/database/manager.php
+6
-3
DatabaseManagerTest.php
tests/Database/DatabaseManagerTest.php
+98
-0
No files found.
laravel/database/connection.php
View file @
917d4cb1
...
@@ -25,7 +25,10 @@ class Connection {
...
@@ -25,7 +25,10 @@ class Connection {
* @param PDO $pdo
* @param PDO $pdo
* @return void
* @return void
*/
*/
public
function
__construct
(
PDO
$pdo
)
{
$this
->
pdo
=
$pdo
;
}
public
function
__construct
(
PDO
$pdo
)
{
$this
->
pdo
=
$pdo
;
}
/**
/**
* Execute a SQL query against the connection and return a scalar result.
* Execute a SQL query against the connection and return a scalar result.
...
...
laravel/database/manager.php
View file @
917d4cb1
...
@@ -15,7 +15,10 @@ class Manager {
...
@@ -15,7 +15,10 @@ class Manager {
* @param array $config
* @param array $config
* @return void
* @return void
*/
*/
public
function
__construct
(
$config
)
{
$this
->
config
=
$config
;
}
public
function
__construct
(
$config
)
{
$this
->
config
=
$config
;
}
/**
/**
* Get a database connection.
* Get a database connection.
...
@@ -26,7 +29,7 @@ class Manager {
...
@@ -26,7 +29,7 @@ class Manager {
* Note: Database connections are managed as singletons.
* Note: Database connections are managed as singletons.
*
*
* @param string $connection
* @param string $connection
* @return
Database\
Connection
* @return Connection
*/
*/
public
function
connection
(
$connection
=
null
)
public
function
connection
(
$connection
=
null
)
{
{
...
...
tests/Database/DatabaseManagerTest.php
0 → 100644
View file @
917d4cb1
<?php
use
Laravel\Database\Manager
;
class
DatabaseManagerTest
extends
PHPUnit_Framework_TestCase
{
public
function
testWhenCallingConnectionMethodForNonEstablishedConnectionNewConnectionIsReturned
()
{
$manager
=
new
Manager
(
$this
->
getConfig
());
$connection
=
$manager
->
connection
();
$this
->
assertInstanceOf
(
'PDOStub'
,
$connection
->
pdo
);
$this
->
assertInstanceOf
(
'Laravel\\Database\\Connection'
,
$connection
);
}
public
function
testConnectionMethodsReturnsSingletonConnections
()
{
$manager
=
new
Manager
(
$this
->
getConfig
());
$connection
=
$manager
->
connection
();
$this
->
assertTrue
(
$connection
===
$manager
->
connection
());
}
public
function
testConnectionMethodOverridesDefaultWhenConnectionNameIsGiven
()
{
$config
=
$this
->
getConfig
();
$config
[
'connectors'
][
'something'
]
=
function
(
$config
)
{
return
new
AnotherPDOStub
;};
$manager
=
new
Manager
(
$config
);
$this
->
assertInstanceOf
(
'AnotherPDOStub'
,
$manager
->
connection
(
'something'
)
->
pdo
);
}
public
function
testConfigurationArrayIsPassedToConnector
()
{
$manager
=
new
Manager
(
$this
->
getConfig
());
$this
->
assertEquals
(
$manager
->
connection
()
->
pdo
->
config
,
$this
->
getConfig
());
}
/**
* @expectedException Exception
*/
public
function
testExceptionIsThrownIfConnectorIsNotDefined
()
{
$manager
=
new
Manager
(
$this
->
getConfig
());
$manager
->
connection
(
'something'
);
}
public
function
testTableMethodCallsTableMethodOnConnection
()
{
$manager
=
new
Manager
(
$this
->
getConfig
());
$this
->
assertEquals
(
$manager
->
table
(
'users'
),
'table'
);
}
// ---------------------------------------------------------------------
// Support Functions
// ---------------------------------------------------------------------
private
function
getConfig
()
{
return
array
(
'default'
=>
'test'
,
'connectors'
=>
array
(
'test'
=>
function
(
$config
)
{
return
new
PDOStub
(
$config
);}));
}
}
// ---------------------------------------------------------------------
// Stubs
// ---------------------------------------------------------------------
class
PDOStub
extends
PDO
{
public
$config
;
public
function
__construct
(
$config
=
array
())
{
$this
->
config
=
$config
;
}
public
function
table
()
{
return
'table'
;
}
}
class
AnotherPDOStub
extends
PDO
{
public
function
__construct
()
{}
public
function
table
()
{
return
'anotherTable'
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment