Skip to content

Commit d96b9d5

Browse files
authored
Merge branch 'main' into feat/phar-compatible
2 parents 4abf33b + 1602654 commit d96b9d5

File tree

18 files changed

+277
-19
lines changed

18 files changed

+277
-19
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Integration Tests (Windows)
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 8 * * *'
7+
env:
8+
POSTGRES_USER: runner
9+
POSTGRES_PASSWORD: ""
10+
POSTGRES_DB: postgres
11+
12+
jobs:
13+
vitest:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php:
19+
- 8.4
20+
os:
21+
- windows-latest
22+
env:
23+
POSTGRES_USER: ${{ matrix.os == 'windows-latest' && 'postgres' || 'runner' }}
24+
25+
name: "Run tests: ${{ matrix.os }}"
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php }}
35+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql, intl, ftp, zip
36+
coverage: pcov
37+
38+
- name: Setup Bun
39+
uses: oven-sh/setup-bun@v2
40+
41+
- name: Install dependencies
42+
run: bun install --frozen-lockfile
43+
44+
- name: Run build
45+
run: bun run build
46+
47+
- name: Run tests
48+
run: bun run test
49+
50+
phpunit:
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
os:
56+
- windows-latest
57+
php:
58+
- 8.4
59+
database:
60+
- sqlite
61+
- mysql
62+
- postgres
63+
stability:
64+
- prefer-stable
65+
env:
66+
POSTGRES_USER: ${{ matrix.os == 'windows-latest' && 'postgres' || 'runner' }}
67+
68+
name: "Run tests: PHP ${{ matrix.php }} - ${{ matrix.database }} - ${{ matrix.stability }} - ${{ matrix.os }}"
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
74+
- name: Setup PHP
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: ${{ matrix.php }}
78+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql, intl, ftp, zip
79+
coverage: pcov
80+
81+
- name: Setup problem matchers
82+
run: |
83+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
84+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
85+
86+
- name: Install dependencies
87+
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
88+
89+
- name: "Setup Redis"
90+
if: ${{ matrix.os != 'windows-latest' }}
91+
uses: supercharge/[email protected]
92+
93+
- name: "Setup MySQL"
94+
if: ${{ matrix.database == 'mysql' }}
95+
uses: ankane/setup-mysql@v1
96+
with:
97+
mysql-version: 8.0
98+
database: "app"
99+
100+
- name: "Setup PostgreSQL"
101+
if: ${{ matrix.database == 'postgres' }}
102+
uses: ankane/setup-postgres@v1
103+
104+
- name: Set database config - ${{ matrix.database }}
105+
run: php -r "copy('tests/Fixtures/Config/database.${{ matrix.database }}.php', 'tests/Fixtures/Config/database.config.php');"
106+
107+
- name: Tempest about
108+
run: php ./tempest about -v
109+
110+
- name: List discovered locations
111+
run: php ./tempest discovery:status
112+
113+
- name: Execute tests
114+
run: php -d"error_reporting = E_ALL & ~E_DEPRECATED" -dmemory_limit=1G vendor/bin/phpunit

.github/workflows/integration-tests.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- 8.4
2424
os:
2525
- ubuntu-latest
26-
- windows-latest
26+
# - windows-latest
2727

2828
name: "Run tests: ${{ matrix.os }}"
2929

@@ -35,7 +35,7 @@ jobs:
3535
uses: shivammathur/setup-php@v2
3636
with:
3737
php-version: ${{ matrix.php }}
38-
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql intl, ftp, zip
38+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql, intl, ftp, zip
3939
coverage: pcov
4040

4141
- name: Setup Bun
@@ -57,7 +57,7 @@ jobs:
5757
matrix:
5858
os:
5959
- ubuntu-latest
60-
- windows-latest
60+
# - windows-latest
6161
php:
6262
- 8.4
6363
database:
@@ -67,9 +67,9 @@ jobs:
6767
stability:
6868
- prefer-stable
6969
- prefer-lowest
70-
exclude:
71-
- os: windows-latest
72-
database: postgres
70+
# exclude:
71+
# - os: windows-latest
72+
# database: postgres
7373

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

@@ -81,7 +81,7 @@ jobs:
8181
uses: shivammathur/setup-php@v2
8282
with:
8383
php-version: ${{ matrix.php }}
84-
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, intl, ftp, zip
84+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, pdo_pgsql, intl, ftp, zip
8585
coverage: pcov
8686

8787
- name: Setup problem matchers

docs/1-essentials/02-views.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Apart from HTMLs boolean attributes, the same syntax can be used with any expres
177177

178178
### Control flow directives
179179

180-
#### `:if`, `:elseif` and `:else`
180+
#### `:if`, `:elseif`, and `:else`
181181

182182
The `:if` directive can conditionally render the element it is attached to, depending on the result of its expression. Similarly, the `:elseif` and `:else` directives can be used on direct siblings for additional control.
183183

