Tweak event extender (tests)

- Inject contract, not implementation
- Do not dispatch event in test, let the core do that
- Ensure the relevant database tables are reset prior to the test
- Use correct parameter order for assertions

Refs #2097.
This commit is contained in:
Franz Liedke 2020-04-13 11:37:03 +02:00
parent cde69480bf
commit 8b30734ffb
2 changed files with 27 additions and 13 deletions

View File

@ -11,7 +11,7 @@ namespace Flarum\Extend;
use Flarum\Extension\Extension; use Flarum\Extension\Extension;
use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Container\Container;
use Illuminate\Events\Dispatcher; use Illuminate\Contracts\Events\Dispatcher;
class Event implements ExtenderInterface class Event implements ExtenderInterface
{ {

View File

@ -10,24 +10,38 @@
namespace Flarum\Tests\integration\extenders; namespace Flarum\Tests\integration\extenders;
use Flarum\Extend; use Flarum\Extend;
use Flarum\Group\Command\CreateGroup;
use Flarum\Group\Event\Created; use Flarum\Group\Event\Created;
use Flarum\Group\Group; use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase; use Flarum\Tests\integration\TestCase;
use Illuminate\Contracts\Events\Dispatcher; use Flarum\User\User;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\Translation\Translator;
class EventTest extends TestCase class EventTest extends TestCase
{ {
use RetrievesAuthorizedUsers;
protected function buildGroup() protected function buildGroup()
{ {
$events = $this->app()->getContainer()->make(Dispatcher::class); $this->prepareDatabase([
'groups' => [
$this->adminGroup(),
],
'users' => [
$this->adminUser(),
],
]);
$group = Group::build('test group', 'test groups', '#000000', 'fas fa-crown'); $bus = $this->app()->getContainer()->make(Dispatcher::class);
$group->save(); return $bus->dispatch(
new CreateGroup(User::find(1), ['attributes' => [
$events->dispatch(new Created($group)); 'nameSingular' => 'test group',
'namePlural' => 'test groups',
return $group; 'color' => '#000000',
'icon' => 'fas fa-crown',
]])
);
} }
/** /**
@ -37,7 +51,7 @@ class EventTest extends TestCase
{ {
$group = $this->buildGroup(); $group = $this->buildGroup();
$this->assertEquals($group->name_singular, 'test group'); $this->assertEquals('test group', $group->name_singular);
} }
/** /**
@ -51,7 +65,7 @@ class EventTest extends TestCase
$group = $this->buildGroup(); $group = $this->buildGroup();
$this->assertEquals($group->name_singular, 'modified group'); $this->assertEquals('modified group', $group->name_singular);
} }
/** /**
@ -64,7 +78,7 @@ class EventTest extends TestCase
$group = $this->buildGroup(); $group = $this->buildGroup();
$this->assertEquals($group->name_singular, 'core.group.admin'); $this->assertEquals('core.group.admin', $group->name_singular);
} }
} }