Skip to content

Commit 188d15a

Browse files
authored
Merge branch 'main' into refactor/cache
2 parents 0d026ad + f34ad57 commit 188d15a

File tree

122 files changed

+2124
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2124
-608
lines changed

.github/workflows/integration-tests.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
workflow_dispatch:
66
schedule:
77
- cron: '0 0 * * *'
8+
env:
9+
POSTGRES_USER: runner
10+
POSTGRES_PASSWORD: ''
11+
POSTGRES_DB: postgres
812

913
jobs:
1014
vitest:
@@ -28,7 +32,7 @@ jobs:
2832
uses: shivammathur/setup-php@v2
2933
with:
3034
php-version: ${{ matrix.php }}
31-
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, intl, ftp, zip
35+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql intl, ftp, zip
3236
coverage: pcov
3337

3438
- name: Setup Bun
@@ -60,6 +64,9 @@ jobs:
6064
stability:
6165
- prefer-stable
6266
- prefer-lowest
67+
exclude:
68+
- os: windows-latest
69+
database: postgres
6370

6471
name: "Run tests: PHP ${{ matrix.php }} - ${{ matrix.database }} - ${{ matrix.stability }} - ${{ matrix.os }}"
6572

@@ -94,7 +101,10 @@ jobs:
94101
uses: ankane/setup-postgres@v1
95102

96103
- name: Set database config - ${{ matrix.database }}
97-
run: php -r "file_exists('tests/Fixtures/Config/database.config.php') || copy('tests/Fixtures/Config/database.${{ matrix.database }}.php', 'tests/Fixtures/Config/database.config.php');"
104+
run: php -r "copy('tests/Fixtures/Config/database.${{ matrix.database }}.php', 'tests/Fixtures/Config/database.config.php');"
105+
106+
- name: Tempest about
107+
run: php ./tempest about
98108

99109
- name: List discovered locations
100110
run: php ./tempest discovery:status

packages/clock/src/Clock.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Psr\Clock\ClockInterface;
88
use Tempest\DateTime\DateTimeInterface;
99
use Tempest\DateTime\Duration;
10+
use Tempest\DateTime\Timestamp;
1011

