Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

## Added

- It is now possible to use an empty array when using `Sign::in` in a specification

## 5.2.0 - 2026-05-14

### Changed
Expand Down
21 changes: 21 additions & 0 deletions proofs/query/where.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,25 @@ static function($assert) {
static fn() => null,
));
});

yield $prove
->proof('Where condition with no values for an "in" sign will match nothing')
->given(
Column::any(),
)
->test(static function($assert, $column) {
$specification = Property::of(
$column->name()->toString(),
Sign::in,
[],
);
$where = Where::of($specification);

[$sql, $parameters] = $where->normalize(Driver::mysql);
$assert->same(
"WHERE {$column->name()->sql(Driver::mysql)} IN (SELECT NULL WHERE false)",
$sql,
);
$assert->same(0, $parameters->size());
});
};
1 change: 1 addition & 0 deletions properties/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static function list(): array
Connection\SelectWhereEndsWith::class,
Connection\SelectWhereContains::class,
Connection\SelectWhereIn::class,
Connection\SelectWhereInNothing::class,
Connection\SelectWhereInQuery::class,
Connection\SelectOffset::class,
Connection\SelectLimit::class,
Expand Down
78 changes: 78 additions & 0 deletions properties/Connection/SelectWhereInNothing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
declare(strict_types = 1);

namespace Properties\Formal\AccessLayer\Connection;

use Formal\AccessLayer\{
Query\Insert,
Query\Select,
Table\Name,
Row,
Connection,
};
use Innmind\Specification\{
Comparator,
Sign,
};
use Innmind\BlackBox\{
Property,
Set,
Runner\Assert,
};

/**
* @implements Property<Connection>
*/
final class SelectWhereInNothing implements Property
{
private string $uuid;
private string $username;
private int $number;

public function __construct(string $uuid, string $username, int $number)
{
$this->uuid = $uuid;
$this->username = $username;
$this->number = $number;
}

public static function any(): Set
{
return Set::compose(
static fn(...$args) => new self(...$args),
Set::uuid(),
Set::strings()
->madeOf(Set::strings()->chars()->ascii())
->between(0, 255),
Set::integers(),
);
}

public function applicableTo(object $connection): bool
{
return true;
}

public function ensureHeldBy(Assert $assert, object $connection): object
{
$_ = $connection(Insert::into(
Name::of('test'),
Row::of([
'id' => $this->uuid,
'username' => $this->username,
'registerNumber' => $this->number,
]),
));

$select = Select::from(Name::of('test'))->where(Comparator\Property::of(
'test.id',
Sign::in,
[],
));
$rows = $connection($select);

$assert->same(0, $rows->size());

return $connection;
}
}
5 changes: 4 additions & 1 deletion src/Query/Where.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ private function buildInSql(
return \sprintf(
'%s IN (%s)',
$this->buildColumn($driver, $specification),
\implode(', ', $placeholders),
match ($placeholders) {
[] => 'SELECT NULL WHERE false',
default => \implode(', ', $placeholders),
},
);
}

Expand Down
Loading