generated from spiral-packages/package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from spiral/dispatchers
Add compatibility with Spiral Framework 3.12.0 dispatchers
- Loading branch information
Showing
3 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\Traits; | ||
|
||
use Spiral\Boot\DispatcherInterface; | ||
use Spiral\Boot\Environment; | ||
use Spiral\Boot\EnvironmentInterface; | ||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Traits\InteractsWithDispatcher; | ||
|
||
/** | ||
* @coversDefaultClass InteractsWithDispatcher | ||
*/ | ||
final class InteractsWithDispatcherTest extends TestCase | ||
{ | ||
public function testAssertDispatcherCanBeServed(): void | ||
{ | ||
$dispatcher = new class implements DispatcherInterface { | ||
public function canServe(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function serve(): void {} | ||
}; | ||
|
||
$this->assertDispatcherCanBeServed($dispatcher::class); | ||
} | ||
|
||
public function testAssertDispatcherCanBeServedStaticMethodWithEnv(): void | ||
{ | ||
$dispatcher = new class { | ||
public function canServe(EnvironmentInterface $env): bool | ||
{ | ||
return $env->get('MODE') === 'http'; | ||
} | ||
}; | ||
|
||
$this->getContainer()->bindSingleton(EnvironmentInterface::class, new Environment(['MODE' => 'http']), true); | ||
$this->assertDispatcherCanBeServed($dispatcher::class); | ||
} | ||
|
||
public function testAssertDispatcherCannotBeServed(): void | ||
{ | ||
$dispatcher = new class implements DispatcherInterface { | ||
public function canServe(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function serve(): void {} | ||
}; | ||
|
||
$this->assertDispatcherCannotBeServed($dispatcher::class); | ||
} | ||
|
||
public function testAssertDispatcherCannotBeServedStaticMethodWithEnv(): void | ||
{ | ||
$dispatcher = new class { | ||
public function canServe(EnvironmentInterface $env): bool | ||
{ | ||
return $env->get('MODE') === 'http'; | ||
} | ||
}; | ||
|
||
$this->getContainer()->bindSingleton(EnvironmentInterface::class, new Environment(['MODE' => 'jobs']), true); | ||
$this->assertDispatcherCannotBeServed($dispatcher::class); | ||
} | ||
|
||
public function testGetRegisteredDispatchers(): void | ||
{ | ||
$dispatcherA = $this->createMock(DispatcherInterface::class); | ||
$dispatcherB = $this->createMock(DispatcherInterface::class); | ||
|
||
$ref = new \ReflectionProperty($this->getApp(), 'dispatchers'); | ||
$ref->setValue($this->getApp(), [$dispatcherA, $dispatcherB::class]); | ||
|
||
$this->assertSame( | ||
[$dispatcherA::class, $dispatcherB::class], | ||
$this->getRegisteredDispatchers(), | ||
); | ||
} | ||
} |