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
cd5bdd90
Commit
cd5bdd90
authored
Jun 25, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed postgres tests
parent
c6f711cc
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
16 deletions
+58
-16
postgres.sql
tests/unit/data/postgres.sql
+10
-1
BatchQueryResultTest.php
tests/unit/framework/db/BatchQueryResultTest.php
+2
-2
CommandTest.php
tests/unit/framework/db/CommandTest.php
+12
-4
SchemaTest.php
tests/unit/framework/db/SchemaTest.php
+1
-1
PostgreSQLCommandTest.php
tests/unit/framework/db/pgsql/PostgreSQLCommandTest.php
+6
-7
PostgreSQLSchemaTest.php
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
+24
-1
SqliteQueryBuilderTest.php
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php
+3
-0
No files found.
tests/unit/data/postgres.sql
View file @
cd5bdd90
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
* and create an account 'postgres/postgres' which owns this test database.
* and create an account 'postgres/postgres' which owns this test database.
*/
*/
DROP
TABLE
IF
EXISTS
"composite_fk"
CASCADE
;
DROP
TABLE
IF
EXISTS
"order_item"
CASCADE
;
DROP
TABLE
IF
EXISTS
"order_item"
CASCADE
;
DROP
TABLE
IF
EXISTS
"item"
CASCADE
;
DROP
TABLE
IF
EXISTS
"item"
CASCADE
;
DROP
TABLE
IF
EXISTS
"order_item_with_null_fk"
CASCADE
;
DROP
TABLE
IF
EXISTS
"order_item_with_null_fk"
CASCADE
;
...
@@ -78,6 +79,14 @@ CREATE TABLE "order_item_with_null_fk" (
...
@@ -78,6 +79,14 @@ CREATE TABLE "order_item_with_null_fk" (
subtotal
decimal
(
10
,
0
)
NOT
NULL
subtotal
decimal
(
10
,
0
)
NOT
NULL
);
);
CREATE
TABLE
"composite_fk"
(
id
integer
NOT
NULL
,
order_id
integer
NOT
NULL
,
item_id
integer
NOT
NULL
,
PRIMARY
KEY
(
id
),
CONSTRAINT
FK_composite_fk_order_item
FOREIGN
KEY
(
order_id
,
item_id
)
REFERENCES
"order_item"
(
order_id
,
item_id
)
ON
DELETE
CASCADE
);
CREATE
TABLE
"null_values"
(
CREATE
TABLE
"null_values"
(
id
INT
NOT
NULL
,
id
INT
NOT
NULL
,
var1
INT
NULL
,
var1
INT
NULL
,
...
@@ -101,7 +110,7 @@ CREATE TABLE "type" (
...
@@ -101,7 +110,7 @@ CREATE TABLE "type" (
bool_col
smallint
NOT
NULL
,
bool_col
smallint
NOT
NULL
,
bool_col2
smallint
DEFAULT
'1'
,
bool_col2
smallint
DEFAULT
'1'
,
ts_default
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
ts_default
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
bit_col
BIT
NOT
NULL
DEFAULT
B
'10000010'
bit_col
BIT
(
8
)
NOT
NULL
DEFAULT
B
'10000010'
);
);
INSERT
INTO
"profile"
(
description
)
VALUES
(
'profile customer 1'
);
INSERT
INTO
"profile"
(
description
)
VALUES
(
'profile customer 1'
);
...
...
tests/unit/framework/db/BatchQueryResultTest.php
View file @
cd5bdd90
...
@@ -14,8 +14,8 @@ use yii\db\BatchQueryResult;
...
@@ -14,8 +14,8 @@ use yii\db\BatchQueryResult;
use
yiiunit\data\ar\Customer
;
use
yiiunit\data\ar\Customer
;
/**
/**
* @
author Qiang Xue <qiang.xue@gmail.com>
* @
group db
* @
since 2.0
* @
group mysql
*/
*/
class
BatchQueryResultTest
extends
DatabaseTestCase
class
BatchQueryResultTest
extends
DatabaseTestCase
{
{
...
...
tests/unit/framework/db/CommandTest.php
View file @
cd5bdd90
...
@@ -159,7 +159,7 @@ class CommandTest extends DatabaseTestCase
...
@@ -159,7 +159,7 @@ class CommandTest extends DatabaseTestCase
$sql
=
'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)'
;
$sql
=
'INSERT INTO type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, :blob_col, :numeric_col, :bool_col)'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
=
$db
->
createCommand
(
$sql
);
$intCol
=
123
;
$intCol
=
123
;
$charCol
=
'abc'
;
$charCol
=
str_repeat
(
'abc'
,
33
)
.
'x'
;
// a 100 char string
$floatCol
=
1.23
;
$floatCol
=
1.23
;
$blobCol
=
"
\x10\x11\x12
"
;
$blobCol
=
"
\x10\x11\x12
"
;
$numericCol
=
'1.23'
;
$numericCol
=
'1.23'
;
...
@@ -172,13 +172,21 @@ class CommandTest extends DatabaseTestCase
...
@@ -172,13 +172,21 @@ class CommandTest extends DatabaseTestCase
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$command
->
bindParam
(
':bool_col'
,
$boolCol
);
$this
->
assertEquals
(
1
,
$command
->
execute
());
$this
->
assertEquals
(
1
,
$command
->
execute
());
$sql
=
'SELECT * FROM type'
;
$command
=
$db
->
createCommand
(
'SELECT int_col, char_col, float_col, blob_col, numeric_col, bool_col FROM type'
);
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
// $command->prepare();
// $command->pdoStatement->bindColumn('blob_col', $bc, \PDO::PARAM_LOB);
$row
=
$command
->
queryOne
();
$this
->
assertEquals
(
$intCol
,
$row
[
'int_col'
]);
$this
->
assertEquals
(
$intCol
,
$row
[
'int_col'
]);
$this
->
assertEquals
(
$charCol
,
$row
[
'char_col'
]);
$this
->
assertEquals
(
$charCol
,
$row
[
'char_col'
]);
$this
->
assertEquals
(
$floatCol
,
$row
[
'float_col'
]);
$this
->
assertEquals
(
$floatCol
,
$row
[
'float_col'
]);
$this
->
assertEquals
(
$blobCol
,
$row
[
'blob_col'
]);
if
(
$this
->
driverName
===
'mysql'
||
$this
->
driverName
===
'sqlite'
)
{
$this
->
assertEquals
(
$blobCol
,
$row
[
'blob_col'
]);
}
else
{
$this
->
assertTrue
(
is_resource
(
$row
[
'blob_col'
]));
$this
->
assertEquals
(
$blobCol
,
stream_get_contents
(
$row
[
'blob_col'
]));
}
$this
->
assertEquals
(
$numericCol
,
$row
[
'numeric_col'
]);
$this
->
assertEquals
(
$numericCol
,
$row
[
'numeric_col'
]);
$this
->
assertEquals
(
$boolCol
,
$row
[
'bool_col'
]);
// bindValue
// bindValue
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
$sql
=
'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'
;
...
...
tests/unit/framework/db/SchemaTest.php
View file @
cd5bdd90
...
@@ -87,7 +87,7 @@ class SchemaTest extends DatabaseTestCase
...
@@ -87,7 +87,7 @@ class SchemaTest extends DatabaseTestCase
$schema
=
$this
->
getConnection
()
->
schema
;
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
)
{
foreach
(
$values
as
$value
)
{
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
]));
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
])
,
'type for value '
.
print_r
(
$value
[
0
],
true
)
.
' does not match.'
);
}
}
fclose
(
$fp
);
fclose
(
$fp
);
}
}
...
...
tests/unit/framework/db/pgsql/PostgreSQLCommandTest.php
View file @
cd5bdd90
...
@@ -3,6 +3,10 @@ namespace yii\tests\unit\framework\db\pgsql;
...
@@ -3,6 +3,10 @@ namespace yii\tests\unit\framework\db\pgsql;
use
yiiunit\framework\db\CommandTest
;
use
yiiunit\framework\db\CommandTest
;
/**
* @group db
* @group pgsql
*/
class
PostgreSQLCommandTest
extends
CommandTest
class
PostgreSQLCommandTest
extends
CommandTest
{
{
public
$driverName
=
'pgsql'
;
public
$driverName
=
'pgsql'
;
...
@@ -15,9 +19,4 @@ class PostgreSQLCommandTest extends CommandTest
...
@@ -15,9 +19,4 @@ class PostgreSQLCommandTest extends CommandTest
$command
=
$db
->
createCommand
(
$sql
);
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
'SELECT "id", "t"."name" FROM "customer" t'
,
$command
->
sql
);
$this
->
assertEquals
(
'SELECT "id", "t"."name" FROM "customer" t'
,
$command
->
sql
);
}
}
}
public
function
testBindParamValue
()
\ No newline at end of file
{
$this
->
markTestIncomplete
(
'TODO: impement it'
);
}
}
\ No newline at end of file
tests/unit/framework/db/pgsql/PostgreSQLSchemaTest.php
View file @
cd5bdd90
...
@@ -53,8 +53,31 @@ class PostgreSQLSchemaTest extends SchemaTest
...
@@ -53,8 +53,31 @@ class PostgreSQLSchemaTest extends SchemaTest
$columns
[
'bool_col2'
][
'scale'
]
=
0
;
$columns
[
'bool_col2'
][
'scale'
]
=
0
;
$columns
[
'ts_default'
][
'defaultValue'
]
=
new
Expression
(
'now()'
);
$columns
[
'ts_default'
][
'defaultValue'
]
=
new
Expression
(
'now()'
);
$columns
[
'bit_col'
][
'dbType'
]
=
'bit'
;
$columns
[
'bit_col'
][
'dbType'
]
=
'bit'
;
$columns
[
'bit_col'
][
'size'
]
=
1
;
// TODO should be 8???
$columns
[
'bit_col'
][
'size'
]
=
8
;
$columns
[
'bit_col'
][
'precision'
]
=
null
;
$columns
[
'bit_col'
][
'precision'
]
=
null
;
return
$columns
;
return
$columns
;
}
}
public
function
testGetPDOType
()
{
$values
=
[
[
null
,
\PDO
::
PARAM_NULL
],
[
''
,
\PDO
::
PARAM_STR
],
[
'hello'
,
\PDO
::
PARAM_STR
],
[
0
,
\PDO
::
PARAM_INT
],
[
1
,
\PDO
::
PARAM_INT
],
[
1337
,
\PDO
::
PARAM_INT
],
[
true
,
\PDO
::
PARAM_INT
],
[
false
,
\PDO
::
PARAM_INT
],
[
$fp
=
fopen
(
__FILE__
,
'rb'
),
\PDO
::
PARAM_LOB
],
];
/* @var $schema Schema */
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
)
{
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
]));
}
fclose
(
$fp
);
}
}
}
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php
View file @
cd5bdd90
...
@@ -84,6 +84,9 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
...
@@ -84,6 +84,9 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public
function
testBatchInsert
()
public
function
testBatchInsert
()
{
{
if
(
version_compare
(
\SQLite3
::
version
()[
'versionString'
],
'3.7.11'
,
'>='
))
{
$this
->
markTestSkipped
(
'This test is only relevant for SQLite < 3.7.11'
);
}
$sql
=
$this
->
getQueryBuilder
()
->
batchInsert
(
'{{customer}} t'
,
[
't.id'
,
't.name'
],
[[
1
,
'a'
],
[
2
,
'b'
]]);
$sql
=
$this
->
getQueryBuilder
()
->
batchInsert
(
'{{customer}} t'
,
[
't.id'
,
't.name'
],
[[
1
,
'a'
],
[
2
,
'b'
]]);
$this
->
assertEquals
(
"INSERT INTO
{
{customer}
}
t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'"
,
$sql
);
$this
->
assertEquals
(
"INSERT INTO
{
{customer}
}
t (`t`.`id`, `t`.`name`) SELECT 1, 'a' UNION SELECT 2, 'b'"
,
$sql
);
}
}
...
...
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