| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 22:54:58 +08:00
										 |  |  | namespace Tests; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Exception; | 
					
						
							| 
									
										
										
										
											2021-01-29 07:13:55 +08:00
										 |  |  | use Illuminate\Cache\ArrayStore; | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  | use Illuminate\Support\Facades\Cache; | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | use Illuminate\Support\Facades\DB; | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  | use Illuminate\Support\Facades\Session; | 
					
						
							| 
									
										
										
										
											2021-12-10 22:54:58 +08:00
										 |  |  | use Mockery; | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class StatusTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function test_returns_json_with_expected_results() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $resp = $this->get('/status'); | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  |         $resp->assertStatus(200); | 
					
						
							|  |  |  |         $resp->assertJson([ | 
					
						
							|  |  |  |             'database' => true, | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'cache'    => true, | 
					
						
							|  |  |  |             'session'  => true, | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_returns_500_status_and_false_on_db_error() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DB::shouldReceive('table')->andThrow(new Exception()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $resp = $this->get('/status'); | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  |         $resp->assertStatus(500); | 
					
						
							|  |  |  |         $resp->assertJson([ | 
					
						
							|  |  |  |             'database' => false, | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_returns_500_status_and_false_on_wrong_cache_return() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-01-29 07:13:55 +08:00
										 |  |  |         $mockStore = Mockery::mock(new ArrayStore())->makePartial(); | 
					
						
							|  |  |  |         Cache::swap($mockStore); | 
					
						
							| 
									
										
										
										
											2021-11-06 00:18:06 +08:00
										 |  |  |         $mockStore->shouldReceive('pull')->andReturn('cat'); | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $resp = $this->get('/status'); | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  |         $resp->assertStatus(500); | 
					
						
							|  |  |  |         $resp->assertJson([ | 
					
						
							|  |  |  |             'cache' => false, | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_returns_500_status_and_false_on_wrong_session_return() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $session = Session::getFacadeRoot(); | 
					
						
							|  |  |  |         $mockSession = Mockery::mock($session)->makePartial(); | 
					
						
							|  |  |  |         Session::swap($mockSession); | 
					
						
							|  |  |  |         $mockSession->shouldReceive('get')->andReturn('cat'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |         $resp = $this->get('/status'); | 
					
						
							| 
									
										
										
										
											2021-01-17 21:21:57 +08:00
										 |  |  |         $resp->assertStatus(500); | 
					
						
							|  |  |  |         $resp->assertJson([ | 
					
						
							|  |  |  |             'session' => false, | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | } |