Commit c5351a9 1 parent 989dcbd commit c5351a9 Copy full SHA for c5351a9
File tree 4 files changed +66
-0
lines changed
4 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -262,3 +262,20 @@ function config()
262
262
return new System \Collection \CollectionImmutable (app ()->get ('config ' ));
263
263
}
264
264
}
265
+
266
+ if (!function_exists ('view ' )) {
267
+ /**
268
+ * Render with costume template engine, wrap in `Route\Controller`.
269
+ */
270
+ function view (string $ view_path , array $ data = [], array $ option = []): System \Http \Response
271
+ {
272
+ /** @var System\Http\Response */
273
+ $ view = app ()->get ('view.response ' );
274
+ $ status_code = $ option ['status ' ] ?? 200 ;
275
+ $ headers = $ option ['header ' ] ?? [];
276
+
277
+ return $ view ($ view_path , $ data )
278
+ ->setResponeCode ($ status_code )
279
+ ->setHeaders ($ headers );
280
+ }
281
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace System \Test \Integrate \Helper ;
6
+
7
+ use PHPUnit \Framework \TestCase ;
8
+ use System \Http \Response ;
9
+ use System \Integrate \Application ;
10
+ use System \Text \Str ;
11
+ use System \View \Templator ;
12
+
13
+ final class ViewTest extends TestCase
14
+ {
15
+ public function testItCanGetResponeFromeContainer ()
16
+ {
17
+ $ app = new Application ('/ ' );
18
+
19
+ $ app ->set (
20
+ 'view.response ' ,
21
+ fn () => fn (string $ view_path , array $ portal = []): Response => (new Response ())
22
+ ->setContent (
23
+ (new Templator (__DIR__ . '/assets/view/ ' , __DIR__ . '/assets/cache ' ))
24
+ ->render ($ view_path , $ portal )
25
+ )
26
+ );
27
+
28
+ $ view = view ('test.php ' , [], ['status ' => 500 ]);
29
+ $ this ->assertEquals (500 , $ view ->getStatusCode ());
30
+ $ this ->assertTrue (
31
+ Str::contains ($ view ->getContent (), 'savanna ' )
32
+ );
33
+
34
+ $ app ->flush ();
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ * .php
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <html lang =" en" >
3
+ <head >
4
+ <meta charset = " UTF-8" >
5
+ <meta http-equiv = " X-UA-Compatible" content = " IE=edge" >
6
+ <meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
7
+ <title >Document</title >
8
+ </head >
9
+ <body >
10
+ <p >savanna</p >
11
+ </body >
12
+ </html >
You can’t perform that action at this time.
0 commit comments