Skip to content

Commit

Permalink
Merge pull request #437 from lucatume/fix-436
Browse files Browse the repository at this point in the history
Conditionally include new PHPMailer if available.
  • Loading branch information
lucatume authored Aug 19, 2020
2 parents 0323640 + f65e76e commit 24d880e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes after version 1.6.16 to this project will be documented in t
This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased
### Fixed

- avoid deprecation notices when loading `MockPHPMailer`, fixes #436

## [2.6.7] 2020-08-14;

Expand Down
32 changes: 29 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ PROJECT_NAME = $(notdir $(PWD))
# Suppress `make` own output.
.SILENT:

# Define what targets should always run.
.PHONY: docker_pull lint sniff fix fix_n_sniff phpstan pre_commit clean docs check_exports build_suites test debug major minor patch

# PUll all the Docker images this repository will use in building images or running processes.
docker_pull:
images=( \
Expand All @@ -31,13 +28,15 @@ docker_pull:
for image in "$${images[@]}"; do \
docker pull "$$image"; \
done;
.PHONY: docker_pull

# Lint the project source files to make sure they are PHP 5.6 compatible.
lint:
docker run --rm -v ${PWD}:/project lucatume/parallel-lint-56 \
--colors \
--exclude /project/src/tad/WPBrowser/Traits/_WithSeparateProcessChecksPHPUnitGte70.php \
/project/src
.PHONY: lint

# Use the PHP Code Sniffer container to sniff the relevant source files.
sniff:
Expand All @@ -48,6 +47,7 @@ sniff:
--standard=phpcs.xml $(SRC) \
--ignore=src/data,src/includes,src/tad/scripts,src/tad/WPBrowser/Compat \
src
.PHONY: sniff

# Use the PHP Code Beautifier container to fix the source and tests code.
fix:
Expand All @@ -58,15 +58,18 @@ fix:
--standard=phpcs.xml $(SRC) \
--ignore=src/data,src/includes,src/tad/scripts,_build \
src tests
.PHONY: fix

# Fix the PHP code, then sniff it.
fix_n_sniff: fix sniff
.PHONY: fix_n_sniff

# Use phpstan container to analyze the source code.
# Configuration will be read from the phpstan.neon.dist file.
PHPSTAN_LEVEL?=2
phpstan:
docker run --rm -v ${PWD}:/project lucatume/wpstan analyze -l ${PHPSTAN_LEVEL}
.PHONY: phpstan

# Clean the project Docker containers, volumes and networks.
clean:
Expand All @@ -84,6 +87,7 @@ clean:
|| echo "No networks found".
echo "Removing .bak files." && rm -f *.bak
echo "Emptying tests/_output directory." && rm -rf tests/_output && mkdir tests/_output && echo "*" > tests/_output/.gitignore
.PHONY: clean

# Produces the Modules documentation in the docs/modules folder.
docs: composer.lock src/Codeception/Module
Expand Down Expand Up @@ -114,10 +118,12 @@ docs: composer.lock src/Codeception/Module
# Prints a list of files that will be exported from the project on package pull.
check_exports:
bash ./_build/check_exports.sh
.PHONY: check_exports

build_suites:
DOCKER_RUN_USER=$$(id -u) DOCKER_RUN_GROUP=$$(id -g) XDE=0 TEST_SUBNET=27 \
docker-compose --project-name=${PROJECT_NAME}_build run --rm codeception build
.PHONY: build_suites

test:
DOCKER_RUN_USER=$$(id -u) DOCKER_RUN_GROUP=$$(id -g) XDEBUG_DISABLE=1 TEST_SUBNET=128 \
Expand Down Expand Up @@ -171,24 +177,31 @@ test:
DOCKER_RUN_USER=$$(id -u) DOCKER_RUN_GROUP=$$(id -g) XDEBUG_DISABLE=1 TEST_SUBNET=144 \
docker-compose --project-name=${PROJECT_NAME}_isolated \
run --rm ccf run isolated
.PHONY: test

ready:
test -f "${PWD}/.ready" && echo $$(<${PWD}/.ready) || echo "No .ready file found."
.PHONY: ready

major:
_build/release.php major
.PHONY: major

minor:
_build/release.php minor
.PHONY: minor

patch:
_build/release.php patch
.PHONY: patch

composer_hash_bump:
sh "${PWD}/_build/composer-hash.sh"
.PHONY: composer_hash_bump

# Run a set of checks on the code before commit.
pre_commit: lint fix sniff docs
.PHONY: pre_commit

test_56:
DOCKER_RUN_USER=$$(id -u) DOCKER_RUN_GROUP=$$(id -g) XDEBUG_DISABLE=1 TEST_SUBNET=89 \
Expand Down Expand Up @@ -239,6 +252,7 @@ test_56:
DOCKER_RUN_USER=$$(id -u) DOCKER_RUN_GROUP=$$(id -g) XDEBUG_DISABLE=1 TEST_SUBNET=104 \
docker-compose --project-name=${PROJECT_NAME}_isolated \
run --rm cc56 run isolated
.PHONY: test_56

# A variable target to debug issues in a PHP 5.6 environment.
debug:
Expand All @@ -247,6 +261,7 @@ debug:
-f docker-compose.debug.yml \
run --rm \
cc56 shell
.PHONY: debug

# A variable target to debug issues in a PHP 7.2 environment.
debug_7:
Expand All @@ -255,13 +270,24 @@ debug_7:
-f docker-compose.debug.yml \
run --rm \
codeception shell
.PHONY: debug_7

# Populate the vendor/wordpres/wordpress directory.
setup_wp:
TEST_SUBNET=200 \
_build/dc.sh --project-name=${PROJECT_NAME}_setup_wordpress \
-f docker-compose.debug.yml \
up -d wordpress
.PHONY: setup_wp

# Remove the current WordPress installation, if any, and set it up again.
refresh_wp:
rm -rf vendor/wordpress/wordpress && \
_build/dc.sh --project-name=${PROJECT_NAME}_refresh_wp \
-f docker-compose.yml \
run --rm cli wp core download
.PHONY: refresh_wp

build_debug:
docker-compose -f docker-compose.yml -f docker-compose.debug.yml build
.PHONY: build_debug
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ services:
user: ${DOCKER_RUN_USER:-}:${DOCKER_RUN_GROUP:-}
networks:
test:
ipv4_address: 172.${TEST_SUBNET:-28}.1.1
# Make the WordPress files source directory world writeable, readable and executable, then exit.
entrypoint: [ "chmod", "-R" ,"a+rwx", "/usr/src/wordpress" ]
volumes:
Expand Down Expand Up @@ -215,3 +214,8 @@ services:
volumes:
- .:/project:cached
- wordpress:/project/vendor/wordpress/wordpress:cached

cli :
image: wordpress:cli
volumes:
- ./vendor/wordpress/wordpress:/var/www/html
13 changes: 12 additions & 1 deletion src/includes/mock-mailer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php
require_once( ABSPATH . '/wp-includes/class-phpmailer.php' );
// phpcs:disable
if ( file_exists( ABSPATH . '/wp-includes/PHPMailer/PHPMailer.php' ) ) {
// WordPress >= 5.5, replicate the aliasing logic here.
require_once ABSPATH . '/wp-includes/PHPMailer/PHPMailer.php';
require_once ABSPATH . '/wp-includes/PHPMailer/Exception.php';
class_alias( PHPMailer\PHPMailer\PHPMailer::class, 'PHPMailer' );
class_alias( PHPMailer\PHPMailer\Exception::class, 'phpmailerException' );
} else {
// WordPress < 5.5, use the pre-5.5 class name.
require_once( ABSPATH . '/wp-includes/class-phpmailer.php' );
}
// phpcs:enable

class MockPHPMailer extends PHPMailer {
var $mock_sent = array();
Expand Down
2 changes: 0 additions & 2 deletions src/tad/WPBrowser/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ function process($cmd = [], $cwd = null, $env = null)
* @param string|array $command The command line to parse, if in array format it will not be modified.
*
* @return array The parsed command line, in array format. Untouched if originally already an array.
*
* @uses \Symfony\Component\Process\Process To parse and escape the command line.
*/
function buildCommandline($command)
{
Expand Down

0 comments on commit 24d880e

Please sign in to comment.