Skip to content

Commit 62f31d7

Browse files
authored
Merge pull request #638 from flightphp/duplicated-slash-in-groups-support
Duplicated slash in groups support
2 parents 22570b9 + 92e5332 commit 62f31d7

File tree

8 files changed

+49
-42
lines changed

8 files changed

+49
-42
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ charset = utf-8
88

99
[*.md]
1010
indent_size = 2
11+
12+
[tests/views/*.php]
13+
insert_final_newline = false

flight/net/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Route
8787
*/
8888
public function __construct(string $pattern, $callback, array $methods, bool $pass, string $alias = '')
8989
{
90-
$this->pattern = $pattern;
90+
$this->pattern = str_replace('//', '/', $pattern);
9191
$this->callback = $callback;
9292
$this->methods = $methods;
9393
$this->pass = $pass;

tests/FlightTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ public function testStaticRouteGroup()
134134
Flight::start();
135135
}
136136

137+
public function testStaticNestedGroups(): void {
138+
Flight::group('/', static function (): void {
139+
Flight::group('/', static function (): void {
140+
Flight::route('GET /', static function (): void {
141+
echo "test";
142+
});
143+
});
144+
});
145+
146+
Flight::request()->url = '/';
147+
148+
$this->expectOutputString('test');
149+
Flight::start();
150+
}
151+
137152
public function testStaticRouteGet()
138153
{
139154

@@ -381,15 +396,11 @@ public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
381396
$html = <<<'html'
382397
<div>Hi</div>
383398
<div>Hi</div>
384-
385399
<input type="number" />
386-
387400
<input type="number" />
388-
389401
html;
390402

391-
// if windows replace \n with \r\n
392-
$html = str_replace(["\n", "\r\n"], PHP_EOL, $html);
403+
$html = str_replace(["\n", "\r"], '', $html);
393404

394405
$this->expectOutputString($html);
395406

tests/ViewTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,12 @@ public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
178178
$html = <<<'html'
179179
<div>Hi</div>
180180
<div>Hi</div>
181-
182181
<input type="number" />
183-
184182
<input type="number" />
185-
186183
html;
187184

188185
// if windows replace \n with \r\n
189-
$html = str_replace("\n", PHP_EOL, $html);
186+
$html = str_replace(["\n", "\r"], '', $html);
190187

191188
$this->expectOutputString($html);
192189

@@ -205,11 +202,9 @@ public function testKeepThePreviousStateOfDataSettedBySetMethod(): void
205202
$html = <<<'html'
206203
<div>qux</div>
207204
<div>bar</div>
208-
209205
html;
210206

211-
// if windows replace \n with \r\n
212-
$html = str_replace("\n", PHP_EOL, $html);
207+
$html = str_replace(["\n", "\r"], '', $html);
213208

214209
$this->expectOutputString($html);
215210

@@ -222,19 +217,15 @@ public static function renderDataProvider(): array
222217
$html1 = <<<'html'
223218
<div>Hi</div>
224219
<div></div>
225-
226220
html;
227221

228222
$html2 = <<<'html'
229-
230223
<input type="number" />
231-
232224
<input type="text" />
233-
234225
html;
235226

236-
$html1 = str_replace(["\n", "\r\n"], PHP_EOL, $html1);
237-
$html2 = str_replace(["\n", "\r\n"], PHP_EOL, $html2);
227+
$html1 = str_replace(["\n", "\r"], '', $html1);
228+
$html2 = str_replace(["\n", "\r"], '', $html2);
238229

239230
return [
240231
[

tests/commands/ControllerCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ public function tearDown(): void
4848

4949
protected function newApp(string $name, string $version = '')
5050
{
51-
$app = new Application($name, $version ?: '0.0.1', fn () => false);
51+
$app = @new Application($name, $version ?: '0.0.1', fn () => false);
5252

53-
return $app->io(new Interactor(static::$in, static::$ou));
53+
return @$app->io(new Interactor(static::$in, static::$ou));
5454
}
5555

5656
public function testConfigAppRootNotSet()
5757
{
5858
$app = $this->newApp('test', '0.0.1');
5959
$app->add(new ControllerCommand([]));
60-
$app->handle(['runway', 'make:controller', 'Test']);
60+
@$app->handle(['runway', 'make:controller', 'Test']);
6161

6262
$this->assertStringContainsString('app_root not set in .runway-config.json', file_get_contents(static::$ou));
6363
}

tests/commands/RouteCommandTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function tearDown(): void
5454

5555
protected function newApp(string $name, string $version = '')
5656
{
57-
$app = new Application($name, $version ?: '0.0.1', fn() => false);
57+
$app = @new Application($name, $version ?: '0.0.1', fn() => false);
5858

5959
return $app->io(new Interactor(static::$in, static::$ou));
6060
}
@@ -90,19 +90,19 @@ protected function removeColors(string $str): string
9090

9191
public function testConfigIndexRootNotSet()
9292
{
93-
$app = $this->newApp('test', '0.0.1');
93+
$app = @$this->newApp('test', '0.0.1');
9494
$app->add(new RouteCommand([]));
95-
$app->handle(['runway', 'routes']);
95+
@$app->handle(['runway', 'routes']);
9696

9797
$this->assertStringContainsString('index_root not set in .runway-config.json', file_get_contents(static::$ou));
9898
}
9999

100100
public function testGetRoutes()
101101
{
102-
$app = $this->newApp('test', '0.0.1');
102+
$app = @$this->newApp('test', '0.0.1');
103103
$this->createIndexFile();
104104
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
105-
$app->handle(['runway', 'routes']);
105+
@$app->handle(['runway', 'routes']);
106106

107107
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
108108
$expected = <<<'output'
@@ -125,16 +125,24 @@ public function testGetRoutes()
125125

126126
public function testGetPostRoute()
127127
{
128-
$app = $this->newApp('test', '0.0.1');
128+
$app = @$this->newApp('test', '0.0.1');
129129
$this->createIndexFile();
130130
$app->add(new RouteCommand(['index_root' => 'tests/commands/index.php']));
131-
$app->handle(['runway', 'routes', '--post']);
131+
@$app->handle(['runway', 'routes', '--post']);
132132

133133
$this->assertStringContainsString('Routes', file_get_contents(static::$ou));
134-
$this->assertStringContainsString('+---------+---------+-------+----------+------------+
135-
| Pattern | Methods | Alias | Streamed | Middleware |
136-
+---------+---------+-------+----------+------------+
137-
| /post | POST | | No | Closure |
138-
+---------+---------+-------+----------+------------+', $this->removeColors(file_get_contents(static::$ou)));
134+
135+
$expected = <<<'output'
136+
+---------+---------+-------+----------+------------+
137+
| Pattern | Methods | Alias | Streamed | Middleware |
138+
+---------+---------+-------+----------+------------+
139+
| /post | POST | | No | Closure |
140+
+---------+---------+-------+----------+------------+
141+
output;
142+
143+
$this->assertStringContainsString(
144+
$expected,
145+
$this->removeColors(file_get_contents(static::$ou))
146+
);
139147
}
140148
}

tests/views/input.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
<?php
2-
3-
$type ??= 'text';
4-
5-
?>
6-
7-
<input type="<?= $type ?>" />
1+
<input type="<?= $type ?? 'text' ?>" />

tests/views/myComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div><?= $prop ?></div>
1+
<div><?= $prop ?></div>

0 commit comments

Comments
 (0)