FIXED: PHP Unit test issue PHP Warning/Warning/Fatal error: Failed to open stream: No such file (mock-mailer.php) for windows

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.

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

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

Show group by alphabet posts with shortcode using WP_Query

Create an array of posts group by alphabet with WP_Query.

Use below to create the list of posts array with the group by alphabet.

Note: I have used post type. You can change this post type with your own. Also, you can modify the WP_Query parameters.

Now we can show the posts with the group by alphabet with a shortcode.

In below code we have created a shortcode prefix_alphabetic_posts to show the result in the post.

NOTE: Below short code is created only for demo purpose. So, Added inline CSS. You need to use wp_enqueue_scripts to enqueue your scripts.