Skip to content

Commit

Permalink
Fix PostgreSQL boolean handling for PHP 8.0.5 (#870)
Browse files Browse the repository at this point in the history
* Fix PostgreSQL boolean handling for PHP 8.0.5

* remove "processUncoveredFiles" from phpunit
  • Loading branch information
mvorisek authored May 5, 2021
1 parent 50c6361 commit 495f9bc
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
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

0 comments on commit 495f9bc

Please sign in to comment.