Skip to content

Commit

Permalink
Merge pull request #6 from msmakouz/master
Browse files Browse the repository at this point in the history
Fixing tests, adding Nyholm bridge
  • Loading branch information
butschster committed Jun 15, 2022
2 parents f87b37d + 67e3f64 commit 21f1a96
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"spiral/boot": "^3.0",
"spiral/core": "^3.0",
"spiral/exceptions": "^3.0",
"spiral/http": "^3.0"
"spiral/http": "^3.0",
"psr/http-factory-implementation": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"spiral/testing": "^2.0",
"vimeo/psalm": "^4.23",
"spiral/framework": "^3.0",
"nyholm/psr7": "^1.5.0"
"spiral/nyholm-bridge": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 0 additions & 5 deletions src/Bootloader/SapiBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Nyholm\Psr7Server\ServerRequestCreatorInterface;
use Spiral\Boot\AbstractKernel;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Http\Bootloader\DiactorosBootloader;
use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\FactoryInterface;
use Spiral\Http\Config\HttpConfig;
Expand All @@ -17,10 +16,6 @@

final class SapiBootloader extends Bootloader implements SingletonInterface
{
protected const DEPENDENCIES = [
DiactorosBootloader::class,
];

protected const SINGLETONS = [
SapiEmitter::class => [self::class, 'createEmitter'],
ServerRequestCreatorInterface::class => ServerRequestCreator::class,
Expand Down
12 changes: 6 additions & 6 deletions tests/src/Dispatcher/SapiDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ public function testDispatchNativeError(): void
{
$emitter = new BufferEmitter();

$app = $this->initApp([
$this->initApp([
'DEBUG' => true
]);

$files = $app->getContainer()->get(FilesInterface::class)->getFiles(
$app->getContainer()->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/'
$files = $this->getApp()->getContainer()->get(FilesInterface::class)->getFiles(
$this->getApp()->getContainer()->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/'
);

$this->assertCount(0, $files);

$_SERVER['REQUEST_URI'] = '/error';
$app->getContainer()->get(SapiDispatcher::class)->serve(
$this->getApp()->getContainer()->get(SapiDispatcher::class)->serve(
\Closure::bind(function (ResponseInterface $response) {$this->emit($response);}, $emitter)
);

$files = $app->getContainer()->get(FilesInterface::class)->getFiles(
$app->getContainer()->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/'
$files = $this->getApp()->getContainer()->get(FilesInterface::class)->getFiles(
$this->getApp()->getContainer()->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/'
);

$this->assertCount(1, $files);
Expand Down
23 changes: 13 additions & 10 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

use App\Bootloader\AppBootloader;
use App\TestApp;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Spiral\Boot\AbstractKernel;
use Spiral\Bootloader\ExceptionHandlerBootloader;
use Spiral\Http\Bootloader\DiactorosBootloader;
use Spiral\Bootloader\Http\ErrorHandlerBootloader;
use Spiral\Bootloader\Http\HttpBootloader;
use Spiral\Bootloader\Http\RouterBootloader;
use Spiral\Bootloader\SnapshotsBootloader;
use Spiral\Core\Container;
use Spiral\Http\Config\HttpConfig;
use Spiral\Nyholm\Bootloader\NyholmBootloader;
use Spiral\Sapi\Bootloader\SapiBootloader;
use Spiral\Sapi\Emitter\SapiEmitter;
use Spiral\Testing\TestableKernelInterface;
Expand All @@ -29,9 +31,11 @@ protected function createResponse(
$body = null,
string $version = '1.1'
): ResponseInterface {
$response = (new Response())
->withStatus($status)
->withProtocolVersion($version);
$this->getContainer()->bind(HttpConfig::class, new HttpConfig(['headers' => []]));

$factory = $this->getContainer()->get(ResponseFactoryInterface::class);
$response = $factory->createResponse($status)->withProtocolVersion($version);

foreach ($headers as $header => $value) {
$response = $response->withHeader($header, $value);
}
Expand Down Expand Up @@ -62,7 +66,7 @@ public function defineBootloaders(): array
return [
SnapshotsBootloader::class,
HttpBootloader::class,
DiactorosBootloader::class,
NyholmBootloader::class,
ErrorHandlerBootloader::class,
RouterBootloader::class,
SapiBootloader::class,
Expand All @@ -81,12 +85,11 @@ protected function tearDown(): void
/**
* @return AbstractKernel|TestableKernelInterface
*/
public function createAppInstance(): TestableKernelInterface
public function createAppInstance(Container $container = new Container()): TestableKernelInterface
{
return TestApp::createWithBootloaders(
$this->defineBootloaders(),
return TestApp::create(
$this->defineDirectories($this->rootDirectory()),
false
);
)->withBootloaders($this->defineBootloaders());
}
}

0 comments on commit 21f1a96

Please sign in to comment.