Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PostgreSQL boolean handling for PHP 8.0.5 #870

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit-mssql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">src-schema</directory>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-mysql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">src-schema</directory>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-oracle.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">src-schema</directory>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-pgsql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">src-schema</directory>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<directory suffix=".php">src-schema</directory>
Expand Down
19 changes: 16 additions & 3 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,25 @@ public function toQueryArguments(): array

foreach (array_reverse($refModels) as $refModel) {
if ($field === '#') {
$field = $value ? $refModel->action('count') : $refModel->action('exists');
if (is_string($value) && $value === (string) (int) $value) {
$value = (int) $value;
}

if ($value === 0) {
$field = $refModel->action('exists');
$value = false;
} elseif ($value === 1 && $operator === self::OPERATOR_GREATER_EQUAL) {
$field = $refModel->action('exists');
$operator = self::OPERATOR_EQUALS;
$value = true;
} else {
$field = $refModel->action('count');
}
} else {
$refModel->addCondition($field, $operator, $value);
$field = $refModel->action('exists');
$operator = '>';
$value = 0;
$operator = self::OPERATOR_EQUALS;
$value = true;
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public function _typecastSaveField(Field $field, $value)

switch ($field->type) {
case 'boolean':
// if enum is not set, then simply cast value to integer
// if enum is not set, then simply cast value to boolean
if (!isset($field->enum) || !$field->enum) {
$v = (int) $v;
$v = (bool) $v;

break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PersistentArrayOfStringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testTypecasting()
'integer' => 123,
'money' => 123.45,
'float' => 123.456789,
'boolean' => 1,
'boolean' => true,
'boolean_enum' => 'N',
'date' => '2019-01-20',
'datetime' => '2019-01-20 12:23:34.000000',
Expand Down