Skip to content

Commit fd3abd2

Browse files
committed
Started support for built in test server
1 parent fb0cc30 commit fd3abd2

File tree

7 files changed

+80
-63
lines changed

7 files changed

+80
-63
lines changed

bin/console

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
#!/usr/bin/env php
22
<?php
33

4-
$rootDir = realpath(__DIR__.'/../../../..');
5-
$vendorDir = realpath($rootDir.'/vendor');
6-
$phpUnitFile = $rootDir.'/phpunit.xml.dist';
7-
8-
if (!file_exists($phpUnitFile)) {
9-
throw new \Exception(sprintf(
10-
'Cannot find phpunit.xml.dist file in "%s"',
11-
$phpUnitFile
12-
));
13-
}
14-
15-
$xml = new \SimpleXMLElement(file_get_contents($phpUnitFile));
16-
$kernelDir = $xml->php[0]->server[0]['value'];
17-
18-
$kernelFile = $kernelDir.'/AppKernel.php';
19-
20-
if (!file_exists($kernelFile)) {
21-
throw new \Exception(sprintf(
22-
'Cannot find kernel file "%s"',
23-
$kernelFile
24-
));
25-
}
26-
27-
require_once $vendorDir.'/symfony-cmf/testing/bootstrap/bootstrap.php';
28-
require_once $kernelFile;
4+
$kernel = include __DIR__.'/../bootstrap/kernel_bootstrap.php';
295

306
use Symfony\Bundle\FrameworkBundle\Console\Application;
317
use Symfony\Component\Console\Input\ArgvInput;
328

33-
$kernel = new AppKernel('test', true);
349
$application = new Application($kernel);
3510
$application->run();

bin/generate_functional.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

bin/server

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$kernel = include __DIR__.'/../bootstrap/kernel_bootstrap.php';
5+
6+
use Symfony\Bundle\FrameworkBundle\Console\Application;
7+
use Symfony\Component\Console\Input\ArrayInput;
8+
9+
$input = new ArrayInput(array(
10+
'server:run',
11+
'--router' => CMF_TEST_ROOT_DIR.'/resources/web/router.php',
12+
'--docroot' => CMF_TEST_ROOT_DIR.'/resources/web',
13+
));
14+
15+
$application = new Application($kernel);
16+
$application->run($input);

bootstrap/bootstrap.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22

33
$vendorDir = realpath(__DIR__.'/../../..');
44

5-
$file = $vendorDir.'/autoload.php';
6-
7-
if (!file_exists($file)) {
8-
throw new RuntimeException('Cannot find "'.$file.'". Run "composer update --dev" to run test suite.');
5+
if (!$loader = include $vendorDir.'/autoload.php') {
6+
$nl = PHP_SAPI === 'cli' ? PHP_EOL : '<br />';
7+
echo "$nl$nl";
8+
die('You must set up the project dependencies.'.$nl.
9+
'Run the following commands in '.dirname(__DIR__).':'.$nl.$nl.
10+
'curl -s http://getcomposer.org/installer | php'.$nl.
11+
'php composer.phar install'.$nl);
912
}
1013

11-
require_once $file;
12-
13-
if (!class_exists('Symfony\\Component\\ClassLoader\\UniversalClassLoader')) {
14-
throw new RuntimeException('Run "composer update --dev" to run test suite. (You seem to have missed the --dev part.)');
15-
}
1614

17-
use Symfony\Component\ClassLoader\UniversalClassLoader;
1815
use Doctrine\Common\Annotations\AnnotationRegistry;
19-
20-
$loader = new UniversalClassLoader();
21-
2216
AnnotationRegistry::registerLoader(function($class) use ($loader) {
2317
$loader->loadClass($class);
24-
return class_exists($class, false);
18+
19+
// this was class_exists($class, false) i.e. do not autoload.
20+
// this is required so that custom annotations (e.g. TreeUiBundle
21+
// annotations) are autoloaded - but they should be found by the
22+
// composer loader above.
23+
//
24+
// This probably slows things down.
25+
//
26+
// @todo: Fix me.
27+
return class_exists($class);
2528
});
2629

2730
AnnotationRegistry::registerFile($vendorDir.'/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php');

bootstrap/kernel_bootstrap.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$rootDir = realpath(__DIR__.'/../../../..');
3+
$vendorDir = realpath($rootDir.'/vendor');
4+
$phpUnitFile = $rootDir.'/phpunit.xml.dist';
5+
6+
if (!file_exists($phpUnitFile)) {
7+
throw new \Exception(sprintf(
8+
'Cannot find phpunit.xml.dist file in "%s"',
9+
$phpUnitFile
10+
));
11+
}
12+
13+
$xml = new \SimpleXMLElement(file_get_contents($phpUnitFile));
14+
$kernelDir = $xml->php[0]->server[0]['value'];
15+
16+
$kernelFile = $rootDir.'/'.$kernelDir.'/AppKernel.php';
17+
18+
if (!file_exists($kernelFile)) {
19+
throw new \Exception(sprintf(
20+
'Cannot find kernel file "%s"',
21+
$kernelFile
22+
));
23+
}
24+
25+
require_once $vendorDir.'/symfony-cmf/testing/bootstrap/bootstrap.php';
26+
require_once $kernelFile;
27+
28+
return new AppKernel('test', true);

resources/web/app_test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
4+
use Symfony\Component\HttpFoundation\Request;
5+
6+
$kernel = include __DIR__.'/../../bootstrap/kernel_bootstrap.php';
7+
$kernel->loadClassCache();
8+
$request = Request::createFromGlobals();
9+
$response = $kernel->handle($request);
10+
$response->send();
11+
$kernel->terminate($request, $response);

resources/web/router.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$_SERVER['DOCUMENT_ROOT'] = __DIR__;
4+
$_SERVER['SCRIPT_FILENAME'] = __DIR__.DIRECTORY_SEPARATOR.'app_test.php';
5+
6+
require 'app_test.php';
7+

0 commit comments

Comments
 (0)