]> granicus.if.org Git - php/commitdiff
Unify mail related tests for *nix and Windows
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 5 Jan 2020 15:46:27 +0000 (16:46 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Thu, 9 Jan 2020 11:04:28 +0000 (12:04 +0100)
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.

.gitignore
ext/standard/tests/mail/mail_basic.phpt
run-tests.php
win32/build/Makefile
win32/build/fakemail.c [new file with mode: 0644]
win32/build/mkdist.php

index 587f4abc42593c96e70cd485591673647ba263b5..39f001a67e248ab0edede640c0c5d55ceb06c9fd 100644 (file)
@@ -213,6 +213,8 @@ php
 /main/config.w32.h
 /win32/build/deplister.exe
 /win32/build/deplister.obj
+/win32/build/fakemail.exe
+/win32/build/fakemail.obj
 /win32/*.aps
 /win32/*.positions
 /win32/*.suo
index 9afef0b65a063d2146a19cdf613549e81f0747d6..fb8cb58e847c33dd7cd04d20cc26806cc83248f4 100644 (file)
@@ -1,13 +1,8 @@
 --TEST--
 Test mail() function : basic functionality
 --INI--
-sendmail_path=tee mailBasic.out >/dev/null
+sendmail_path={MAIL:mailBasic.out}
 mail.add_x_header = Off
---SKIPIF--
-<?php
-if(substr(PHP_OS, 0, 3) == "WIN")
-  die("skip Won't run on Windows");
-?>
 --FILE--
 <?php
 /* Prototype  : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
index b73f6c9355a972ce5c387447f04dfc6fe9e8415a..8ea737e1e4ad07df737edaa926c51fdb96f526cb 100755 (executable)
@@ -2109,6 +2109,12 @@ TEST $file
        if (array_key_exists('INI', $section_text)) {
                $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']);
                $section_text['INI'] = str_replace('{TMP}', sys_get_temp_dir(), $section_text['INI']);
+               if (PHP_OS_FAMILY === 'Windows') {
+                       $replacement = 'fakemail $1';
+               } else {
+                       $replacement = 'tee $1 >/dev/null';
+               }
+               $section_text['INI'] = preg_replace('/{MAIL:(\S+)}/', $replacement, $section_text['INI']);
                settings2array(preg_split("/[\n\r]+/", $section_text['INI']), $ini_settings);
        }
 
index a6b54c07ff3d9b52ee1ec783fb774c576fae884c..6df5b966e31c9edde53dddf0a161889b294bdf8e 100644 (file)
@@ -203,7 +203,7 @@ build-snap: set-tmp-env generated_files
        -for %T in ($(EXT_TARGETS)) do $(MAKE) /I /nologo "%T"
        -for %T in ($(PECL_TARGETS)) do $(MAKE) /I /nologo "%T"
 
-build-dist: $(BUILD_DIR)\deplister.exe
+build-dist: $(BUILD_DIR)\deplister.exe $(BUILD_DIR)\fakemail.exe
        -rd /s /q $(BUILD_DIR)\php-$(PHP_VERSION_STRING)
        -rd /s /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)
        -del /f /q $(BUILD_DIR)\$(DIST_ZIP_SNAP)
@@ -227,6 +227,9 @@ snap: build-snap build-devel build-dist
 $(BUILD_DIR)\deplister.exe:    win32\build\deplister.c
        $(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
 
+$(BUILD_DIR)\fakemail.exe:     win32\build\fakemail.c
+       $(CC) /nologo /Fo$(BUILD_DIR)\ /Fd$(BUILD_DIR)\ /Fp$(BUILD_DIR)\ /FR$(BUILD_DIR) /Fe$(BUILD_DIR)\fakemail.exe win32\build\fakemail.c
+
 install: really-install install-sdk
 
 build-lib: build-ext-libs
diff --git a/win32/build/fakemail.c b/win32/build/fakemail.c
new file mode 100644 (file)
index 0000000..6a24c47
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  +----------------------------------------------------------------------+
+  | Copyright (c) The PHP Group                                          |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.01 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available through the world-wide-web at the following url:           |
+  | http://www.php.net/license/3_01.txt                                  |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Christoph M. Becker <cmb@php.net>                            |
+  +----------------------------------------------------------------------+
+*/
+
+/* This program can be used as sendmail replacement to write the email contents
+   to a file, which is mainly useful for email related tests on Windows. 
+   Usage: fakemail <path> */
+
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+    FILE *out;
+    char c;
+
+    if (argc != 2) {
+        return 1;
+    }
+    if (!(out = fopen(argv[1], "w"))) {
+        return 1;
+    }
+    while ((c = getchar()) != EOF) {
+        putc(c, out);
+    }
+    fclose(out);
+
+    return 0;
+}
index f4155308af93dc1bcfe154e9664baf3092697d03..0995c8f7cfe978adecf39a6c92020b38eda397bf 100644 (file)
@@ -497,6 +497,7 @@ foreach ($dirs as $dir) {
        copy_test_dir($dir, $test_dir);
 }
 copy('run-tests.php', $test_dir . '/run-test.php');
+copy($build_dir . '/fakemail.exe', $test_dir . '/fakemail.exe');
 
 /* change this next line to true to use good-old
  * hand-assembled go-pear-bundle from the snapshot template */