]> BookStack Code Mirror - bookstack/blob - tests/StatusTest.php
Applied StyleCI changes, added php/larastan to attribution
[bookstack] / tests / StatusTest.php
1 <?php
2
3 use Illuminate\Cache\ArrayStore;
4 use Illuminate\Support\Facades\Cache;
5 use Illuminate\Support\Facades\DB;
6 use Illuminate\Support\Facades\Session;
7 use Tests\TestCase;
8
9 class StatusTest extends TestCase
10 {
11     public function test_returns_json_with_expected_results()
12     {
13         $resp = $this->get('/status');
14         $resp->assertStatus(200);
15         $resp->assertJson([
16             'database' => true,
17             'cache'    => true,
18             'session'  => true,
19         ]);
20     }
21
22     public function test_returns_500_status_and_false_on_db_error()
23     {
24         DB::shouldReceive('table')->andThrow(new Exception());
25
26         $resp = $this->get('/status');
27         $resp->assertStatus(500);
28         $resp->assertJson([
29             'database' => false,
30         ]);
31     }
32
33     public function test_returns_500_status_and_false_on_wrong_cache_return()
34     {
35         $mockStore = Mockery::mock(new ArrayStore())->makePartial();
36         Cache::swap($mockStore);
37         $mockStore->shouldReceive('pull')->andReturn('cat');
38
39         $resp = $this->get('/status');
40         $resp->assertStatus(500);
41         $resp->assertJson([
42             'cache' => false,
43         ]);
44     }
45
46     public function test_returns_500_status_and_false_on_wrong_session_return()
47     {
48         $session = Session::getFacadeRoot();
49         $mockSession = Mockery::mock($session)->makePartial();
50         Session::swap($mockSession);
51         $mockSession->shouldReceive('get')->andReturn('cat');
52
53         $resp = $this->get('/status');
54         $resp->assertStatus(500);
55         $resp->assertJson([
56             'session' => false,
57         ]);
58     }
59 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.