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 b343206c7b
commit b7d8f77529
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4
2 changed files with 27 additions and 13 deletions

View File

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

View File

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