Skip to content

Commit

Permalink
[general] Testing fixes (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 25, 2024
1 parent 28ec037 commit 75146f4
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -4,7 +4,7 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 150
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]

steps:
Expand Down Expand Up @@ -318,7 +318,7 @@ jobs:

strategy:
matrix:
php-version: [ "8.1", "8.2" ]
php-version: [ "8.2" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down
10 changes: 2 additions & 8 deletions composer.json
Expand Up @@ -36,9 +36,9 @@
"source": "https://github.com/FastyBird/web-server-plugin"
},
"require": {
"php": ">=8.1.0",
"php": ">=8.2.0",
"cweagans/composer-patches": "^1.7",
"fastybird/bootstrap-library": "dev-main",
"fastybird/application-library": "dev-main",
"fastybird/metadata-library": "dev-main",
"fig/http-message-util": "^1.1",
"ipub/slim-router": "^0.2",
Expand Down Expand Up @@ -108,12 +108,6 @@
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mathsolver/mathsolver.git"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -230,7 +230,7 @@ You can copy & paste it to your project, for example to `<app_root>/www/index.ph

require __DIR__ . '/../vendor/autoload.php';

exit(Your\CoolApp\Bootstrap::boot()
exit(Your\CoolApp\Application::boot()
->createContainer()
->getByType(FastyBird\Plugin\WebServer\Application\Application::class)
->run());
Expand Down
24 changes: 5 additions & 19 deletions src/Commands/HttpServer.php
Expand Up @@ -15,7 +15,7 @@

namespace FastyBird\Plugin\WebServer\Commands;

use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers;
use FastyBird\Library\Application\Helpers as ApplicationHelpers;
use FastyBird\Library\Metadata\Types as MetadataTypes;
use FastyBird\Plugin\WebServer\Events;
use FastyBird\Plugin\WebServer\Exceptions;
Expand Down Expand Up @@ -79,9 +79,9 @@ protected function execute(
): int
{
$this->logger->info(
'Launching HTTP Server',
'Starting HTTP Server',
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value,
'type' => 'server-command',
],
);
Expand Down Expand Up @@ -117,28 +117,14 @@ protected function execute(

$this->eventLoop->run();

} catch (Exceptions\Terminate $ex) {
// Log error action reason
$this->logger->error(
'HTTP server was forced to close',
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'type' => 'server-command',
'exception' => BootstrapHelpers\Logger::buildException($ex),
'cmd' => $this->getName(),
],
);

$this->eventLoop->stop();

} catch (Throwable $ex) {
// Log error action reason
$this->logger->error(
'An unhandled error occurred. Stopping HTTP server',
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value,
'type' => 'server-command',
'exception' => BootstrapHelpers\Logger::buildException($ex),
'exception' => ApplicationHelpers\Logger::buildException($ex),
'cmd' => $this->getName(),
],
);
Expand Down
8 changes: 4 additions & 4 deletions src/DI/WebServerExtension.php
Expand Up @@ -15,7 +15,7 @@

namespace FastyBird\Plugin\WebServer\DI;

use FastyBird\Library\Bootstrap\Boot as BootstrapBoot;
use FastyBird\Library\Application\Boot as ApplicationBoot;
use FastyBird\Plugin\WebServer\Application;
use FastyBird\Plugin\WebServer\Commands;
use FastyBird\Plugin\WebServer\Http;
Expand Down Expand Up @@ -43,12 +43,12 @@ class WebServerExtension extends DI\CompilerExtension
public const NAME = 'fbWebServerPlugin';

public static function register(
BootstrapBoot\Configurator $config,
ApplicationBoot\Configurator $config,
string $extensionName = self::NAME,
): void
{
$config->onCompile[] = static function (
BootstrapBoot\Configurator $config,
ApplicationBoot\Configurator $config,
DI\Compiler $compiler,
) use (
$extensionName,
Expand All @@ -61,7 +61,7 @@ public function getConfigSchema(): Schema\Schema
{
return Schema\Expect::structure([
'static' => Schema\Expect::structure([

Check warning on line 63 in src/DI/WebServerExtension.php

View workflow job for this annotation

GitHub Actions / Test for mutants (8.2, ubuntu-latest)

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ } public function getConfigSchema() : Schema\Schema { - return Schema\Expect::structure(['static' => Schema\Expect::structure(['publicRoot' => Schema\Expect::string()->nullable(), 'enabled' => Schema\Expect::bool(false)]), 'server' => Schema\Expect::structure(['address' => Schema\Expect::string('127.0.0.1'), 'port' => Schema\Expect::int(8000), 'certificate' => Schema\Expect::string()->nullable()]), 'cors' => Schema\Expect::structure(['enabled' => Schema\Expect::bool(false), 'allow' => Schema\Expect::structure(['origin' => Schema\Expect::string('*'), 'methods' => Schema\Expect::arrayOf('string')->default([RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST, RequestMethodInterface::METHOD_PATCH, RequestMethodInterface::METHOD_DELETE, RequestMethodInterface::METHOD_OPTIONS]), 'credentials' => Schema\Expect::bool(true), 'headers' => Schema\Expect::arrayOf('string')->default(['Content-Type', 'Authorization', 'X-Requested-With'])])])]); + return Schema\Expect::structure(['static' => Schema\Expect::structure(['enabled' => Schema\Expect::bool(false)]), 'server' => Schema\Expect::structure(['address' => Schema\Expect::string('127.0.0.1'), 'port' => Schema\Expect::int(8000), 'certificate' => Schema\Expect::string()->nullable()]), 'cors' => Schema\Expect::structure(['enabled' => Schema\Expect::bool(false), 'allow' => Schema\Expect::structure(['origin' => Schema\Expect::string('*'), 'methods' => Schema\Expect::arrayOf('string')->default([RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST, RequestMethodInterface::METHOD_PATCH, RequestMethodInterface::METHOD_DELETE, RequestMethodInterface::METHOD_OPTIONS]), 'credentials' => Schema\Expect::bool(true), 'headers' => Schema\Expect::arrayOf('string')->default(['Content-Type', 'Authorization', 'X-Requested-With'])])])]); } public function loadConfiguration() : void {
'publicRoot' => Schema\Expect::string(null)->nullable(),
'publicRoot' => Schema\Expect::string()->nullable(),
'enabled' => Schema\Expect::bool(false),

Check warning on line 65 in src/DI/WebServerExtension.php

View workflow job for this annotation

GitHub Actions / Test for mutants (8.2, ubuntu-latest)

Escaped Mutant for Mutator "FalseValue": --- Original +++ New @@ @@ } public function getConfigSchema() : Schema\Schema { - return Schema\Expect::structure(['static' => Schema\Expect::structure(['publicRoot' => Schema\Expect::string()->nullable(), 'enabled' => Schema\Expect::bool(false)]), 'server' => Schema\Expect::structure(['address' => Schema\Expect::string('127.0.0.1'), 'port' => Schema\Expect::int(8000), 'certificate' => Schema\Expect::string()->nullable()]), 'cors' => Schema\Expect::structure(['enabled' => Schema\Expect::bool(false), 'allow' => Schema\Expect::structure(['origin' => Schema\Expect::string('*'), 'methods' => Schema\Expect::arrayOf('string')->default([RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST, RequestMethodInterface::METHOD_PATCH, RequestMethodInterface::METHOD_DELETE, RequestMethodInterface::METHOD_OPTIONS]), 'credentials' => Schema\Expect::bool(true), 'headers' => Schema\Expect::arrayOf('string')->default(['Content-Type', 'Authorization', 'X-Requested-With'])])])]); + return Schema\Expect::structure(['static' => Schema\Expect::structure(['publicRoot' => Schema\Expect::string()->nullable(), 'enabled' => Schema\Expect::bool(true)]), 'server' => Schema\Expect::structure(['address' => Schema\Expect::string('127.0.0.1'), 'port' => Schema\Expect::int(8000), 'certificate' => Schema\Expect::string()->nullable()]), 'cors' => Schema\Expect::structure(['enabled' => Schema\Expect::bool(false), 'allow' => Schema\Expect::structure(['origin' => Schema\Expect::string('*'), 'methods' => Schema\Expect::arrayOf('string')->default([RequestMethodInterface::METHOD_GET, RequestMethodInterface::METHOD_POST, RequestMethodInterface::METHOD_PATCH, RequestMethodInterface::METHOD_DELETE, RequestMethodInterface::METHOD_OPTIONS]), 'credentials' => Schema\Expect::bool(true), 'headers' => Schema\Expect::arrayOf('string')->default(['Content-Type', 'Authorization', 'X-Requested-With'])])])]); } public function loadConfiguration() : void {
]),
'server' => Schema\Expect::structure([
Expand Down
24 changes: 0 additions & 24 deletions src/Exceptions/Terminate.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Http/Entity.php
@@ -1,7 +1,7 @@
<?php declare(strict_types = 1);

/**
* Transformer.php
* Entity.php
*
* @license More in LICENSE.md
* @copyright https://www.fastybird.com
Expand Down
12 changes: 6 additions & 6 deletions src/Middleware/Cors.php
Expand Up @@ -29,19 +29,19 @@
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
final class Cors
final readonly class Cors
{

/**
* @param array<string> $allowMethods
* @param array<string> $allowHeaders
*/
public function __construct(
private readonly bool $enabled,
private readonly string $allowOrigin,
private readonly array $allowMethods,
private readonly bool $allowCredentials,
private readonly array $allowHeaders,
private bool $enabled,
private string $allowOrigin,
private array $allowMethods,
private bool $allowCredentials,
private array $allowHeaders,
)
{
}
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/Router.php
Expand Up @@ -29,12 +29,12 @@
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
final class Router
final readonly class Router
{

public function __construct(
private readonly Routing\IRouter $router,
private readonly EventDispatcher\EventDispatcherInterface|null $dispatcher = null,
private Routing\IRouter $router,
private EventDispatcher\EventDispatcherInterface|null $dispatcher = null,
)
{
}
Expand Down
22 changes: 11 additions & 11 deletions src/Server/Factory.php
Expand Up @@ -15,7 +15,7 @@

namespace FastyBird\Plugin\WebServer\Server;

use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers;
use FastyBird\Library\Application\Helpers as ApplicationHelpers;
use FastyBird\Library\Metadata\Types as MetadataTypes;
use FastyBird\Plugin\WebServer\Middleware;
use Psr\Log;
Expand All @@ -34,15 +34,15 @@
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
final class Factory
final readonly class Factory
{

public function __construct(
private readonly Middleware\Cors $corsMiddleware,
private readonly Middleware\StaticFiles $staticFilesMiddleware,
private readonly Middleware\Router $routerMiddleware,
private readonly EventLoop\LoopInterface $eventLoop,
private readonly Log\LoggerInterface $logger = new Log\NullLogger(),
private Middleware\Cors $corsMiddleware,
private Middleware\StaticFiles $staticFilesMiddleware,
private Middleware\Router $routerMiddleware,
private EventLoop\LoopInterface $eventLoop,
private Log\LoggerInterface $logger = new Log\NullLogger(),
)
{
}
Expand All @@ -61,9 +61,9 @@ public function create(Socket\ServerInterface $server): void
$this->logger->error(
'An error occurred during handling request. Stopping HTTP server',
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value,
'type' => 'factory',
'exception' => BootstrapHelpers\Logger::buildException($ex),
'exception' => ApplicationHelpers\Logger::buildException($ex),
],
);

Expand All @@ -77,7 +77,7 @@ public function create(Socket\ServerInterface $server): void
$this->logger->info(
sprintf('Listening on "%s"', str_replace('tls:', 'https:', $server->getAddress())),
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value,
'type' => 'factory',
],
);
Expand All @@ -86,7 +86,7 @@ public function create(Socket\ServerInterface $server): void
$this->logger->info(
sprintf('Listening on "%s"', str_replace('tcp:', 'http:', $server->getAddress())),
[
'source' => MetadataTypes\PluginSource::SOURCE_PLUGIN_WEB_SERVER,
'source' => MetadataTypes\Sources\Plugin::WEB_SERVER->value,
'type' => 'factory',
],
);
Expand Down
14 changes: 7 additions & 7 deletions src/Subscribers/Server.php
Expand Up @@ -16,8 +16,8 @@
namespace FastyBird\Plugin\WebServer\Subscribers;

use Doctrine\DBAL;
use FastyBird\Library\Bootstrap\Exceptions as BootstrapExceptions;
use FastyBird\Library\Bootstrap\Helpers as BootstrapHelpers;
use FastyBird\Library\Application\Exceptions as ApplicationExceptions;
use FastyBird\Library\Application\Helpers as ApplicationHelpers;
use FastyBird\Plugin\WebServer\Events;
use FastyBird\Plugin\WebServer\Exceptions;
use Symfony\Component\EventDispatcher;
Expand All @@ -30,10 +30,10 @@
*
* @author Adam Kadlec <adam.kadlec@fastybird.com>
*/
class Server implements EventDispatcher\EventSubscriberInterface
readonly class Server implements EventDispatcher\EventSubscriberInterface
{

public function __construct(private readonly BootstrapHelpers\Database $database)
public function __construct(private ApplicationHelpers\Database $database)
{
}

Expand All @@ -47,7 +47,7 @@ public static function getSubscribedEvents(): array
}

/**
* @throws BootstrapExceptions\InvalidState
* @throws ApplicationExceptions\InvalidState
* @throws DBAL\Exception
* @throws Exceptions\InvalidState
*/
Expand All @@ -66,7 +66,7 @@ public function check(): void
}

/**
* @throws BootstrapExceptions\InvalidState
* @throws ApplicationExceptions\InvalidState
* @throws DBAL\Exception
*/
public function request(): void
Expand All @@ -78,7 +78,7 @@ public function request(): void
}

/**
* @throws BootstrapExceptions\InvalidState
* @throws ApplicationExceptions\InvalidState
*/
public function response(): void
{
Expand Down

0 comments on commit 75146f4

Please sign in to comment.