-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.7] Clean up cache integration tests (#25545)
* Split cache lock tests for Memcached and Redis The previous setup incorrectly skipped even the Redis tests when the Memcached extension was not installed. By separating them, we can also separate the logic for skipping these tests. * Redis cache lock tests: Use normal setup() and tearDown() * Memcached cache lock tests: Test for PHP extension, not class * Memcached cache lock tests: Also skip if no connection can be established
- Loading branch information
1 parent
f12df3e
commit bdd0113
Showing
2 changed files
with
70 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Cache; | ||
|
||
use Illuminate\Support\Carbon; | ||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class RedisCacheLockTest extends TestCase | ||
{ | ||
use InteractsWithRedis; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpRedis(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->tearDownRedis(); | ||
} | ||
|
||
public function test_redis_locks_can_be_acquired_and_released() | ||
{ | ||
Cache::store('redis')->lock('foo')->release(); | ||
$this->assertTrue(Cache::store('redis')->lock('foo', 10)->get()); | ||
$this->assertFalse(Cache::store('redis')->lock('foo', 10)->get()); | ||
Cache::store('redis')->lock('foo')->release(); | ||
$this->assertTrue(Cache::store('redis')->lock('foo', 10)->get()); | ||
$this->assertFalse(Cache::store('redis')->lock('foo', 10)->get()); | ||
Cache::store('redis')->lock('foo')->release(); | ||
} | ||
|
||
public function test_redis_locks_can_block_for_seconds() | ||
{ | ||
Carbon::setTestNow(); | ||
|
||
Cache::store('redis')->lock('foo')->release(); | ||
$this->assertEquals('taylor', Cache::store('redis')->lock('foo', 10)->block(1, function () { | ||
return 'taylor'; | ||
})); | ||
|
||
Cache::store('redis')->lock('foo')->release(); | ||
$this->assertTrue(Cache::store('redis')->lock('foo', 10)->block(1)); | ||
} | ||
} |