Final Class Yiisoft\Yii\Testing\TestApplicationRunner
| Inheritance | Yiisoft\Yii\Testing\TestApplicationRunner » Yiisoft\Yii\Runner\ApplicationRunner |
|---|
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $container | \Psr\Container\ContainerInterface|null | Yiisoft\Yii\Testing\TestApplicationRunner | |
| $responseGrabber | Yiisoft\Yii\Testing\ResponseGrabber | Yiisoft\Yii\Testing\TestApplicationRunner |
Public Methods
Property Details
Method Details
| public __construct( Yiisoft\Yii\Testing\ResponseGrabber $responseGrabber, string $rootPath, boolean $debug = false, boolean $checkEvents = false, string|null $environment = null, string $bootstrapGroup = 'bootstrap-web', string $eventsGroup = 'events-web', string $diGroup = 'di-web', string $diProvidersGroup = 'di-providers-web', string $diDelegatesGroup = 'di-delegates-web', string $diTagsGroup = 'di-tags-web', string $paramsGroup = 'params-web', array $nestedParamsGroups = ['params'], array $nestedEventsGroups = ['events'] ): mixed | ||
| $responseGrabber | Yiisoft\Yii\Testing\ResponseGrabber | |
| $rootPath | string |
The absolute path to the project root. |
| $debug | boolean |
Whether the debug mode is enabled. |
| $checkEvents | boolean |
Whether to check events' configuration. |
| $environment | string|null |
The environment name. |
| $bootstrapGroup | string |
The bootstrap configuration group name. |
| $eventsGroup | string |
The events' configuration group name. |
| $diGroup | string |
The container definitions' configuration group name. |
| $diProvidersGroup | string |
The container providers' configuration group name. |
| $diDelegatesGroup | string |
The container delegates' configuration group name. |
| $diTagsGroup | string |
The container tags' configuration group name. |
| $paramsGroup | string |
The configuration parameters group name. |
| $nestedParamsGroups | array |
Configuration group names that included into configuration parameters group. This is needed for recursive merging of parameters. |
| $nestedEventsGroups | array |
Configuration group names that included into events' configuration group. This is needed for reverse and recursive merge of events' configurations. |
public function __construct(
public ResponseGrabber $responseGrabber,
string $rootPath,
bool $debug = false,
bool $checkEvents = false,
?string $environment = null,
string $bootstrapGroup = 'bootstrap-web',
string $eventsGroup = 'events-web',
string $diGroup = 'di-web',
string $diProvidersGroup = 'di-providers-web',
string $diDelegatesGroup = 'di-delegates-web',
string $diTagsGroup = 'di-tags-web',
string $paramsGroup = 'params-web',
array $nestedParamsGroups = ['params'],
array $nestedEventsGroups = ['events'],
) {
parent::__construct(
$rootPath,
$debug,
$checkEvents,
$environment,
$bootstrapGroup,
$eventsGroup,
$diGroup,
$diProvidersGroup,
$diDelegatesGroup,
$diTagsGroup,
$paramsGroup,
$nestedParamsGroups,
$nestedEventsGroups,
);
}
| public addProviders( \Yiisoft\Di\ServiceProviderInterface[] $providers ): void | ||
| $providers | \Yiisoft\Di\ServiceProviderInterface[] | |
public function addProviders(array $providers): void
{
$this->providers = array_merge($this->providers, $providers);
}
| public preloadContainer( ): void |
public function preloadContainer(): void
{
/**
* @psalm-suppress UnresolvableInclude
*/
require_once $this->rootPath . '/autoload.php';
$this->container = $this->createContainer();
$this->runBootstrap();
$this->checkEvents();
}
| public run( ): |
public function run(): void
{
$this->preloadContainer();
/** @var ContainerInterface $container */
$container = $this->container;
$errorHandler = $container->get(ErrorHandler::class);
if ($this->debug) {
$errorHandler->debug();
}
$errorHandler->register();
/** @var Application $application */
$application = $container->get(Application::class);
/**
* @var ServerRequestInterface
* @psalm-suppress MixedMethodCall
*/
$serverRequest = $container
->get(ServerRequestFactoryInterface::class)
->createServerRequest(
$this->requestParameters['server']['REQUEST_METHOD'],
$this->requestParameters['server']['REQUEST_URI'],
)
->withQueryParams($this->requestParameters['get'] ?? [])
->withParsedBody($this->requestParameters['post'] ?? [])
->withCookieParams($this->requestParameters['cookies'] ?? [])
->withUploadedFiles($this->requestParameters['files'] ?? []);
if (!empty($this->requestParameters['headers'])) {
foreach ($this->requestParameters['headers'] as $name => $value) {
$serverRequest = $serverRequest->withHeader($name, $value);
}
}
if (!empty($this->requestParameters['body'])) {
$serverRequest->getBody()->write((string) $this->requestParameters['body']);
$serverRequest->getBody()->rewind();
}
/**
* @var ResponseInterface|null $response
*/
$response = null;
try {
$application->start();
$response = $application->handle($serverRequest);
} catch (Throwable $throwable) {
$handler = new ThrowableHandler($throwable);
/**
* @psalm-suppress MixedMethodCall
*/
$response = $container
->get(ErrorCatcher::class)
->process($serverRequest, $handler);
} finally {
$application->afterEmit($response ?? null);
$application->shutdown();
$this->responseGrabber->setResponse($response);
}
}
| public withRequest( string $method, string $url, array $queryParams = [], array $postParams = [], mixed $body = null, array $headers = [], array $cookies = [], array $files = [] ): void | ||
| $method | string | |
| $url | string | |
| $queryParams | array | |
| $postParams | array | |
| $body | mixed | |
| $headers | array | |
| $cookies | array | |
| $files | array | |
public function withRequest(
string $method,
string $url,
array $queryParams = [],
array $postParams = [],
mixed $body = null,
array $headers = [],
array $cookies = [],
array $files = [],
): void {
$this->requestParameters = [
'server' => [
'SCRIPT_NAME' => '/index.php',
'REQUEST_METHOD' => $method,
'SERVER_PROTOCOL' => '1.1',
'REQUEST_URI' => $url,
],
'headers' => $headers,
'cookies' => $cookies,
'get' => $queryParams,
'post' => $postParams,
'files' => $files,
'body' => $body,
];
}
Signup or Login in order to comment.