Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
e6a9e645
Commit
e6a9e645
authored
Sep 03, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished Connection.
parent
f082c0eb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
23 deletions
+60
-23
YiiBase.php
framework/YiiBase.php
+2
-6
ApplicationComponent.php
framework/base/ApplicationComponent.php
+0
-12
Connection.php
framework/db/dao/Connection.php
+0
-0
Schema.php
framework/db/dao/mysql/Schema.php
+1
-1
ConnectionTest.php
tests/unit/framework/db/dao/ConnectionTest.php
+57
-4
No files found.
framework/YiiBase.php
View file @
e6a9e645
...
...
@@ -349,17 +349,13 @@ class YiiBase
$object
=
new
$class
;
}
if
(
$object
instanceof
Initable
)
{
foreach
(
$config
as
$name
=>
$value
)
{
$object
->
$name
=
$value
;
}
if
(
$object
instanceof
\yii\base\Initable
)
{
$object
->
init
();
}
else
{
foreach
(
$config
as
$name
=>
$value
)
{
$object
->
$name
=
$value
;
}
}
return
$object
;
}
...
...
framework/base/ApplicationComponent.php
View file @
e6a9e645
...
...
@@ -28,18 +28,6 @@ abstract class ApplicationComponent extends Component implements Initable
public
$behaviors
=
array
();
/**
* Pre-initializes this component.
* This method is required by the [[Initable]] interface. It is invoked by
* [[\Yii::createComponent]] after its creates the new component instance but
* BEFORE the component properties are initialized.
*
* You may override this method to do work such as setting property default values.
*/
public
function
preinit
()
{
}
/**
* Initializes the application component.
* This method is invoked after the component is created and its property values are
* initialized. The default implementation will call [[Component::attachBehaviors]]
...
...
framework/db/dao/Connection.php
View file @
e6a9e645
This diff is collapsed.
Click to expand it.
framework/db/dao/mysql/Schema.php
View file @
e6a9e645
...
...
@@ -143,7 +143,7 @@ class Schema extends \yii\db\dao\Schema
foreach
(
$matches
as
$match
)
{
$fks
=
array_map
(
'trim'
,
explode
(
','
,
str_replace
(
'`'
,
''
,
$match
[
1
])));
$pks
=
array_map
(
'trim'
,
explode
(
','
,
str_replace
(
'`'
,
''
,
$match
[
3
])));
$constraint
=
array
(
str_replace
(
'`'
,
''
,
$match
[
2
]))
,
$constraint
=
array
(
str_replace
(
'`'
,
''
,
$match
[
2
]))
;
foreach
(
$fks
as
$k
=>
$name
)
{
$constraint
[
$name
]
=
$pks
[
$k
];
}
...
...
tests/unit/framework/db/dao/ConnectionTest.php
View file @
e6a9e645
...
...
@@ -7,13 +7,14 @@ class ConnectionTest extends TestCase
function
setUp
()
{
if
(
!
extension_loaded
(
'pdo'
)
||
!
extension_loaded
(
'pdo_mysql'
))
$this
->
markTestSkipped
(
'
PDO and MySQL
extensions are required.'
);
$this
->
markTestSkipped
(
'
pdo and pdo_mysql
extensions are required.'
);
}
function
testConstruct
()
{
$connection
=
$this
->
createConnection
();
$params
=
$this
->
getParam
(
'mysql'
);
$connection
=
new
Connection
(
$params
[
'dsn'
],
$params
[
'username'
],
$params
[
'password'
]);
$this
->
assertEquals
(
$params
[
'dsn'
],
$connection
->
dsn
);
$this
->
assertEquals
(
$params
[
'username'
],
$connection
->
username
);
$this
->
assertEquals
(
$params
[
'password'
],
$connection
->
password
);
...
...
@@ -21,8 +22,8 @@ class ConnectionTest extends TestCase
function
testOpenClose
()
{
$
params
=
$this
->
getParam
(
'mysql'
);
$connection
=
new
Connection
(
$params
[
'dsn'
],
$params
[
'username'
],
$params
[
'password'
]);
$
connection
=
$this
->
createConnection
(
);
$this
->
assertFalse
(
$connection
->
active
);
$this
->
assertEquals
(
null
,
$connection
->
pdo
);
...
...
@@ -39,6 +40,58 @@ class ConnectionTest extends TestCase
$connection
->
open
();
}
function
testGetDriverName
()
{
$connection
=
$this
->
createConnection
();
$this
->
assertEquals
(
'mysql'
,
$connection
->
driverName
);
$this
->
assertFalse
(
$connection
->
active
);
}
function
testQuoteValue
()
{
$connection
=
$this
->
createConnection
();
$this
->
assertEquals
(
123
,
$connection
->
quoteValue
(
123
));
$this
->
assertEquals
(
"'string'"
,
$connection
->
quoteValue
(
'string'
));
$this
->
assertEquals
(
"'It\'s interesting'"
,
$connection
->
quoteValue
(
"It's interesting"
));
}
function
testQuoteTableName
()
{
$connection
=
$this
->
createConnection
();
$this
->
assertEquals
(
'`table`'
,
$connection
->
quoteTableName
(
'table'
));
$this
->
assertEquals
(
'`table`'
,
$connection
->
quoteTableName
(
'`table`'
));
$this
->
assertEquals
(
'`schema`.`table`'
,
$connection
->
quoteTableName
(
'schema.table'
));
}
function
testQuoteColumnName
()
{
$connection
=
$this
->
createConnection
();
$this
->
assertEquals
(
'`column`'
,
$connection
->
quoteColumnName
(
'column'
));
$this
->
assertEquals
(
'`column`'
,
$connection
->
quoteColumnName
(
'`column`'
));
$this
->
assertEquals
(
'`table`.`column`'
,
$connection
->
quoteColumnName
(
'table.column'
));
}
function
testGetPdoType
()
{
$connection
=
$this
->
createConnection
();
$this
->
assertEquals
(
\PDO
::
PARAM_BOOL
,
$connection
->
getPdoType
(
'boolean'
));
$this
->
assertEquals
(
\PDO
::
PARAM_INT
,
$connection
->
getPdoType
(
'integer'
));
$this
->
assertEquals
(
\PDO
::
PARAM_STR
,
$connection
->
getPdoType
(
'string'
));
$this
->
assertEquals
(
\PDO
::
PARAM_NULL
,
$connection
->
getPdoType
(
'NULL'
));
}
function
testAttribute
()
{
}
function
createConnection
()
{
$params
=
$this
->
getParam
(
'mysql'
);
return
new
Connection
(
$params
[
'dsn'
],
$params
[
'username'
],
$params
[
'password'
]);
}
/*
function testCreateCommand()
{
...
...
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