Skip to content

Commit

Permalink
refactor: remove 'without-model' method to maintain compatibility wit…
Browse files Browse the repository at this point in the history
…h newer versions of PHPUnit
  • Loading branch information
mostafaznv committed Mar 3, 2024
1 parent 96b6f8e commit e9173e1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tests/Feature/QueueCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@
use Mostafaznv\LaraCache\Jobs\RefreshCache;
use Mostafaznv\LaraCache\Jobs\UpdateLaraCacheModelsList;
use Mostafaznv\LaraCache\Tests\TestSupport\TestModels\QueueTestModel;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;

beforeEach(function() {
Bus::fake([
UpdateLaraCacheModelsList::class
]);

if (!Str::contains($this->getName(), '[without-model]')) {
createQueueModel();
}
});

it('will initiate cache object with CREATING status', function() {
createQueueModel();

$cache = QueueTestModel::cache()->get('latest', true);
$isCreating = $cache->status->equals(CacheStatus::CREATING());

expect($isCreating)->toBeTrue();
});

it('will initiate cache object with entity default value', function() {
createQueueModel();

$cache = QueueTestModel::cache()->get('latest', true);

expect($cache->value)->toBe(-1);
});

it('will initiate cache object with properly expiration ttl', function() {
createQueueModel();

$cache = QueueTestModel::cache()->get('latest', true);

expect(is_null($cache->expiration))->toBeFalse();
});

it('will dispatch refresh-cache [without-model]', function() {
it('will dispatch refresh-cache', function() {
Queue::fake();
createQueueModel();

Expand All @@ -49,6 +50,7 @@
});

it('will create cache after processing queue', function() {
createQueueModel();
$before = now();

$model = createQueueModel();
Expand All @@ -64,7 +66,7 @@
->and($isCreated)->toBeTrue();
});

it('will return default value and dispatch cache creation job on retrieving entity [without-model]', function() {
it('will return default value and dispatch cache creation job on retrieving entity', function() {
Queue::fake();
DB::table('test_models')
->insert([
Expand All @@ -84,7 +86,7 @@
Queue::assertPushedOn($onQueue, RefreshCache::class);
});

it('will create cache in background on retrieving entity [without-model]', function() {
it('will create cache in background on retrieving entity', function() {
$name = 'queue-test-name';
$before = now();

Expand Down Expand Up @@ -113,7 +115,7 @@
->and($isCreated)->toBeTrue();
});

it('will change cache status to creating on model update [without-model]', function() {
it('will change cache status to creating on model update', function() {
$model = createQueueModel();

$cache = QueueTestModel::cache()->get('latest', true);
Expand Down Expand Up @@ -145,7 +147,7 @@
->and($cache->value->name)->toBe('new name');
});

it('will return old cache until queue process of updating model is done [without-model]', function() {
it('will return old cache until queue process of updating model is done', function() {
$model = createQueueModel('old-name');

$cache = QueueTestModel::cache()->get('latest');
Expand Down

0 comments on commit e9173e1

Please sign in to comment.