Skip to content

Commit

Permalink
Use fake sendmail script for TravisCI builds
Browse files Browse the repository at this point in the history
This avoids 'sh: 1: /usr/sbin/sendmail: not found' error message
displayed after PHPUnit suite execution, as sendmail is not installed on
Travis.

Note: This is not a "real" error and does not actually cause the build
to fail, but it could lead someone reviewing the build's log to think
that something went wrong, so it should be fixed to avoid confusion.

The fakesendmail.sh script was copied from PHPMailer's test suite [1].
It will generate a .eml file in /tmp/fakemail directory, each time
the test suite sends an email.

[1]: https://github.com/PHPMailer/PHPMailer/blob/v6.8.0/test/fakesendmail.sh
  • Loading branch information
dregad committed Aug 14, 2023
1 parent a4e075c commit 752f7d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -20,6 +20,13 @@ install:
before_script:
# Ignore E_DEPRECATED notices when running PHP 8.1 builds
- if php -r "exit( (int)! version_compare( '$TRAVIS_PHP_VERSION', '8.1', '>=' ) );"; then echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/mantis_php81.ini; fi

# sendmail replacement
- chmod +x "$TRAVIS_BUILD_DIR/tests/fakesendmail.sh"
- echo 'sendmail_path = $TRAVIS_BUILD_DIR/tests/fakesendmail.sh' > ./tests/sendmail.ini
- phpenv config-add ./tests/sendmail.ini

# MantisBT setup
- ./build/travis_before_script.sh

script:
Expand Down
22 changes: 22 additions & 0 deletions tests/fakesendmail.sh
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#Fake sendmail script, adapted from:
#https://github.com/mrded/MNPP/blob/ee64fb2a88efc70ba523b78e9ce61f9f1ed3b4a9/init/fake-sendmail.sh

#Create a temp folder to put messages in
numPath="${TMPDIR-/tmp/}fakemail"
umask 037
mkdir -p ${numPath}

if [ ! -f ${numPath}/num ]; then
echo "0" > ${numPath}/num
fi
num=`cat ${numPath}/num`
num=$((${num} + 1))
echo ${num} > ${numPath}/num

name="${numPath}/message_${num}.eml"
while read line
do
echo ${line} >> ${name}
done
exit 0

0 comments on commit 752f7d3

Please sign in to comment.