Skip to content

Commit

Permalink
Move C4 to index-test.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 5, 2020
1 parent cd2c9ed commit 5a36225
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -59,11 +59,11 @@ jobs:
if: matrix.php == '8.0'
run: composer create-project --prefer-dist --no-interaction --no-progress --ignore-platform-reqs --stability=dev yii-extension/app app --ansi

- name: Run tests with codeception
- name: Run tests with codeception with coverage
run: |
cd app
php -S 127.0.0.1:8080 -t public > ./runtime/yii.log 2>&1 &
vendor/bin/codecept run --coverage --coverage-xml
php -S 127.0.0.1:8080 -t public public/index-test.php > ./runtime/yii.log 2>&1 &
vendor/bin/codecept run --coverage-xml
- name: Upload coverage to codecov on Linux php 7.4
if: matrix.os == 'ubuntu-20.04' && matrix.php == '7.4'
Expand Down
74 changes: 74 additions & 0 deletions public/index-test.php
@@ -0,0 +1,74 @@
<?php

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Yiisoft\Composer\Config\Builder;
use Yiisoft\Di\Container;
use Yiisoft\ErrorHandler\ErrorHandler;
use Yiisoft\ErrorHandler\HtmlRenderer;
use Yiisoft\ErrorHandler\ThrowableRendererInterface;
use Yiisoft\Http\Method;
use Yiisoft\Yii\Web\Application;
use Yiisoft\Yii\Web\SapiEmitter;
use Yiisoft\Yii\Web\ServerRequestFactory;

// PHP built-in server routing.
if (PHP_SAPI === 'cli-server') {
// Serve static files as is.
if (is_file(__DIR__ . $_SERVER["REQUEST_URI"])) {
return false;
}

// Explicitly set for URLs with dot.
$_SERVER['SCRIPT_NAME'] = '/index-test.php';
}

$c3 = dirname(__DIR__) . '/c3.php';

if (is_file($c3)) {
require_once $c3;
}

require_once dirname(__DIR__) . '/vendor/autoload.php';

// Don't do it in production, assembling takes it's time
Builder::rebuild();
$startTime = microtime(true);

/**
* Register temporary error handler to catch error while container is building.
*/
$errorHandler = new ErrorHandler(new NullLogger(), new HtmlRenderer());
/**
* Production mode
* $errorHandler = $errorHandler->withoutExposedDetails();
*/
$errorHandler->register();

$container = new Container(
require Builder::path('web'),
require Builder::path('providers')
);

/**
* Configure error handler with real container-configured dependencies
*/
$errorHandler->setLogger($container->get(LoggerInterface::class));
$errorHandler->setRenderer($container->get(ThrowableRendererInterface::class));

$container = $container->get(ContainerInterface::class);
$application = $container->get(Application::class);

$request = $container->get(ServerRequestFactory::class)->createFromGlobals();
$request = $request->withAttribute('applicationStartTime', $startTime);

try {
$application->start();
$response = $application->handle($request);
$emitter = new SapiEmitter();
$emitter->emit($response, $request->getMethod() === Method::HEAD);
} finally {
$application->afterEmit($response ?? null);
$application->shutdown();
}

0 comments on commit 5a36225

Please sign in to comment.