-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAllowToStartTwoQueriesInParallel.php
More file actions
73 lines (64 loc) · 1.79 KB
/
AllowToStartTwoQueriesInParallel.php
File metadata and controls
73 lines (64 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types = 1);
namespace Properties\Formal\AccessLayer\Connection;
use Formal\AccessLayer\{
Query\SQL,
Query\Insert,
Table\Name,
Row,
Connection,
};
use Innmind\BlackBox\{
Property,
Set,
Runner\Assert,
};
/**
* @implements Property<Connection>
*/
final class AllowToStartTwoQueriesInParallel implements Property
{
private string $uuid;
private string $name;
private int $number;
private function __construct(string $uuid, string $name, int $number)
{
$this->uuid = $uuid;
$this->name = $name;
$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, 125),
Set::integers(),
)->toSet();
}
public function applicableTo(object $connection): bool
{
return true;
}
public function ensureHeldBy(Assert $assert, object $connection): object
{
// Insert at least one value to make sure the any() call will always
// return true
$_ = $connection(Insert::into(
Name::of('test'),
Row::of([
'id' => $this->uuid,
'username' => $this->name,
'registerNumber' => $this->number,
]),
));
$result1 = $connection(SQL::of('SELECT * FROM test'));
$result2 = $connection(SQL::of('SELECT * FROM test'));
// by using any() we only do a partial iteration over the results
$assert->true($result1->any(static fn() => true));
$assert->true($result2->any(static fn() => true));
return $connection;
}
}