Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pquery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pquery
Commits
85134e9a
Commit
85134e9a
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Reversed assertion arguments to match PHPUnit documentation.
parent
6bbdb4ef
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/array.php
+5
-5
5 additions, 5 deletions
test/array.php
test/sql.php
+34
-36
34 additions, 36 deletions
test/sql.php
test/template.php
+2
-2
2 additions, 2 deletions
test/template.php
with
41 additions
and
43 deletions
test/array.php
+
5
−
5
View file @
85134e9a
...
@@ -14,11 +14,11 @@ class pQueryArrayTest extends PHPUnit_Framework_TestCase {
...
@@ -14,11 +14,11 @@ class pQueryArrayTest extends PHPUnit_Framework_TestCase {
function
test_constructor
()
{
function
test_constructor
()
{
$this
->
assertTrue
(
$this
->
arr
instanceof
pQueryArray
,
'constructor does not return pQueryArray object.'
);
$this
->
assertTrue
(
$this
->
arr
instanceof
pQueryArray
,
'constructor does not return pQueryArray object.'
);
$this
->
assertEquals
(
$this
->
arr
->
variable
,
$this
->
variable
,
'variable is not set correctly.'
);
$this
->
assertEquals
(
$this
->
variable
,
$this
->
arr
->
variable
,
'variable is not set correctly.'
);
}
}
function
test_get_simple
()
{
function
test_get_simple
()
{
$this
->
assertEquals
(
$this
->
ar
r
->
get
(
0
)
,
$this
->
v
ar
iable
[
0
]
);
$this
->
assertEquals
(
$this
->
v
ar
iable
[
0
]
,
$this
->
ar
r
->
get
(
0
)
);
}
}
function
test_get_non_existent
()
{
function
test_get_non_existent
()
{
...
@@ -37,17 +37,17 @@ class pQueryArrayTest extends PHPUnit_Framework_TestCase {
...
@@ -37,17 +37,17 @@ class pQueryArrayTest extends PHPUnit_Framework_TestCase {
$orginal
=
range
(
1
,
4
);
$orginal
=
range
(
1
,
4
);
$reverse
=
range
(
4
,
1
,
-
1
);
$reverse
=
range
(
4
,
1
,
-
1
);
$arr
=
_arr
(
$orginal
);
$arr
=
_arr
(
$orginal
);
$this
->
assertEquals
(
$arr
->
reverse
()
->
variable
,
$reverse
,
'reverse is not really reverse...'
);
$this
->
assertEquals
(
$reverse
,
$arr
->
reverse
()
->
variable
,
'reverse is not really reverse...'
);
}
}
function
test_call_count
()
{
function
test_call_count
()
{
$this
->
assertEquals
(
$this
->
arr
->
count
(),
count
(
$this
->
variable
));
$this
->
assertEquals
(
count
(
$this
->
variable
),
$this
->
arr
->
count
(
));
}
}
function
test_call_sort
()
{
function
test_call_sort
()
{
$arr
=
range
(
1
,
8
);
$arr
=
range
(
1
,
8
);
shuffle
(
$arr
);
shuffle
(
$arr
);
$this
->
assertEquals
(
_arr
(
$arr
)
->
sort
()
->
variable
,
range
(
1
,
8
)
);
$this
->
assertEquals
(
range
(
1
,
8
),
_arr
(
$arr
)
->
sort
()
->
variable
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
test/sql.php
+
34
−
36
View file @
85134e9a
...
@@ -17,10 +17,10 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -17,10 +17,10 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
$this
->
tearDown
();
$this
->
tearDown
();
__sql
::
set_login_data
(
'a'
,
'b'
,
'c'
,
'd'
);
__sql
::
set_login_data
(
'a'
,
'b'
,
'c'
,
'd'
);
$this
->
assertEquals
(
__sql
::
$login_data
[
'host'
]
,
'a'
);
$this
->
assertEquals
(
'a'
,
__sql
::
$login_data
[
'host'
]);
$this
->
assertEquals
(
__sql
::
$login_data
[
'username'
]
,
'b'
);
$this
->
assertEquals
(
'b'
,
__sql
::
$login_data
[
'username'
]);
$this
->
assertEquals
(
__sql
::
$login_data
[
'password'
]
,
'c'
);
$this
->
assertEquals
(
'c'
,
__sql
::
$login_data
[
'password'
]);
$this
->
assertEquals
(
__sql
::
$login_data
[
'dbname'
]
,
'd'
);
$this
->
assertEquals
(
'd'
,
__sql
::
$login_data
[
'dbname'
]);
}
}
/**
/**
...
@@ -33,61 +33,61 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -33,61 +33,61 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
function
test_query_getter
()
{
function
test_query_getter
()
{
$sql
=
_sql
(
'foobar'
);
$sql
=
_sql
(
'foobar'
);
$this
->
assertEquals
(
$sql
->
variable
,
'foobar'
);
$this
->
assertEquals
(
'foobar'
,
$sql
->
variable
);
$this
->
assertEquals
(
$sql
->
query
,
'foobar'
);
$this
->
assertEquals
(
'foobar'
,
$sql
->
query
);
}
}
function
test_variable_query
()
{
function
test_variable_query
()
{
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
->
set
(
array
(
'bar'
=>
'test1'
));
->
set
(
array
(
'bar'
=>
'test1'
));
$this
->
assertEquals
(
$sql
->
query
,
"select id from foo where bar = 'test1'"
);
$this
->
assertEquals
(
"select id from foo where bar = 'test1'"
,
$sql
->
query
);
}
}
function
test_unescaped_query
()
{
function
test_unescaped_query
()
{
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
->
set_unescaped
(
array
(
'bar'
=>
"select id from foo where bar = 'test1'"
));
->
set_unescaped
(
array
(
'bar'
=>
"select id from foo where bar = 'test1'"
));
$this
->
assertEquals
(
$sql
->
query
,
"select id from foo where bar = 'select id from foo where bar = 'test1''"
);
$this
->
assertEquals
(
"select id from foo where bar = 'select id from foo where bar = 'test1''"
,
$sql
->
query
);
}
}
function
test_escaped_query
()
{
function
test_escaped_query
()
{
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
$sql
=
_sql
(
"select id from foo where bar = '[bar]'"
)
->
set
(
array
(
'bar'
=>
"select id from foo where bar = 'test1'"
));
->
set
(
array
(
'bar'
=>
"select id from foo where bar = 'test1'"
));
$this
->
assertNotEquals
(
$sql
->
query
,
"select id from foo where bar = 'select id from foo where bar = 'test1''"
);
$this
->
assertNotEquals
(
"select id from foo where bar = 'select id from foo where bar = 'test1''"
,
$sql
->
query
);
}
}
function
test_constructor_simple
()
{
function
test_constructor_simple
()
{
$sql
=
_sql
(
"select id from foo where bar = '[0]'"
,
'test1'
);
$sql
=
_sql
(
"select id from foo where bar = '[0]'"
,
'test1'
);
$this
->
assertEquals
(
$sql
->
query
,
"select id from foo where bar = 'test1'"
);
$this
->
assertEquals
(
"select id from foo where bar = 'test1'"
,
$sql
->
query
);
}
}
function
test_constructor_advanced
()
{
function
test_constructor_advanced
()
{
$sql
=
_sql
(
"[0] [bar] [foo] [2]"
,
'1'
,
array
(
'bar'
=>
'2'
,
'foo'
=>
'3'
),
'4'
);
$sql
=
_sql
(
"[0] [bar] [foo] [2]"
,
'1'
,
array
(
'bar'
=>
'2'
,
'foo'
=>
'3'
),
'4'
);
$this
->
assertEquals
(
$sql
->
query
,
"1 2 3 4"
);
$this
->
assertEquals
(
"1 2 3 4"
,
$sql
->
query
);
}
}
function
test_num_rows
()
{
function
test_num_rows
()
{
$sql
=
_sql
(
"select bar from foo where id in (1, 2)"
);
$sql
=
_sql
(
"select bar from foo where id in (1, 2)"
);
$this
->
assertEquals
(
$sql
->
num_rows
()
,
2
);
$this
->
assertEquals
(
2
,
$sql
->
num_rows
());
}
}
function
test_escape_column_simple
()
{
function
test_escape_column_simple
()
{
$this
->
assertEquals
(
__sql
::
escape_column
(
'foo'
)
,
'`foo`'
);
$this
->
assertEquals
(
'`foo`'
,
__sql
::
escape_column
(
'foo'
));
}
}
function
test_escape_column_escaped
()
{
function
test_escape_column_escaped
()
{
$this
->
assertEquals
(
__sql
::
escape_column
(
'`foo`'
)
,
'`foo`'
);
$this
->
assertEquals
(
'`foo`'
,
__sql
::
escape_column
(
'`foo`'
));
}
}
function
test_escape_column_table
()
{
function
test_escape_column_table
()
{
$this
->
assertEquals
(
__sql
::
escape_column
(
'foo.bar'
)
,
'`foo`.`bar`'
);
$this
->
assertEquals
(
'`foo`.`bar`'
,
__sql
::
escape_column
(
'foo.bar'
));
}
}
function
test_escape_column_aggregate
()
{
function
test_escape_column_aggregate
()
{
$this
->
assertEquals
(
__sql
::
escape_column
(
'count(foo)'
)
,
'COUNT(`foo`)'
);
$this
->
assertEquals
(
'COUNT(`foo`)'
,
__sql
::
escape_column
(
'count(foo)'
));
}
}
function
test_escape_column_aggregate_escaped
()
{
function
test_escape_column_aggregate_escaped
()
{
$this
->
assertEquals
(
__sql
::
escape_column
(
'count(`foo`)'
)
,
'COUNT(`foo`)'
);
$this
->
assertEquals
(
'COUNT(`foo`)'
,
__sql
::
escape_column
(
'count(`foo`)'
));
}
}
function
test_escape_value
()
{
function
test_escape_value
()
{
...
@@ -100,58 +100,56 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -100,58 +100,56 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
function
test_parse_columns_star
()
{
function
test_parse_columns_star
()
{
$sql
=
__sql
::
select
(
'foo'
,
'*'
,
''
,
false
);
$sql
=
__sql
::
select
(
'foo'
,
'*'
,
''
,
false
);
$this
->
assertEquals
(
$sql
->
query
,
"SELECT * FROM `foo` WHERE 1;"
);
$this
->
assertEquals
(
"SELECT * FROM `foo` WHERE 1;"
,
$sql
->
query
);
}
}
function
test_parse_columns_simple
()
{
function
test_parse_columns_simple
()
{
$sql
=
__sql
::
select
(
'foo'
,
array
(
'id'
,
'bar'
),
''
,
false
);
$sql
=
__sql
::
select
(
'foo'
,
array
(
'id'
,
'bar'
),
''
,
false
);
$this
->
assertEquals
(
$sql
->
query
,
"SELECT `id`, `bar` FROM `foo` WHERE 1;"
);
$this
->
assertEquals
(
"SELECT `id`, `bar` FROM `foo` WHERE 1;"
,
$sql
->
query
);
}
}
function
test_parse_columns_as
()
{
function
test_parse_columns_as
()
{
$sql
=
__sql
::
select
(
'foo'
,
array
(
'id'
=>
'foo_id'
),
''
,
false
);
$sql
=
__sql
::
select
(
'foo'
,
array
(
'id'
=>
'foo_id'
),
''
,
false
);
$this
->
assertEquals
(
$sql
->
query
,
"SELECT `id` AS `foo_id` FROM `foo` WHERE 1;"
);
$this
->
assertEquals
(
"SELECT `id` AS `foo_id` FROM `foo` WHERE 1;"
,
$sql
->
query
);
}
}
function
test_parse_constraints_empty
()
{
function
test_parse_constraints_empty
()
{
$this
->
assertSame
(
__sql
::
parse_constraints
(
null
,
false
)
,
"1"
);
$this
->
assertSame
(
"1"
,
__sql
::
parse_constraints
(
null
,
false
));
}
}
function
test_parse_constraints_string
()
{
function
test_parse_constraints_string
()
{
$constraints
=
"foo LIKE '%bar%'"
;
$constraints
=
"foo LIKE '%bar%'"
;
$this
->
assertEquals
(
__sql
::
parse_constraints
(
$constraints
,
false
)
,
$constraints
);
$this
->
assertEquals
(
$constraints
,
__sql
::
parse_constraints
(
$constraints
,
false
));
}
}
function
test_parse_constraints_simple
()
{
function
test_parse_constraints_simple
()
{
$this
->
assertEquals
(
__sql
::
parse_constraints
(
$this
->
assertEquals
(
"`id` = '1' AND `bar` = 'test1'"
,
array
(
'id'
=>
1
,
'bar'
=>
'test1'
),
false
),
__sql
::
parse_constraints
(
array
(
'id'
=>
1
,
'bar'
=>
'test1'
),
false
));
"`id` = '1' AND `bar` = 'test1'"
);
}
}
function
test_parse_constraints_value_list
()
{
function
test_parse_constraints_value_list
()
{
$this
->
assertEquals
(
__sql
::
parse_constraints
(
$this
->
assertEquals
(
"`id` IN ('1', '2', '3')"
,
array
(
'id'
=>
range
(
1
,
3
)),
false
),
__sql
::
parse_constraints
(
array
(
'id'
=>
range
(
1
,
3
)),
false
));
"`id` IN ('1', '2', '3')"
);
}
}
function
test_select_query
()
{
function
test_select_query
()
{
$sql
=
__sql
::
select
(
'foo'
,
'*'
,
array
(
'bar'
=>
'test1'
),
false
);
$sql
=
__sql
::
select
(
'foo'
,
'*'
,
array
(
'bar'
=>
'test1'
),
false
);
$this
->
assertEquals
(
$sql
->
query
,
"SELECT * FROM `foo` WHERE `bar` = 'test1';"
);
$this
->
assertEquals
(
"SELECT * FROM `foo` WHERE `bar` = 'test1';"
,
$sql
->
query
);
}
}
function
test_update_query
()
{
function
test_update_query
()
{
$sql
=
__sql
::
update
(
'foo'
,
array
(
'bar'
=>
'test4'
),
array
(
'id'
=>
1
),
false
);
$sql
=
__sql
::
update
(
'foo'
,
array
(
'bar'
=>
'test4'
),
array
(
'id'
=>
1
),
false
);
$this
->
assertEquals
(
$sql
->
query
,
"UPDATE `foo` SET `bar` = 'test4' WHERE `id` = '1';"
);
$this
->
assertEquals
(
"UPDATE `foo` SET `bar` = 'test4' WHERE `id` = '1';"
,
$sql
->
query
);
}
}
function
test_insert_query
()
{
function
test_insert_query
()
{
$sql
=
__sql
::
insert_row
(
'foo'
,
array
(
'bar'
=>
'test3'
),
false
);
$sql
=
__sql
::
insert_row
(
'foo'
,
array
(
'bar'
=>
'test3'
),
false
);
$this
->
assertEquals
(
$sql
->
query
,
"INSERT INTO `foo`(`bar`) VALUES('test3');"
);
$this
->
assertEquals
(
"INSERT INTO `foo`(`bar`) VALUES('test3');"
,
$sql
->
query
);
}
}
function
test_delete_query
()
{
function
test_delete_query
()
{
$sql
=
__sql
::
delete
(
'foo'
,
array
(
'bar'
=>
'test3'
),
false
);
$sql
=
__sql
::
delete
(
'foo'
,
array
(
'bar'
=>
'test3'
),
false
);
$this
->
assertEquals
(
$sql
->
query
,
"DELETE FROM `foo` WHERE `bar` = 'test3';"
);
$this
->
assertEquals
(
"DELETE FROM `foo` WHERE `bar` = 'test3';"
,
$sql
->
query
);
}
}
/**
/**
...
@@ -161,7 +159,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -161,7 +159,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
$sql
=
_sql
(
"select bar from foo where id = 1"
);
$sql
=
_sql
(
"select bar from foo where id = 1"
);
$result
=
$sql
->
fetch
(
'object'
);
$result
=
$sql
->
fetch
(
'object'
);
$this
->
assertEquals
(
'test1'
,
$result
->
bar
);
$this
->
assertEquals
(
'test1'
,
$result
->
bar
);
$this
->
assert
Sam
e
(
$sql
->
fetch
()
,
false
);
$this
->
assert
Fals
e
(
$sql
->
fetch
());
}
}
/**
/**
...
@@ -172,7 +170,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -172,7 +170,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
array
(
'id'
=>
1
),
false
)
->
execute
();
array
(
'id'
=>
1
),
false
)
->
execute
();
// Do not continue unless the value has been updated
// Do not continue unless the value has been updated
$this
->
assert
Sam
e
(
$update
->
result
,
true
);
$this
->
assert
Tru
e
(
$update
->
result
);
}
}
/**
/**
...
@@ -180,7 +178,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -180,7 +178,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
*/
*/
function
test_insert
()
{
function
test_insert
()
{
$insert
=
__sql
::
insert_row
(
'foo'
,
array
(
'bar'
=>
'test3'
))
->
execute
();
$insert
=
__sql
::
insert_row
(
'foo'
,
array
(
'bar'
=>
'test3'
))
->
execute
();
$this
->
assert
Sam
e
(
$insert
->
result
,
true
);
$this
->
assert
Tru
e
(
$insert
->
result
);
}
}
/**
/**
...
@@ -189,7 +187,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
...
@@ -189,7 +187,7 @@ class pQuerySqlTest extends PHPUnit_Framework_TestCase {
*/
*/
function
test_delete
()
{
function
test_delete
()
{
$delete
=
__sql
::
delete
(
'foo'
,
array
(
'bar'
=>
'test3'
))
->
execute
();
$delete
=
__sql
::
delete
(
'foo'
,
array
(
'bar'
=>
'test3'
))
->
execute
();
$this
->
assert
Sam
e
(
$delete
->
result
,
true
);
$this
->
assert
Tru
e
(
$delete
->
result
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
test/template.php
+
2
−
2
View file @
85134e9a
...
@@ -59,7 +59,7 @@ class pQueryTemplateTest extends PHPUnit_Framework_TestCase {
...
@@ -59,7 +59,7 @@ class pQueryTemplateTest extends PHPUnit_Framework_TestCase {
function
test_open_template_file
()
{
function
test_open_template_file
()
{
$path
=
$this
->
templates_folder
.
$this
->
file
;
$path
=
$this
->
templates_folder
.
$this
->
file
;
$content
=
file_get_contents
(
$path
);
$content
=
file_get_contents
(
$path
);
$this
->
assertEquals
(
$this
->
tpl
->
content
,
$content
,
'template content
i
s not set correctly'
);
$this
->
assertEquals
(
$content
,
$this
->
tpl
->
content
,
'template content
wa
s not set correctly'
);
}
}
/**
/**
...
@@ -85,7 +85,7 @@ class pQueryTemplateTest extends PHPUnit_Framework_TestCase {
...
@@ -85,7 +85,7 @@ class pQueryTemplateTest extends PHPUnit_Framework_TestCase {
// Expected content is defined in a text file
// Expected content is defined in a text file
$expected_content
=
file_get_contents
(
$this
->
templates_folder
.
'expect_parse.html'
);
$expected_content
=
file_get_contents
(
$this
->
templates_folder
.
'expect_parse.html'
);
$this
->
assertEquals
(
$
this
->
tpl
->
parse
(),
$expected_content
);
$this
->
assertEquals
(
$
expected_content
,
$this
->
tpl
->
parse
()
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment