mirror of
https://github.com/flarum/core.git
synced 2025-08-08 17:36:38 +02:00
chore: create tests to highlight the conditional instantiation problem
This commit is contained in:
@@ -12,9 +12,12 @@ namespace Flarum\Tests\integration\extenders;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Api\Serializer\ForumSerializer;
|
use Flarum\Api\Serializer\ForumSerializer;
|
||||||
use Flarum\Extend;
|
use Flarum\Extend;
|
||||||
|
use Flarum\Extend\ExtenderInterface;
|
||||||
|
use Flarum\Extension\Extension;
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||||
use Flarum\Testing\integration\TestCase;
|
use Flarum\Testing\integration\TestCase;
|
||||||
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class ConditionalTest extends TestCase
|
class ConditionalTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -159,4 +162,46 @@ class ConditionalTest extends TestCase
|
|||||||
|
|
||||||
$this->app();
|
$this->app();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function conditional_does_not_instantiate_extender_if_condition_is_false()
|
||||||
|
{
|
||||||
|
$this->extend(
|
||||||
|
(new Extend\Conditional())
|
||||||
|
->when(false, [
|
||||||
|
new TestExtender()
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->app();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function conditional_does_instantiate_extender_if_condition_is_true()
|
||||||
|
{
|
||||||
|
$this->expectException(Exception::class);
|
||||||
|
$this->expectExceptionMessage('TestExtender was instantiated!');
|
||||||
|
|
||||||
|
$this->extend(
|
||||||
|
(new Extend\Conditional())
|
||||||
|
->when(true, [
|
||||||
|
new TestExtender()
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->app();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestExtender implements ExtenderInterface
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
throw new Exception('TestExtender was instantiated!');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function extend(Container $container, Extension $extension = null)
|
||||||
|
{
|
||||||
|
// This method can be left empty for this test.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user