@@ -186,6 +186,21 @@ The `:if` directive can conditionally render the element it is attached to, depe
186186
<span :else>Import {{ $this->pendingUploads->count() }} file(s)</span>
187187
```
188188

189+
#### `:isset`
190+
191+
The `:isset` directive can be used to conditionally render the element it is attached to, depending on the existence of a variable.
192+
193+
```html
194+
<h1 :isset="$title">{{ $title }}</h1>
195+
```
196+
197+
Since `:isset` is a shorthand for `:if="isset()"`, it can be combined with `:elseif` and `:else`:
198+
199+
```html
200+
<h1 :isset="$title">{{ $title }}</h1>
201+
<h1 :else>Title</h1>
202+
```
203+
189204
#### `:foreach` and `:{:hl-keyword:forelse:}`
190205

191206
The `:foreach` directive may be used to render the associated element multiple times based on the result of its expression. Combined with `:{:hl-keyword:forelse:}`, an empty state can be displayed when the data is empty.
@@ -230,7 +245,7 @@ To create a view component, create a `.view.php` file that starts with `x-`. The
230245
```html app/x-base.view.php
231246
<html lang="en">
232247
<head>
233-
<title :if="$title">{{ $title }} — AirAcme</title>
248+
<title :if="$title ?? null">{{ $title }} — AirAcme</title>
234249
<title :else>AirAcme</title>
235250
</head>
236251
<body>
@@ -265,7 +280,7 @@ Attributes and [expression attributes](#expression-attributes) may be passed int
265280

266281
```html x-base.view.php
267282
// ...
268-
<title :if="$title">{{ $title }}</title>
283+
<title :if="$title ?? null">{{ $title }}</title>
269284
```
270285

271286
Note that the casing of attributes will affect the associated variable name:

docs/4-internals/03-view-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Some frontend frameworks also provide a `{html}:{:hl-property:attribute:}` synta
2727

2828
### Control structures
2929

30-
Control structures like conditionals and loops are modelled with expression attributes. These control structure attributes are available: `{html}:{:hl-property:if:}`, `{html}:{:hl-property:elseif:}`, `{html}:{:hl-property:else:}`, `{html}:{:hl-property:foreach:}`, `{html}:{:hl-property:forelse:}`. Code within these control structures is compiled to valid PHP expressions.
30+
Control structures like conditionals and loops are modelled with expression attributes. These control structure attributes are available: `{html}:{:hl-property:if:}`, `{html}:{:hl-property:elseif:}`, `{html}:{:hl-property:else:}`, {:hl-property:isset:}`, `{html}:{:hl-property:foreach:}`, `{html}:{:hl-property:forelse:}`. Code within these control structures is compiled to valid PHP expressions.
3131

3232
The following conditional:
3333

packages/event-bus/src/EventBusDiscovery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Tempest\Reflection\ClassReflector;
1111
use Tempest\Reflection\TypeReflector;
1212
use Tempest\Support\Str;
13+
use UnitEnum;
1314

1415
final class EventBusDiscovery implements Discovery
1516
{
@@ -30,6 +31,10 @@ public function discover(DiscoveryLocation $location, ClassReflector $class): vo
3031

3132
$eventName = Str\parse($eventHandler->event, default: null);
3233

34+
if ($eventHandler->event instanceof UnitEnum) {
35+
$eventName = $eventHandler->event::class . '::' . $eventName;
36+
}
37+
3338
if ($eventName === null) {
3439
$parameters = iterator_to_array($method->getParameters());
3540

packages/event-bus/src/GenericEventBus.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Closure;
88
use Tempest\Container\Container;
99
use Tempest\Support\Str;
10+
use UnitEnum;
1011

1112
final readonly class GenericEventBus implements EventBus
1213
{
@@ -33,6 +34,11 @@ public function dispatch(string|object $event): void
3334
private function resolveHandlers(string|object $event): array
3435
{
3536
$eventName = Str\parse($event) ?: $event::class;
37+
38+
if ($event instanceof UnitEnum) {
39+
$eventName = $event::class . '::' . $eventName;
40+
}
41+
3642
$handlers = $this->eventBusConfig->handlers[$eventName] ?? [];
3743

3844
if (is_object($event)) {

packages/http-client/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"tempest/container": "dev-main",
1111
"tempest/http": "dev-main",
1212
"tempest/router": "dev-main",
13-
"psr-discovery/http-factory-implementations": "^1.4",
14-
"psr-discovery/http-client-implementations": "^1.2"
13+
"psr-discovery/http-client-implementations": "^1.4",
14+
"psr-discovery/http-factory-implementations": "^1.2"
1515
},
1616
"require-dev": {
1717
"guzzlehttp/psr7": "^2.6.1",

packages/upgrade/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"minimum-stability": "dev",
66
"require": {
77
"php": "^8.4",
8-
"rector/rector": "2.2.1"
8+
"rector/rector": "^2.1"
99
},
1010
"autoload": {
1111
"psr-4": {

packages/view/src/Attributes/AttributeFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function make(string $attributeName): Attribute
1212
{
1313
return match (true) {
1414
$attributeName === ':if' => new IfAttribute(),
15+
$attributeName === ':isset' => new IssetAttribute(),
1516
$attributeName === ':elseif' => new ElseIfAttribute(),
1617
$attributeName === ':else' => new ElseAttribute(),
1718
$attributeName === ':foreach' => new ForeachAttribute(),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\View\Attributes;
6+
7+
use Tempest\View\Attribute;
8+
use Tempest\View\Element;
9+
use Tempest\View\Elements\PhpIfElement;
10+
11+
final readonly class IssetAttribute implements Attribute
12+
{
13+
public function apply(Element $element): Element
14+
{
15+
return new PhpIfElement($element);
16+
}
17+
}

0 commit comments

Comments
 (0)