0 follower

Final Class Yiisoft\Yii\Testing\TestApplicationRunner

InheritanceYiisoft\Yii\Testing\TestApplicationRunner » Yiisoft\Yii\Runner\ApplicationRunner

Property Details

Hide inherited properties

$container public property
public \Psr\Container\ContainerInterface|null $container null
$responseGrabber public property

Method Details

Hide inherited methods

__construct() public method

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,
    );
}

            
addProviders() public method

public addProviders( \Yiisoft\Di\ServiceProviderInterface[] $providers ): void
$providers \Yiisoft\Di\ServiceProviderInterface[]

                public function addProviders(array $providers): void
{
    $this->providers = array_merge($this->providers, $providers);
}

            
preloadContainer() public method

public preloadContainer( ): void

                public function preloadContainer(): void
{
    /**
     * @psalm-suppress UnresolvableInclude
     */
    require_once $this->rootPath . '/autoload.php';
    $this->container = $this->createContainer();
    $this->runBootstrap();
    $this->checkEvents();
}

            
run() public method

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);
    }
}

            
withRequest() public method

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,
    ];
}