-
Notifications
You must be signed in to change notification settings - Fork 11.3k
/
Copy pathFoundationCacheBasedMaintenanceModeTest.php
62 lines (46 loc) · 2.11 KB
/
FoundationCacheBasedMaintenanceModeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Illuminate\Tests\Foundation;
use Illuminate\Contracts\Cache\Factory;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Foundation\CacheBasedMaintenanceMode;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class FoundationCacheBasedMaintenanceModeTest extends TestCase
{
use MockeryPHPUnitIntegration;
public function test_it_determines_whether_maintenance_mode_is_active()
{
$cache = m::mock(Factory::class, Repository::class);
$cache->shouldReceive('store')->with('store-key')->andReturnSelf();
$manager = new CacheBasedMaintenanceMode($cache, 'store-key', 'key');
$cache->shouldReceive('has')->once()->with('key')->andReturnFalse();
$this->assertFalse($manager->active());
$cache->shouldReceive('has')->once()->with('key')->andReturnTrue();
$this->assertTrue($manager->active());
}
public function test_it_retrieves_payload_from_cache()
{
$cache = m::mock(Factory::class, Repository::class);
$cache->shouldReceive('store')->with('store-key')->andReturnSelf();
$manager = new CacheBasedMaintenanceMode($cache, 'store-key', 'key');
$cache->shouldReceive('get')->once()->with('key')->andReturn(['payload']);
$this->assertSame(['payload'], $manager->data());
}
public function test_it_stores_payload_in_cache()
{
$cache = m::spy(Factory::class, Repository::class);
$cache->shouldReceive('store')->with('store-key')->andReturnSelf();
$manager = new CacheBasedMaintenanceMode($cache, 'store-key', 'key');
$manager->activate(['payload']);
$cache->shouldHaveReceived('put')->once()->with('key', ['payload']);
}
public function test_it_removes_payload_from_cache()
{
$cache = m::spy(Factory::class, Repository::class);
$cache->shouldReceive('store')->with('store-key')->andReturnSelf();
$manager = new CacheBasedMaintenanceMode($cache, 'store-key', 'key');
$manager->deactivate();
$cache->shouldHaveReceived('forget')->once()->with('key');
}
}