{"id":824,"date":"2024-05-17T15:28:23","date_gmt":"2024-05-17T19:28:23","guid":{"rendered":"https:\/\/sites.bu.edu\/marcom-team\/?page_id=824"},"modified":"2025-10-30T13:31:38","modified_gmt":"2025-10-30T17:31:38","slug":"common-situations-for-developers","status":"publish","type":"page","link":"https:\/\/sites.bu.edu\/marcom-team\/departments\/interactive-design\/role-specific-info\/info-for-developers\/common-situations-for-developers\/","title":{"rendered":"VVV PHP Storm, PHP Unit Testing"},"content":{"rendered":"<h1><span style=\"color: #ff0000;\"><strong>NOTE &#8211; This information is archival and no longer supported.<\/strong><\/span><\/h1>\n<hr \/>\n<p><span style=\"font-weight: 400;\">Unit Testing Code is a best practice for writing code. This page will focus on how to setup PHP Storm with PHP Unit using VVV.<\/span><\/p>\n<p>VVV is an open source local development environment focused on<span>\u00a0<\/span><a href=\"https:\/\/wordpress.org\/\">WordPress<\/a>, powered by<span>\u00a0<\/span><a href=\"https:\/\/www.vagrantup.com\/\">Vagrant<\/a> and is ideal for developing themes and plugins as well as for<span>\u00a0<\/span><a href=\"https:\/\/make.wordpress.org\/core\/\">contributing to WordPress core<\/a>.<\/p>\n<h3><strong>Step 1: Install VVV<\/strong><\/h3>\n<p>Visit <a href=\"https:\/\/varyingvagrantvagrants.org\/\"><span style=\"font-weight: 400;\">varyingvagrantvagrants.org<\/span><\/a>, or their git respository at <a href=\"https:\/\/github.com\/Varying-Vagrant-Vagrants\/VVV\"><span style=\"font-weight: 400;\">github.com\/Varying-Vagrant-Vagrants\/VVV<\/span><\/a>.<\/p>\n<p><span style=\"font-weight: 400;\">VVV instructions will walk you through installing dependencies for VVV including Vagrant and Virtual Box. VVV includes PHP Unit and a WordPress specific set up for using WP Unit Tests.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Step 2: Configure PHP Storm<\/strong><\/h3>\n<div class=\" bu-callout alignright\"><\/p>\n<h5><strong>Make sure VVV, PHP Storm and all their dependencies are up to date before beginning and that your\u00a0VVV is running with Vagrant Up command before doing the following.<\/strong><\/h5>\n<p><\/div>\n<p><span style=\"font-weight: 400;\">Several pieces of information on how to complete this setup were found on <a href=\"https:\/\/make.xwp.co\/2016\/04\/21\/running-phpunit-tests-with-vvv-and-phpstorm\/\">this blog post<\/a><\/span><span style=\"font-weight: 400;\">. However, that post deals with an older version of PHP Storm and VVV, so please extrapolate the details from that post and the information below to your current version of PHP Storm and VVV.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h5><strong>Add PHP CLI interpreter<\/strong><\/h5>\n<ol>\n<li><span style=\"font-weight: 400;\">Go to <strong>Preferences<\/strong> &gt; <strong>Language &amp; Frameworks<\/strong> &gt; <strong>PHP<\/strong><\/span><\/li>\n<li><span style=\"font-weight: 400;\">In the dialog, select the ellipsis[<code>\u2026<\/code>] in the CLI Interpreter Box.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select <strong>Vagrant<\/strong>.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Add the path to the root of your Vagrant Instance and click <strong>Apply<\/strong>.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">The general section should automatically populate.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<h5><strong>Tell PHP Storm Where to Load PHP Unit From<\/strong><\/h5>\n<p><span style=\"font-weight: 400;\"><div class=\" bu-callout alignright\"><\/span><\/p>\n<h5><strong>Note: This file path is only accessible inside the virtual machine.<\/strong><\/h5>\n<p><\/div><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">Go to <strong>Preferences<\/strong> &gt; <strong>Language &amp; Frameworks<\/strong> &gt; <strong>PHP<\/strong> &gt; <strong>Test Frameworks<\/strong><\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select \u201c<strong>Use Composer Autoloader<\/strong>\u201d<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select the path to the script<br \/>\n<span><code>\/usr\/local\/src\/composer\/vendor\/autoload.php<\/code><\/span><\/span><\/li>\n<li>Click <strong>Apply<\/strong> and the path mapping will populate automatically.<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<h5><strong>Setup PHP Test Runner Configuration<\/strong><\/h5>\n<div class=\" bu-callout alignright\"><\/p>\n<h5><strong>This file path is shared between the Virtual Environment and your local computer. Change the Username to your appropriate name. YOU MUST git clone your theme or plugin into this shared file path before being able to select it.<\/strong><\/h5>\n<p><\/div>\n<p><span style=\"font-weight: 400;\">For each project:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400;\">Open the project you are working on, and from the menu bar choose the \u201c<strong>Edit Configurations<\/strong>\u201d option.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click <strong>+<\/strong> and add a new PHP Unit configuration and a name for the Project.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select \u201c<strong>Defined in Configuration File<\/strong>\u201d<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Select \u201c<strong>Use Alternative Configuration File<\/strong>\u201d<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Point to the configuration file within the root of the theme or plugin.<br \/>\n[code] <code>\/Users\/alanam\/vagrant-local\/www\/wordpress-trunk\/public_html\/src\/wp-content\/themes\/responsive-framework\/phpunit.xml.dist<\/code>[\/code]<\/span><\/li>\n<li>From the same screen click the folder icon for \u201c<strong>Environment Variables<\/strong>\u201d<\/li>\n<li>Add a constant that points to where PHP Unit should load for this test.<br \/>\n[code] <span style=\"font-weight: 400;\"><code>WP_TESTS_DIR = \/srv\/www\/wordpress-trunk\/public_html\/tests\/phpunit\/<\/code><\/span> [\/code]<\/li>\n<\/ol>\n<div class=\" bu-callout alignright\"><\/p>\n<h5><strong>This folder is accessible through the shared files with the virtual machine or via the server path only on the virtual machine. The example shows the server path on the virtual machine and should be selected.<\/strong><\/h5>\n<p><\/div>\n<p style=\"padding-left: 40px;\"><span style=\"font-weight: 400;\">8. Set the password and database name for the test to run in.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h5>Maintenance &amp; Advisory<\/h5>\n<p><span style=\"font-weight: 400;\">In the root directory of the WordPress Develop branch instance of VVV, the same place you will typically find the wp-config.php file you will find a <code>wp-tests-config-sample.php<\/code> file. Copy this to the <code>wp-tests-config.php<\/code> and update the database name and password for that of the standard VVV password names. For some reason, this is not setup by default inside of VVV. See listing of default credentials. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can use the <code>PHPMYADMIN<\/code> screen within VVV to confirm the database name for testing. As of this writing, the default test database with VVV is <code>wordpress_unit_tests<\/code>. <a href=\"https:\/\/varyingvagrantvagrants.org\/docs\/en-US\/default-credentials\/\">This article in VVV&#8217;s docs has further info<\/a>.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\"><em>Deep Breath<\/em>: <\/span><span style=\"font-weight: 400;\"><strong>Now you are ready to run tests! <\/strong><\/span><span style=\"font-weight: 400;\">Select the green <strong>Play<\/strong> button within the menu bar and you&#8217;re off!<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<div class=\" bu-callout aligncenter\"><\/p>\n<h3>Additional Tips<\/h3>\n<h5><strong>Note: To run as multisite edit the <code>wp-tests-config.php<\/code> and uncomment the multisite code.<\/strong><\/h5>\n<p>[code]<\/p>\n<p>&amp;lt;span class=&#8221;s1&#8243;&amp;gt; \/\/ Test with multisite enabled.&amp;lt;\/span&amp;gt;<\/p>\n<p>&amp;lt;span class=&#8221;s1&#8243;&amp;gt; \/\/ Alternatively, use the tests\/phpunit\/multisite.xml configuration file.&amp;lt;\/span&amp;gt;<\/p>\n<p>&amp;lt;span class=&#8221;s1&#8243;&amp;gt;define( &#8216;WP_TESTS_MULTISITE&#8217;, true );&amp;lt;\/span&amp;gt;<\/p>\n<p>[\/code]<\/p>\n<p><span style=\"font-weight: 400;\">Note: There is a conflict in responsive-framework with the code below with Travis test vs local tests on single site install tests. Comment this code out to get successful tests run on local single instances of WordPress.<\/span><\/p>\n<p>[code]<\/p>\n<p>\/**<\/p>\n<p>* Before WordPress version 4.7, the theme&#8217;s functions.php file needs to be included manually.<\/p>\n<p>* This only needs to be done when running as multisite. *\/<\/p>\n<p>if ( ! function_exists( &#8216;responsive_init&#8217; ) &amp;amp;&amp;amp; ! is_multisite() ) {<\/p>\n<p style=\"padding-left: 40px;\">global $wp_version;<\/p>\n<p style=\"padding-left: 40px;\">if ( 1 &amp;gt; version_compare( &#8216;4.7&#8217;, $wp_version ) ) {<\/p>\n<p style=\"padding-left: 80px;\">require_once( dirname( dirname( __FILE__ ) ) . &#8216;\/functions.php&#8217; );<\/p>\n<p>[\/code]<\/p>\n<p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>NOTE &#8211; This information is archival and no longer supported. Unit Testing Code is a best practice for writing code. This page will focus on how to setup PHP Storm with PHP Unit using VVV. VVV is an open source local development environment focused on\u00a0WordPress, powered by\u00a0Vagrant and is ideal for developing themes and plugins [&hellip;]<\/p>\n","protected":false},"author":12906,"featured_media":0,"parent":230,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/pages\/824"}],"collection":[{"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/users\/12906"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/comments?post=824"}],"version-history":[{"count":21,"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/pages\/824\/revisions"}],"predecessor-version":[{"id":4075,"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/pages\/824\/revisions\/4075"}],"up":[{"embeddable":true,"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/pages\/230"}],"wp:attachment":[{"href":"https:\/\/sites.bu.edu\/marcom-team\/wp-json\/wp\/v2\/media?parent=824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}