From 356960a7eb6eea6dddad3c35a3c78c5fbfa6e955 Mon Sep 17 00:00:00 2001 From: Karoly Gossler Date: Fri, 17 Feb 2023 00:31:29 +0100 Subject: [PATCH] add(test) enable phpunit tests --- .github/workflows/continuous-integration.yml | 5 +- .gitignore | 3 + composer.json | 12 +++- phpunit.xml.dist | 31 +++++++++ test/bin/test | 31 ++++----- tests/bootstrap.php | 73 ++++++++++++++++++++ 6 files changed, 135 insertions(+), 20 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/bootstrap.php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 47e723aed..86a90b84b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -59,5 +59,8 @@ jobs: - name: Run Check configuration run: php data/bin/check_configuration.php - - name: Run Tests + - name: Run Lime Tests run: php data/bin/symfony symfony:test --trace + + - name: Run PHPUnit Tests + run: php vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index 3c17d4767..0644b20d6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/ /vendor /composer.lock .php-cs-fixer.cache +.phpunit.result.cache +phpunit.xml +/tests/fixtures/symfony/log diff --git a/composer.json b/composer.json index a424d6ea6..c3664aab3 100755 --- a/composer.json +++ b/composer.json @@ -8,7 +8,9 @@ "swiftmailer/swiftmailer": "~5.2 || ^6.0" }, "require-dev": { - "psr/log": "*" + "psr/log": "*", + "phpunit/phpunit": "^9.6", + "symfony/phpunit-bridge": "^7.0" }, "autoload": { "files": ["autoload.php"] @@ -26,5 +28,13 @@ "replace": { "lexpress/symfony1": "^1.5" }, + "scripts": { + "test": [ + "@test:lime", + "@test:phpunit" + ], + "test:lime": "php data/bin/symfony symfony:test --trace", + "test:phpunit": "phpunit" + }, "bin": ["data/bin/symfony"] } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..41c3f6314 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + ./tests/ + + + + + + + ./lib/ + + + diff --git a/test/bin/test b/test/bin/test index 5305c0541..51f0d389c 100755 --- a/test/bin/test +++ b/test/bin/test @@ -12,20 +12,17 @@ # Configuration # dependencyPreferences='highest' -skipPHPVersions='php8' # Commands # dcexec="docker-compose exec -u `id -u`:`id -g`" installSubmodule='git submodule update --checkout --recursive --force' -composerUpdate='composer update --prefer-dist --no-suggest --optimize-autoloader' -symfonyTestSuite='data/bin/symfony symfony:test --trace' +composerUpdate='/usr/local/bin/composer update --prefer-dist --no-suggest --optimize-autoloader' # Parse arguments # phpVersions="${1-}" dependencyPreferences="${2-${dependencyPreferences}}" -phpTestRuntime="${3-${symfonyTestSuite}}" script () { @@ -34,17 +31,16 @@ script () echo $0 ${1} ${2} echo ${dcexec} ${1} php data/bin/check_configuration.php - ${dcexec} ${1} php ${phpTestRuntime} + ${dcexec} ${1} php /usr/local/bin/composer test } scriptAll () { for dependencyPreference in ${dependencyPreferences} do - install_${dependencyPreference} - for phpVersion in ${phpVersions} do + install_${dependencyPreference} ${phpVersion} script ${phpVersion} ${dependencyPreference} done done @@ -54,33 +50,32 @@ fetchAllPHPVersions () { docker-compose 2>/dev/null ps --services --filter status=running \ | grep php \ - | sort \ - | grep -v ${skipPHPVersions} + | sort } install_highest () { - ${installSubmodule} --remote - ${dcexec} composer ${composerUpdate} + ${dcexec} ${1} git config --global --add safe.directory /app + ${dcexec} ${1} ${installSubmodule} --remote + ${dcexec} ${1} ${composerUpdate} } install_lowest () { - reset_submodules + reset_submodules ${1} - ${installSubmodule} - ${dcexec} composer ${composerUpdate} --prefer-lowest + ${dcexec} ${1} ${installSubmodule} + ${dcexec} ${1} ${composerUpdate} --prefer-lowest } reset_submodules () { - git submodule deinit --force --quiet -- . - - git submodule init + ${dcexec} ${1} 'git submodule deinit --force --quiet -- .' + ${dcexec} ${1} 'git submodule init' } echo '+ docker-compose build' -docker-compose up -d --build --remove-orphans > /dev/null +docker-compose up -d --build --remove-orphans test x"" != x"${phpVersions}" || { phpVersions=`fetchAllPHPVersions` diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 000000000..92582ad54 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,73 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; + +// setup expected test environment (per check_configuration.php) +ini_set('magic_quotes_runtime', 'off'); +ini_set('session.auto_start', 'off'); +ini_set('arg_separator.output', '&'); +ini_set('allow_url_fopen', 'on'); + +require_once __DIR__.'/../vendor/autoload.php'; + +$libDir = realpath(__DIR__.'/../lib'); + +require_once __DIR__.'/../lib/config/sfConfig.class.php'; +sfConfig::set('sf_symfony_lib_dir', $libDir); + +require_once $libDir.'/autoload/sfCoreAutoload.class.php'; +sfCoreAutoload::register(); + +require_once $libDir.'/util/sfToolkit.class.php'; +sfConfig::set('sf_test_cache_dir', sys_get_temp_dir().'/sf_test_project'); + +// TODO enable later require_once __DIR__.'/fixtures/symfony/config/ProjectConfiguration.class.php'; + +// remove all test cache +sf_unit_test_shutdown(); + +// create test cache dir +$sf_root_dir = sys_get_temp_dir().'/sf_test_project'; +@mkdir($sf_root_dir, 0777, true); + +register_shutdown_function('sf_unit_test_shutdown'); + +function sf_unit_test_shutdown() +{ + $sf_root_dir = sys_get_temp_dir().'/sf_test_project'; + if (is_dir($sf_root_dir)) { + sfToolkit::clearDirectory($sf_root_dir); + @rmdir($sf_root_dir); + } + + $sessions = glob(sys_get_temp_dir().'/sessions*'); + $tmp_files = glob(sys_get_temp_dir().'/sf*'); + + $files = array_merge(empty($sessions) ? array() : $sessions, empty($tmp_files) ? array() : $tmp_files); + foreach ($files as $file) { + if (is_dir($file)) { + sfToolkit::clearDirectory($file); + @rmdir($file); + } else { + @unlink($file); + } + } +} + +// Helper for cross platform testcases that validate output +function fix_linebreaks($content) +{ + return str_replace(array("\r\n", "\n", "\r"), "\n", $content); +} + +if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) { + DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER')); +}