Skip to content

Commit f96786d

Browse files
committed
Switch from Atoum to PHPUnit
1 parent a31a7d1 commit f96786d

33 files changed

+1040
-1288
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- '8.1'
2020
- '8.2'
2121
- '8.3'
22+
- '8.4'
2223
steps:
2324
- name: Check out repository
2425
uses: actions/checkout@v4
@@ -57,10 +58,10 @@ jobs:
5758
- name: Run PHP linter (php-cs-fixer)
5859
run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer --diff --dry-run -v fix
5960

60-
- name: Atoum tests
61+
- name: Unit tests
6162
run: |
6263
cp app/config/config.ini-ghactions app/config/config.ini
63-
vendor/atoum/atoum/bin/atoum -d tests/units/ --use-light-report
64+
php ./vendor/bin/phpunit
6465
6566
- name: Functional tests (API, pages)
6667
run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
22
.php-cs-fixer.cache
3+
.phpunit.result.cache
34
*.pyc
45
app/config/config.ini
56
app/config/sources/*.json
@@ -14,6 +15,7 @@ composer.phar
1415
logs/*.log
1516
logs/github_log.txt
1617
python-venv
18+
tests/**/*.cache
1719
vendor
1820
web/data.tar.gz
1921
web/download/.htaccess

.php-cs-fixer.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
],
2323
'encoding' => true,
2424
'full_opening_tag' => true,
25+
'method_argument_space' => [
26+
'on_multiline' => 'ignore',
27+
'keep_multiple_spaces_after_comma' => false,
28+
],
2529
'no_alias_functions' => true,
2630
'no_blank_lines_after_class_opening' => true,
2731
'no_blank_lines_after_phpdoc' => true,

app/classes/Transvision/Project.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public static function getRepositoryLocales($repository, $ignored = [])
218218
$file_name = APP_SOURCES . "{$repository}.txt";
219219
$supported_locales = [];
220220
if (file_exists($file_name)) {
221-
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
221+
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
222222
}
223223

224224
// Make sure that the reference locale is included
@@ -245,7 +245,7 @@ public static function getAllLocales()
245245
$file_name = APP_SOURCES . 'all_projects.txt';
246246
$supported_locales = [];
247247
if (file_exists($file_name)) {
248-
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
248+
$supported_locales = file($file_name, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
249249
}
250250
sort($supported_locales);
251251

app/classes/Transvision/Strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,6 @@ public static function levenshteinQuality($string1, $string2)
333333
mb_strlen($string2, 'UTF-8'),
334334
]);
335335

336-
return (float) (1 - self::levenshteinUTF8($string1, $string2) / $length) * 100;
336+
return (float) round((1 - self::levenshteinUTF8($string1, $string2) / $length) * 100, 5);
337337
}
338338
}

