Failed to open stream: No such file (mock-mailer.php) for windows

Advertisement

After setup the PHP unit test on your Windows operating system maybe you get below error:

PHP Warning:  require_once(/tmp/wordpress//wp-includes/class-phpmailer.php): failed to open stream: No such file or directory in C:\Users\MaheshW\AppData\Local\Temp\wordpress-tests-lib\includes\mock-mailer.php o
n line 2
...
...
Warning: require_once(/tmp/wordpress//wp-includes/class-phpmailer.php): failed to open stream: No such file or directory in C:\Users\MaheshW\AppData\Local\Temp\wordpress-tests-lib\includes\mock-mailer.php on lin
e 2
...
...
PHP Fatal error:  require_once(): Failed opening required '/tmp/wordpress//wp-includes/class-phpmailer.php' (include_path='C:\xampp\php\PEAR') in C:\Users\MaheshW\AppData\Local\Temp\wordpress-tests-lib\includes\
mock-mailer.php on line 2
...
...
Fatal error: require_once(): Failed opening required '/tmp/wordpress//wp-includes/class-phpmailer.php' (include_path='C:\xampp\php\PEAR') in C:\Users\MaheshW\AppData\Local\Temp\wordpress-tests-lib\includes\mock-
mailer.php on line 2
...
...

In file C:\Users\MaheshW\AppData\Local\Temp\wordpress-tests-lib\wp-tests-config.php line 7 has code:

define( 'ABSPATH', '/tmp/wordpress/' );

Here, ABSPATH return the invalid path.

You can simply change the above code with below:

define( 'ABSPATH', 'C:\Users\{USERNAME}\AppData\Local\Temp/wordpress/' );

NOTE: Here change the {USERNAME} with your own user name.

To know the user name just open command prompt which shows your username.

E.g.

Failed to open stream: No such file (mock-mailer.php) for windows 1

In my case it was MaheshW so, I have change the code as below:

define( 'ABSPATH', 'C:\Users\MaheshW\AppData\Local\Temp/wordpress/' );

Leave a Reply