Skip to content

Commit 6463304

Browse files
committed
Unify mail related tests for *nix and Windows
Currently mail related tests are split for *nix and Windows (if there are even Windows versions). The basic difference is that the *nix variants set the INI directive sendmail_path to just write the email to disk, while the Windows tests use ext/imap. The latter tests are way more verbose, and such duplicated tests are generally a pain point. Furthermore, the Windows tests are much slower, and could not be run without ext/imap being available. We therefore introduce a small fakemail application, which basically works like `tee <path> >/dev/null`, and which will be shipped with the Windows tests packs. fakemail.exe would also need to be added to the PHP binary SDK, so these tests could be run during developments. To cater to the remaining differences, we also introduce support for `{MAIL:<path>}` placeholders in the INI sections to run-tests.php. How to use this can be seen in mail_basic.phpt, which is currently the only modified test case, because these tests are yet supposed to fail on Windows, due to the missing fakemail.exe in the PHP SDK.
1 parent 0a9bdd6 commit 6463304

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ php
213213
/main/config.w32.h
214214
/win32/build/deplister.exe
215215
/win32/build/deplister.obj
216+
/win32/build/fakemail.exe
217+
/win32/build/fakemail.obj
216218
/win32/*.aps
217219
/win32/*.positions
218220
/win32/*.suo

ext/standard/tests/mail/mail_basic.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
--TEST--
22
Test mail() function : basic functionality
33
--INI--
4-
sendmail_path=tee mailBasic.out >/dev/null
4+
sendmail_path={MAIL:mailBasic.out}
55
mail.add_x_header = Off
6-
--SKIPIF--
7-
<?php
8-
if(substr(PHP_OS, 0, 3) == "WIN")
9-
die("skip Won't run on Windows");
10-
?>
116
--FILE--
127
<?php
138
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])

run-tests.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,12 @@ function run_test($php, $file, $env)
21092109
if (array_key_exists('INI', $section_text)) {
21102110
$section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']);
21112111
$section_text['INI'] = str_replace('{TMP}', sys_get_temp_dir(), $section_text['INI']);
2112+
if (PHP_OS_FAMILY === 'Windows') {
2113+
$replacement = 'fakemail $1';
2114+
} else {
2115+
$replacement = 'tee $1 >/dev/null';
2116+
}
2117+
$section_text['INI'] = preg_replace('/{MAIL:(\S+)}/', $replacement, $section_text['INI']);
21122118
settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings);
21132119
}
21142120

win32/build/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ build-snap: set-tmp-env generated_files
203203
-for %T in ($(EXT_TARGETS)) do $(MAKE) /I /nologo "%T"
204204
-for %T in ($(PECL_TARGETS)) do $(MAKE) /I /nologo "%T"
205205

206-
build-dist: $(BUILD_DIR)\deplister.exe
206+
build-dist: $(BUILD_DIR)\deplister.exe $(BUILD_DIR)\fakemail.exe
207207
-rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
208208
-rd /s /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
209209
-del /f /q $(BUILD_DIR)\$(DIST_ZIP_SNAP)
@@ -227,6 +227,9 @@ snap: build-snap build-devel build-dist
227227
$(BUILD_DIR)\deplister.exe: win32\build\deplister.c
228228
$(CC) /nologo /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\deplister.exe win32\build\deplister.c imagehlp.lib
229229

230+
$(BUILD_DIR)\fakemail.exe: win32\build\fakemail.c
231+
$(CC) /nologo /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\fakemail.exe win32\build\fakemail.c
232+
230233
install: really-install install-sdk
231234

232235
build-lib: build-ext-libs

win32/build/fakemail.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| http://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: Christoph M. Becker <[email protected]> |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
/* This program can be used as sendmail replacement to write the email contents
18+
to a file, which is mainly useful for email related tests on Windows.
19+
Usage: fakemail <path> */
20+
21+
#include <stdio.h>
22+
23+
int main(int argc, char *argv[])
24+
{
25+
FILE *out;
26+
char c;
27+
28+
if (argc != 2) {
29+
return 1;
30+
}
31+
if (!(out = fopen(argv[1], "w"))) {
32+
return 1;
33+
}
34+
while ((c = getchar()) != EOF) {
35+
putc(c, out);
36+
}
37+
fclose(out);
38+
39+
return 0;
40+
}

win32/build/mkdist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ function make_phar_dot_phar($dist_dir)
497497
copy_test_dir($dir, $test_dir);
498498
}
499499
copy('run-tests.php', $test_dir . '/run-test.php');
500+
copy($build_dir . '/fakemail.exe', $test_dir . '/fakemail.exe');
500501

501502
/* change this next line to true to use good-old
502503
* hand-assembled go-pear-bundle from the snapshot template */

0 commit comments

Comments
 (0)