Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
08b83087
Commit
08b83087
authored
Apr 23, 2014
by
Davi Koscianski Vidal
Committed by
lucasvanlierop
Jun 30, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRYing up tests and abstraction layer
parent
4090136a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
42 deletions
+69
-42
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-20
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+61
-22
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
08b83087
...
...
@@ -754,28 +754,16 @@ class PostgreSqlPlatform extends AbstractPlatform
return
parent
::
convertBooleansToDatabaseValue
(
$item
);
}
$item
=
$this
->
convertBooleans
(
$item
);
if
(
is_array
(
$item
))
{
foreach
(
$item
as
$key
=>
$value
)
{
if
(
is_bool
(
$value
)
||
is_numeric
(
$value
))
{
$item
[
$key
]
=
$value
?
1
:
0
;
}
elseif
(
is_string
(
$value
))
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
[
$key
]
=
0
;
}
else
{
$item
[
$key
]
=
1
;
}
}
}
$item
=
array_map
(
function
(
$element
)
{
return
(
int
)
(
'true'
===
$element
);
},
$item
);
}
else
{
if
(
is_bool
(
$item
)
||
is_numeric
(
$item
))
{
$item
=
$item
?
1
:
0
;
}
elseif
(
is_string
(
$item
))
{
if
(
in_array
(
trim
(
strtolower
(
$item
)),
$this
->
booleanLiterals
[
'false'
]))
{
$item
=
0
;
}
else
{
$item
=
1
;
}
}
$item
=
(
int
)
(
'true'
===
$item
);
}
return
$item
;
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
08b83087
...
...
@@ -290,27 +290,13 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
/**
* @group DBAL-457
* @dataProvider pgStringBooleanProvider
*/
public
function
testConvertBooleanAsLiteralStrings
()
public
function
testConvertBooleanAsLiteralStrings
(
$expected
,
$input
)
{
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
't'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'true'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'y'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'yes'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'on'
));
$this
->
assertEquals
(
'true'
,
$platform
->
convertBooleans
(
'1'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
false
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'f'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'false'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'n'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'no'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'off'
));
$this
->
assertEquals
(
'false'
,
$platform
->
convertBooleans
(
'0'
));
$this
->
assertEquals
(
$expected
,
$platform
->
convertBooleans
(
$input
));
}
/**
...
...
@@ -321,19 +307,22 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$platform
=
$this
->
createPlatform
();
$platform
->
setUseBooleanTrueFalseStrings
(
false
);
$this
->
assertEquals
(
'1'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'0'
,
$platform
->
convertBooleans
(
false
));
$this
->
assertEquals
(
1
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
1
,
$platform
->
convertBooleans
(
'1'
));
$this
->
assertEquals
(
0
,
$platform
->
convertBooleans
(
false
));
$this
->
assertEquals
(
0
,
$platform
->
convertBooleans
(
'0'
));
}
/**
* @group DBAL-630
* @dataProvider pgStringBooleanDatabaseValueProvider
*/
public
function
testConvertBooleanAsDatabaseValueStrings
()
public
function
testConvertBooleanAsDatabaseValueStrings
(
$expected
,
$input
)
{
$platform
=
$this
->
createPlatform
();
$this
->
assertEquals
(
1
,
$platform
->
convertBooleansToDatabaseValue
(
true
));
$this
->
assertEquals
(
0
,
$platform
->
convertBooleansToDatabaseValue
(
false
));
$this
->
assertEquals
(
$expected
,
$platform
->
convertBooleansToDatabaseValue
(
$input
));
}
/**
...
...
@@ -588,6 +577,56 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
);
}
/**
* PostgreSQL boolean strings provider
* @return array
*/
public
function
pgStringBooleanProvider
()
{
return
array
(
array
(
'true'
,
true
),
array
(
'true'
,
't'
),
array
(
'true'
,
'true'
),
array
(
'true'
,
'y'
),
array
(
'true'
,
'yes'
),
array
(
'true'
,
'on'
),
array
(
'true'
,
'1'
),
array
(
'false'
,
false
),
array
(
'false'
,
'f'
),
array
(
'false'
,
'false'
),
array
(
'false'
,
'n'
),
array
(
'false'
,
'no'
),
array
(
'false'
,
'off'
),
array
(
'false'
,
'0'
),
);
}
/**
* PostgreSQL boolean strings as database values provider
* @return array
*/
public
function
pgStringBooleanDatabaseValueProvider
()
{
return
array
(
array
(
1
,
true
),
array
(
1
,
't'
),
array
(
1
,
'true'
),
array
(
1
,
'y'
),
array
(
1
,
'yes'
),
array
(
1
,
'on'
),
array
(
1
,
'1'
),
array
(
0
,
false
),
array
(
0
,
'f'
),
array
(
0
,
'false'
),
array
(
0
,
'n'
),
array
(
0
,
'no'
),
array
(
0
,
'off'
),
array
(
0
,
'0'
),
);
}
/**
* {@inheritdoc}
*/
...
...
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