Skip to content

Commit 10c20e6

Browse files
committed
add(test) enable phpunit tests
1 parent 2a68033 commit 10c20e6

File tree

5 files changed

+122
-2
lines changed

5 files changed

+122
-2
lines changed

.github/workflows/continuous-integration.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,8 @@ jobs:
5757
- name: Run Check configuration
5858
run: php data/bin/check_configuration.php
5959

60-
- name: Run Tests
60+
- name: Run Lime Tests
6161
run: php data/bin/symfony symfony:test --trace
62+
63+
- name: Run PHPUnit Tests
64+
run: php vendor/bin/phpunit

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
77
/vendor
88
/composer.lock
99
.php-cs-fixer.cache
10+
.phpunit.result.cache
11+
phpunit.xml
12+
/tests/fixtures/symfony/log

composer.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"swiftmailer/swiftmailer": "~5.2 || ^6.0"
99
},
1010
"require-dev": {
11-
"psr/log": "*"
11+
"psr/log": "*",
12+
"phpunit/phpunit": "^9.6",
13+
"symfony/phpunit-bridge": "^7.0"
1214
},
1315
"autoload": {
1416
"files": ["autoload.php"]
@@ -26,5 +28,13 @@
2628
"replace": {
2729
"lexpress/symfony1": "^1.5"
2830
},
31+
"scripts": {
32+
"test": [
33+
"@test:lime",
34+
"@test:phpunit"
35+
],
36+
"test:lime": "php data/bin/symfony symfony:test --trace",
37+
"test:phpunit": "phpunit"
38+
},
2939
"bin": ["data/bin/symfony"]
3040
}

phpunit.xml.dist

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/10.0/phpunit.xsd"
4+
colors="true"
5+
bootstrap="tests/bootstrap.php"
6+
failOnRisky="true"
7+
failOnWarning="true"
8+
stderr="true">
9+
<php>
10+
<ini name="error_reporting" value="32767" />
11+
<ini name="intl.default_locale" value="en" />
12+
<ini name="intl.error_level" value="0" />
13+
<ini name="memory_limit" value="-1" />
14+
<ini name="apc.enable_cli" value="1" />
15+
16+
<env name="MEMCACHED_HOST" value="localhost" />
17+
</php>
18+
19+
<testsuites>
20+
<testsuite name="Symfony Test Suite">
21+
<directory>./tests/</directory>
22+
</testsuite>
23+
</testsuites>
24+
25+
26+
<coverage>
27+
<include>
28+
<directory>./lib/</directory>
29+
</include>
30+
</coverage>
31+
</phpunit>

tests/bootstrap.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony package.
5+
* (c) Fabien Potencier <fabien@symfony.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
12+
13+
// setup expected test environment (per check_configuration.php)
14+
ini_set('magic_quotes_runtime', 'off');
15+
ini_set('session.auto_start', 'off');
16+
ini_set('arg_separator.output', '&amp;');
17+
ini_set('allow_url_fopen', 'on');
18+
19+
require_once __DIR__.'/../vendor/autoload.php';
20+
21+
$libDir = realpath(__DIR__.'/../lib');
22+
23+
require_once __DIR__.'/../lib/config/sfConfig.class.php';
24+
sfConfig::set('sf_symfony_lib_dir', $libDir);
25+
26+
require_once $libDir.'/autoload/sfCoreAutoload.class.php';
27+
sfCoreAutoload::register();
28+
29+
require_once $libDir.'/util/sfToolkit.class.php';
30+
sfConfig::set('sf_test_cache_dir', sys_get_temp_dir().'/sf_test_project');
31+
32+
// TODO enable later require_once __DIR__.'/fixtures/symfony/config/ProjectConfiguration.class.php';
33+
34+
// remove all test cache
35+
sf_unit_test_shutdown();
36+
37+
// create test cache dir
38+
$sf_root_dir = sys_get_temp_dir().'/sf_test_project';
39+
@mkdir($sf_root_dir, 0777, true);
40+
41+
register_shutdown_function('sf_unit_test_shutdown');
42+
43+
function sf_unit_test_shutdown()
44+
{
45+
$sf_root_dir = sys_get_temp_dir().'/sf_test_project';
46+
if (is_dir($sf_root_dir)) {
47+
sfToolkit::clearDirectory($sf_root_dir);
48+
@rmdir($sf_root_dir);
49+
}
50+
51+
$sessions = glob(sys_get_temp_dir().'/sessions*');
52+
$tmp_files = glob(sys_get_temp_dir().'/sf*');
53+
54+
$files = array_merge(empty($sessions) ? array() : $sessions, empty($tmp_files) ? array() : $tmp_files);
55+
foreach ($files as $file) {
56+
if (is_dir($file)) {
57+
sfToolkit::clearDirectory($file);
58+
@rmdir($file);
59+
} else {
60+
@unlink($file);
61+
}
62+
}
63+
}
64+
65+
// Helper for cross platform testcases that validate output
66+
function fix_linebreaks($content)
67+
{
68+
return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
69+
}
70+
71+
if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) {
72+
DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER'));
73+
}

0 commit comments

Comments
 (0)