Skip to content

Commit

Permalink
Assert events are being fired
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljennings committed Aug 6, 2018
1 parent 71265f5 commit 5c13fee
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/BrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Michaeljennings\Broker\Tests;

use Illuminate\Support\Facades\Event;
use Michaeljennings\Broker\Events\CacheableFlushed;
use Michaeljennings\Broker\Events\CacheableKeyForgotten;
use Michaeljennings\Broker\Events\CacheableKeyWritten;
use Michaeljennings\Broker\Tests\Fixtures\TestModel;

class BrokerTest extends TestCase
Expand All @@ -11,37 +15,49 @@ class BrokerTest extends TestCase
*/
public function it_stores_an_item_in_the_cache()
{
Event::fake();

$cacheable = new TestModel(['id' => 1]);

$this->makeBroker()->put($cacheable, 'foo', 'bar', 60);

$this->assertEquals($this->app->make('cache')->tags([$cacheable->getCacheKey(), $cacheable->id])->get('foo'), 'bar');

Event::assertDispatched(CacheableKeyWritten::class);
}

/**
* @test
*/
public function it_stores_an_item_in_the_cache_forever()
{
Event::fake();

$cacheable = new TestModel(['id' => 1]);

$this->makeBroker()->forever($cacheable, 'foo', 'bar');

$this->assertEquals($this->app->make('cache')->tags([$cacheable->getCacheKey(), $cacheable->id])->get('foo'), 'bar');

Event::assertDispatched(CacheableKeyWritten::class);
}

/**
* @test
*/
public function it_stores_an_item_in_the_cache_using_a_callback()
{
Event::fake();

$cacheable = new TestModel(['id' => 1]);

$this->makeBroker()->remember($cacheable, 'foo', function() {
return 'bar';
});

$this->assertEquals($this->app->make('cache')->tags([$cacheable->getCacheKey(), $cacheable->id])->get('foo'), 'bar');

Event::assertDispatched(CacheableKeyWritten::class);
}

/**
Expand Down Expand Up @@ -77,6 +93,8 @@ public function it_checks_if_an_item_is_in_the_cache()
*/
public function it_removes_an_item_from_the_cache()
{
Event::fake();

$broker = $this->makeBroker();
$cacheable = new TestModel(['id' => 1]);

Expand All @@ -87,13 +105,17 @@ public function it_removes_an_item_from_the_cache()
$broker->forget($cacheable, 'foo');

$this->assertNull($broker->get($cacheable, 'foo'));

Event::assertDispatched(CacheableKeyForgotten::class);
}

/**
* @test
*/
public function it_removes_multiple_items_from_the_cache()
{
Event::fake();

$broker = $this->makeBroker();
$cacheable = new TestModel(['id' => 1]);

Expand All @@ -107,13 +129,17 @@ public function it_removes_multiple_items_from_the_cache()

$this->assertNull($broker->get($cacheable, 'foo'));
$this->assertNull($broker->get($cacheable, 'baz'));

Event::assertDispatched(CacheableKeyForgotten::class);
}

/**
* @test
*/
public function it_fluses_all_of_the_keys_for_a_cacheable_entity()
{
Event::fake();

$broker = $this->makeBroker();
$cacheable = new TestModel(['id' => 1]);

Expand All @@ -127,6 +153,8 @@ public function it_fluses_all_of_the_keys_for_a_cacheable_entity()

$this->assertNull($broker->get($cacheable, 'foo'));
$this->assertNull($broker->get($cacheable, 'baz'));

Event::assertDispatched(CacheableFlushed::class);
}

/**
Expand Down

0 comments on commit 5c13fee

Please sign in to comment.