@@ -13,42 +13,38 @@ class ApplicationTest extends TestCase
13
13
14
14
public function testMake ()
15
15
{
16
- $ application = Application:: make ( ' laravel ' , $ this ->basePath . ' /laravel ' );
16
+ $ application = $ this ->makeApplication ( );
17
17
18
18
$ this ->assertInstanceOf (Application::class, $ application );
19
19
}
20
20
21
- public function testRunLaravel ()
21
+ public function testMakeInvalidFramework ()
22
22
{
23
- $ application = Application::make ('laravel ' , $ this ->basePath . '/laravel ' );
24
- $ response = $ application ->run (Request::create ('/ ' ));
23
+ $ this ->expectException (\Exception::class);
25
24
26
- $ this ->assertInstanceOf (Response::class, $ response );
27
- $ this ->assertSame ('welcome ' , $ response ->getContent ());
25
+ $ this ->makeApplication ('other ' );
28
26
}
29
27
30
- public function testRunLumen ()
28
+ public function testRun ()
31
29
{
32
- $ application = Application:: make ( ' lumen ' , $ this ->basePath . ' /lumen ' );
30
+ $ application = $ this ->makeApplication ( );
33
31
$ response = $ application ->run (Request::create ('/ ' ));
34
32
35
33
$ this ->assertInstanceOf (Response::class, $ response );
36
- $ this ->assertSame ('hello ' , $ response ->getContent ());
37
- }
38
-
39
- public function testRunOther ()
40
- {
41
- $ this ->expectException (\Exception::class);
42
-
43
- $ application = Application::make ('other ' , $ this ->basePath . '/laravel ' );
44
- $ application ->run (Request::create ('/ ' ));
34
+ $ this ->assertSame ('welcome ' , $ response ->getContent ());
45
35
}
46
36
47
37
public function testTerminate ()
48
38
{
49
39
$ flag = false ;
50
40
51
- $ application = Application::make ('laravel ' , $ this ->basePath . '/laravel ' );
41
+ if (class_exists ('\Laravel\Lumen\Application ' )) {
42
+ $ this ->assertTrue (true );
43
+
44
+ return ;
45
+ }
46
+
47
+ $ application = $ this ->makeApplication ();
52
48
$ request = Request::create ('/ ' );
53
49
$ response = $ application ->run ($ request );
54
50
@@ -60,4 +56,40 @@ public function testTerminate()
60
56
61
57
$ this ->assertTrue ($ flag );
62
58
}
59
+
60
+ public function testResetProvider ()
61
+ {
62
+ $ application = $ this ->makeApplication ();
63
+ $ response = $ application ->run (Request::create ('/ ' ));
64
+
65
+ $ app = $ application ->getApplication ();
66
+
67
+ $ this ->assertSame ('bar ' , $ app ['singleton.test ' ]->foo );
68
+
69
+ $ app ->singleton ('singleton.test ' , function () {
70
+ $ obj = new \stdClass ;
71
+ $ obj ->foo = 'foo ' ;
72
+
73
+ return $ obj ;
74
+ });
75
+ $ this ->assertSame ('foo ' , $ app ['singleton.test ' ]->foo );
76
+
77
+ $ response = $ application ->resetProviders ();
78
+ $ this ->assertSame ('bar ' , $ app ['singleton.test ' ]->foo );
79
+ }
80
+
81
+ protected function makeApplication ($ forceFramework = null )
82
+ {
83
+ if (! is_null ($ forceFramework )) {
84
+ $ framework = $ forceFramework ;
85
+ } elseif (class_exists ('\Illuminate\Foundation\Application ' )) {
86
+ $ framework = 'laravel ' ;
87
+ } elseif (class_exists ('\Laravel\Lumen\Application ' )) {
88
+ $ framework = 'lumen ' ;
89
+ } else {
90
+ $ framework = 'other ' ;
91
+ }
92
+
93
+ return Application::make ($ framework , $ this ->basePath . '/ ' . $ framework );
94
+ }
63
95
}
0 commit comments