Skip to content
Draft
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
5 changes: 4 additions & 1 deletion src/Behavior/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ipl\Orm\Exception\ValueConversionException;
use ipl\Orm\Query;
use ipl\Sql\Adapter\Pgsql;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter\Condition;
use UnexpectedValueException;

Expand Down Expand Up @@ -44,7 +45,7 @@
*/
public function toDb($value, $key, $_)
{
if (! $this->isPostgres) {
if (! $this->isPostgres || $value instanceof Expression) {
return $value;
}

Expand Down Expand Up @@ -77,11 +78,13 @@
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
*/
$column = $condition->metaData()->get('columnName');
if ($column !== null && isset($this->properties[$column])) {

Check failure on line 81 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Possibly invalid array key type mixed.

Check failure on line 81 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Possibly invalid array key type mixed.

Check failure on line 81 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Possibly invalid array key type mixed.

Check failure on line 81 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Possibly invalid array key type mixed.
$value = $condition->metaData()->get('originalValue');

if ($this->isPostgres && is_resource($value)) {
throw new UnexpectedValueException(sprintf('Unexpected resource for %s', $column));
} elseif ($value instanceof Expression) {
return;

Check failure on line 87 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Method ipl\Orm\Behavior\Binary::rewriteCondition() should return ipl\Stdlib\Filter\Rule|null but empty return statement found.

Check failure on line 87 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Method ipl\Orm\Behavior\Binary::rewriteCondition() should return ipl\Stdlib\Filter\Rule|null but empty return statement found.

Check failure on line 87 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Method ipl\Orm\Behavior\Binary::rewriteCondition() should return ipl\Stdlib\Filter\Rule|null but empty return statement found.

Check failure on line 87 in src/Behavior/Binary.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Method ipl\Orm\Behavior\Binary::rewriteCondition() should return ipl\Stdlib\Filter\Rule|null but empty return statement found.
}

// ctype_xdigit expects strings.
Expand Down
22 changes: 22 additions & 0 deletions tests/Behavior/BinaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ipl\Orm\Exception\ValueConversionException;
use ipl\Orm\Query;
use ipl\Sql\Connection;
use ipl\Sql\Expression;
use ipl\Stdlib\Filter\Equal;
use UnexpectedValueException;

Expand Down Expand Up @@ -107,6 +108,27 @@ public function testRewriteConditionThrowsExceptionIfAdapterIsPostgreSQLAndValue
$this->behavior(true)->rewriteCondition($this->condition(fopen('php://temp', 'r')));
}

public function testPersistPropertyReturnsExpressionValuesAsIsIfAdapterIsPostgreSQL(): void
{
// Expression values (e.g. from relation filters) must not be hex-encoded but passed through as-is
$expression = new Expression('NOW()');

$this->assertSame(
$expression,
$this->behavior(true)->persistProperty($expression, static::TEST_COLUMN)
);
}

public function testRewriteConditionLeavesExpressionValuesUnchanged(): void
{
$expression = new Expression('other_column');
$condition = $this->condition($expression);

$this->behavior(true)->rewriteCondition($condition);

$this->assertSame($expression, $condition->getValue());
}

protected function behavior(bool $postgres = false): Binary
{
return (new Binary([static::TEST_COLUMN]))
Expand Down
Loading