app/classes/Transvision/TMX.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ class TMX
1313
/**
1414
* Generate a TMX file from a data source
1515
*
16-
* @param array $strings All the strings the user picked
17-
* @param string $target_lang Locale picked from which we get translations
18-
* @param string $source_lang Source locale
16+
* @param array $strings All the strings the user picked
17+
* @param string $target_lang Locale picked from which we get translations
18+
* @param string $source_lang Source locale
19+
* @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used.
1920
*
2021
* @return mixed string that contains a TMX in xml format, False otherwise
2122
*/
22-
public static function create($strings, $target_lang, $source_lang)
23+
public static function create($strings, $target_lang, $source_lang, $time = null)
2324
{
2425
if ($strings[$target_lang] && $strings[$source_lang]) {
26+
$creationDate = $time ?? date('c');
27+
2528
$content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
2629
. '<tmx version="1.4">' . "\n"
2730
. '<header o-tmf="plain text" o-encoding="UTF8" adminlang="en"'
28-
. ' creationdate="' . date('c') . '" creationtoolversion="0.1" creationtool="Transvision"'
31+
. ' creationdate="' . $creationDate . '" creationtoolversion="0.1" creationtool="Transvision"'
2932
. ' srclang="' . $source_lang . '" segtype="sentence" datatype="plaintext">' . "\n"
3033
. '</header>' . "\n"
3134
. '<body>' . "\n";
@@ -56,21 +59,24 @@ public static function create($strings, $target_lang, $source_lang)
5659
/**
5760
* Generate a TMX file from a data source with the format of OmegaT
5861
*
59-
* @param array $strings All the strings the user picked
60-
* @param string $target_lang Locale picked from which we get translations
61-
* @param string $source_lang Source locale
62+
* @param array $strings All the strings the user picked
63+
* @param string $target_lang Locale picked from which we get translations
64+
* @param string $source_lang Source locale
65+
* @param string|null $time Optional time string (in a valid date format) to use for creationdate; if not provided, date('c') is used.
6266
*
6367
* @return mixed string that contains a TMX in xml format, False otherwise
6468
*/
65-
public static function createOmegat($strings, $target_lang, $source_lang)
69+
public static function createOmegat($strings, $target_lang, $source_lang, $time = null)
6670
{
6771
if ($strings[$target_lang] && $strings[$source_lang]) {
72+
$creationDate = $time ?? date('c');
73+
6874
$content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
6975
. '<!DOCTYPE tmx SYSTEM "tmx11.dtd">' . "\n"
7076
. '<tmx version="1.1">' . "\n"
7177
. '<header creationtool="Transvision" o-tmf="OmegaT TMX" o-encoding="UTF8"'
7278
. ' adminlang="EN-US" datatype="plaintext" creationtoolversion="0.1" segtype="paragraph"'
73-
. ' creationdate="' . date('c') . '" srclang="' . $source_lang . '">'
79+
. ' creationdate="' . $creationDate . '" srclang="' . $source_lang . '">'
7480
. '</header>' . "\n"
7581
. '<body>' . "\n";
7682

app/inc/constants.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?php
22

33
// Constants for the project
4-
define('DATA_ROOT', realpath($server_config['root']) . '/');
5-
define('HG', realpath($server_config['local_hg']) . '/');
6-
define('GIT', realpath($server_config['local_git']) . '/');
7-
define('TMX', DATA_ROOT . 'TMX/');
8-
define('INSTALL_ROOT', realpath($server_config['install']) . '/');
9-
define('APP_SOURCES', realpath($server_config['config']) . '/sources/');
10-
define('WEB_ROOT', INSTALL_ROOT . 'web/');
11-
define('APP_ROOT', INSTALL_ROOT . 'app/');
12-
define('INC', APP_ROOT . 'inc/');
13-
define('VIEWS', APP_ROOT . 'views/');
14-
define('MODELS', APP_ROOT . 'models/');
15-
define('CONTROLLERS', APP_ROOT . 'controllers/');
4+
define('DATA_ROOT', realpath($server_config['root']) . '/');
5+
define('HG', realpath($server_config['local_hg']) . '/');
6+
define('GIT', realpath($server_config['local_git']) . '/');
7+
define('TMX', DATA_ROOT . 'TMX/');
8+
define('INSTALL_ROOT', realpath($server_config['install']) . '/');
9+
define('APP_SOURCES', realpath($server_config['config']) . '/sources/');
10+
define('WEB_ROOT', INSTALL_ROOT . 'web/');
11+
define('APP_ROOT', INSTALL_ROOT . 'app/');
12+
define('INC', APP_ROOT . 'inc/');
13+
define('VIEWS', APP_ROOT . 'views/');
14+
define('MODELS', APP_ROOT . 'models/');
15+
define('CONTROLLERS', APP_ROOT . 'controllers/');
1616
define('CACHE_ENABLED', isset($_GET['nocache']) ? false : true);
17-
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
18-
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
17+
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
18+
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
1919

2020
if (php_sapi_name() != 'cli') {
21-
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
21+
define('API_ROOT', APP_SCHEME . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_QUOTES, 'UTF-8') . '/api/v1/');
2222
}
2323

2424
/*
@@ -39,14 +39,14 @@
3939
define('BETA_VERSION', $beta_version);
4040

4141
if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
42-
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
42+
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
4343
} else {
4444
// 05h20 cache (because we extract data every 6h and extraction lasts 25mn)
45-
define('CACHE_TIME', 19200);
45+
define('CACHE_TIME', 19200);
4646
}
4747

4848
// Special modes for the app
49-
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
49+
define('DEBUG', BETA_VERSION || isset($_GET['debug']));
5050
define('LOCAL_DEV', isset($server_config['dev']) && $server_config['dev']);
5151

5252
// Set perf_check=true in config.ini to log page time generation and memory used while in DEBUG mode

app/views/credits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<li>Bash for installation scripts and cron jobs</li>
1111
<li>Python for extracting strings (compare-locales)</li>
1212
<li><a href="https://getcomposer.org/">Composer</a>, a dependency manager for PHP projects</li>
13-
<li><a href="https://www.atoum.org/">Atoum</a>, a unit testing framework for PHP</li>
13+
<li><a href="https://www.phpunit.de/">PHPUnit</a>, a unit testing framework for PHP</li>
1414
<li><a href="https://www.jquery.com/">jQuery</a>, a JavaScript library</li>
1515
</ul>
1616

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
},
3333

3434
"require-dev": {
35-
"atoum/atoum" : "~4.2",
3635
"symfony/var-dumper": "~6.4",
37-
"friendsofphp/php-cs-fixer": "~3.64",
38-
"pchevrel/verif": "0.4"
36+
"friendsofphp/php-cs-fixer": "~3.75",
37+
"pchevrel/verif": "0.4",
38+
"phpunit/phpunit": "^10 || ^12"
3939
},
4040

4141
"autoload": {

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="tests/units/bootstrap.php"
3+
colors="true"
4+
displayDetailsOnTestsThatTriggerDeprecations="true"
5+
displayDetailsOnTestsThatTriggerErrors="true"
6+
displayDetailsOnTestsThatTriggerNotices="true"
7+
displayDetailsOnTestsThatTriggerWarnings="true"
8+
displayDetailsOnPhpunitDeprecations="true">
9+
<php>
10+
<!-- Report every error, warning, and notice -->
11+
<ini name="error_reporting" value="-1"/>
12+
<ini name="display_errors" value="1"/>
13+
</php>
14+
<testsuites>
15+
<testsuite name="Unit Tests">
16+
<directory>tests/units</directory>
17+
</testsuite>
18+
</testsuites>
19+
</phpunit>

0 commit comments

Comments
 (0)