1112
interface Clock
1213
{
@@ -21,14 +22,19 @@ public function now(): DateTimeInterface;
2122
public function toPsrClock(): ClockInterface;
2223

2324
/**
24-
* Returns the current timestamp in seconds.
25+
* Returns the current timestamp.
2526
*/
26-
public function timestamp(): int;
27+
public function timestamp(): Timestamp;
28+
29+
/**
30+
* Returns the current UNIX timestamp in seconds.
31+
*/
32+
public function seconds(): int;
2733

2834
/**
2935
* Returns the current timestamp in milliseconds.
3036
*/
31-
public function timestampMs(): int;
37+
public function milliseconds(): int;
3238

3339
/**
3440
* Sleeps for the given number of milliseconds.

packages/clock/src/GenericClock.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ public function now(): DateTimeInterface
2424
return DateTime::now();
2525
}
2626

27-
public function timestamp(): int
27+
public function timestamp(): Timestamp
28+
{
29+
return Timestamp::monotonic();
30+
}
31+
32+
public function seconds(): int
2833
{
2934
return Timestamp::monotonic()->getSeconds();
3035
}
3136

32-
public function timestampMs(): int
37+
public function milliseconds(): int
3338
{
3439
return Timestamp::monotonic()->getMilliseconds();
3540
}

packages/clock/src/MockClock.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ final class MockClock implements Clock
1717

1818
public function __construct(DateTimeImmutable|DateTimeInterface|string $now = 'now')
1919
{
20-
if ($now instanceof DateTimeImmutable) {
21-
$this->now = DateTime::fromTimestamp(
22-
Timestamp::fromParts($now->getTimestamp()),
23-
);
24-
} else {
25-
$this->now = DateTime::parse($now);
26-
}
20+
$this->setNow($now);
2721
}
2822

2923
public function toPsrClock(): ClockInterface
@@ -36,53 +30,61 @@ public function now(): DateTimeInterface
3630
return $this->now;
3731
}
3832

39-
public function setNow(DateTimeInterface|string $now): void
33+
/**
34+
* Globally sets the current time to the specified value.
35+
*/
36+
public function setNow(DateTimeImmutable|DateTimeInterface|string $now): void
4037
{
41-
if ($now instanceof DateTimeInterface) {
42-
$this->now = $now;
43-
} else {
44-
$this->now = DateTime::parse($now);
45-
}
38+
$this->now = DateTime::parse($now);
4639
}
4740

48-
public function timestamp(): int
41+
public function timestamp(): Timestamp
42+
{
43+
return $this->now->getTimestamp();
44+
}
45+
46+
public function seconds(): int
4947
{
5048
return $this->now->getTimestamp()->getSeconds();
5149
}
5250

53-
public function timestampMs(): int
51+
public function milliseconds(): int
5452
{
5553
return $this->now->getTimestamp()->getMilliseconds();
5654
}
5755

5856
public function sleep(int|Duration $milliseconds): void
5957
{
6058
if ($milliseconds instanceof Duration) {
61-
$this->addInterval($milliseconds);
59+
$this->plus($milliseconds);
6260
return;
6361
}
6462

6563
$this->now = $this->now->plusMilliseconds($milliseconds);
6664
}
6765

68-
public function addInterval(Duration $duration): void
66+
/**
67+
* Adds the given duration. Providing an integer value adds the corresponding seconds to the current time.
68+
*/
69+
public function plus(int|Duration $duration): void
6970
{
70-
$this->now = $this->now->plus($duration);
71-
}
71+
if (is_int($duration)) {
72+
$duration = Duration::seconds($duration);
73+
}
7274

73-
public function subInternal(Duration $duration): void
74-
{
75-
$this->now = $this->now->minus($duration);
75+
$this->now = $this->now->plus($duration);
7676
}
7777

78-
public function changeTime(int $seconds): void
78+
/**
79+
* Removes the given duration. Providing an integer value removes the corresponding seconds to the current time.
80+
*/
81+
public function minus(int|Duration $duration): void
7982
{
80-
if ($seconds < 0) {
81-
$seconds = abs($seconds);
82-
$this->now = $this->now->minusSeconds($seconds);
83-
} else {
84-
$this->now = $this->now->plusSeconds($seconds);
83+
if (is_int($duration)) {
84+
$duration = Duration::seconds($duration);
8585
}
86+
87+
$this->now = $this->now->minus($duration);
8688
}
8789

8890
public function dd(): void

packages/clock/src/PsrClock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public function __construct(
1313

1414
public function now(): DateTimeImmutable
1515
{
16-
return DateTimeImmutable::createFromTimestamp($this->clock->timestamp());
16+
return DateTimeImmutable::createFromTimestamp($this->clock->seconds());
1717
}
1818
}

packages/clock/tests/GenericClockTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_that_generic_clock_returns_the_current_date_time(): void
2929
public function test_that_generic_clock_returns_the_current_time(): void
3030
{
3131
$timeBefore = new DateTimeImmutable()->getTimestamp();
32-
$clockTime = new GenericClock()->timestamp();
32+
$clockTime = new GenericClock()->seconds();
3333
$timeAfter = new DateTimeImmutable()->getTimestamp();
3434

3535
$this->assertGreaterThanOrEqual($timeBefore, $clockTime);

packages/clock/tests/MockClockTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function test_mock_clock_returns_the_time_we_want(): void
4141
$time = DateTime::parse('2024-09-11 13:54:23');
4242
$clock = new MockClock($time);
4343

44-
$this->assertEquals($time->getTimestamp()->getSeconds(), $clock->timestamp());
44+
$this->assertEquals($time->getTimestamp()->getSeconds(), $clock->seconds());
4545
}
4646

4747
public function test_mock_clock_sleeps_time(): void
@@ -52,7 +52,7 @@ public function test_mock_clock_sleeps_time(): void
5252
$clock = new MockClock($oldTime);
5353
$clock->sleep(2_000);
5454

55-
$this->assertSame($expectedTime->getTimestamp()->getSeconds(), $clock->timestamp());
55+
$this->assertSame($expectedTime->getTimestamp()->getSeconds(), $clock->seconds());
5656
}
5757

5858
public function test_mock_clock_can_change_time(): void
@@ -62,14 +62,14 @@ public function test_mock_clock_can_change_time(): void
6262
$addedTime = DateTime::parse('2024-09-11 13:54:25');
6363
$clock = new MockClock($dateTime);
6464

65-
$clock->changeTime(-2);
65+
$clock->minus(2);
6666

6767
$this->assertEquals($subtractedTime, $clock->now());
68-
$this->assertEquals($subtractedTime->getTimestamp()->getSeconds(), $clock->timestamp());
68+
$this->assertEquals($subtractedTime->getTimestamp()->getSeconds(), $clock->seconds());
6969

70-
$clock->changeTime(4);
70+
$clock->plus(4);
7171

7272
$this->assertEquals($addedTime, $clock->now());
73-
$this->assertEquals($addedTime->getTimestamp()->getSeconds(), $clock->timestamp());
73+
$this->assertEquals($addedTime->getTimestamp()->getSeconds(), $clock->seconds());
7474
}
7575
}

packages/container/src/GenericContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(
3030
private ArrayIterator $singletons = new ArrayIterator(),
3131

3232
/** @var ArrayIterator<array-key, class-string> $initializers */
33-
private ArrayIterator $initializers = new ArrayIterator(),
33+
public ArrayIterator $initializers = new ArrayIterator(),
3434

3535
/** @var ArrayIterator<array-key, class-string> $dynamicInitializers */
3636
private ArrayIterator $dynamicInitializers = new ArrayIterator(),

packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(
3434
);
3535
}
3636

37-
public function execute(mixed ...$bindings): Id
37+
public function execute(mixed ...$bindings): ?Id
3838
{
3939
return $this->build()->execute(...$bindings);
4040
}

packages/database/src/Config/DatabaseDialect.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tempest\Database\Config;
66

7+
use PDOException;
8+
79
enum DatabaseDialect: string
810
{
911
case SQLITE = 'sqlite';
@@ -18,4 +20,13 @@ public function tableNotFoundCode(): string
1820
self::SQLITE => 'HY000',
1921
};
2022
}
23+
24+
public function isTableNotFoundError(PDOException $exception): bool
25+
{
26+
return match ($this) {
27+
self::MYSQL => $exception->getCode() === '42S02' && str_contains($exception->getMessage(), 'table'),
28+
self::SQLITE => $exception->getCode() === 'HY000' && str_contains($exception->getMessage(), 'table'),
29+
self::POSTGRESQL => $exception->getCode() === '42P01' && str_contains($exception->getMessage(), 'relation'),
30+
};
31+
}
2132
}

0 commit comments

Comments
 (0)