# Local Classic + PHPUnit + PhpStorm

**URL:** <https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203>\
**Category:** Workflow\
**Tags:** phpunit, phpstorm, local-classic\
**Created:** [April 20, 2018, 5:45pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203 "2018-04-20T17:45:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [April 20, 2018, 5:45pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/1 "2018-04-20T17:45:14Z")

</div>

**Note!** This is an involved tutorial, and is focused on Local Classic (Version [3.3.0](https://localwp.com/releases/3.3.0) and earlier).

We plan on drastically streamlining the PHPUnit experience with Local in future versions.

* * *

# Requirements

- [Local 2.3.0](https://local.getflywheel.com/community/t/local-by-flywheel-2-3-0-pre-release/6163) or newer
- [Local Ports Add-on](https://github.com/getflywheel/local-addon-ports)

* * *

### Step 1: Map the SSH Port

In order to access SSH inside the Local container, port `22` needs to be exposed. This is done using the [Local Ports Add-on](https://github.com/getflywheel/local-addon-ports).

1. Navigate to the site in Local
2. Click More » Ports
3. Add a port for `SSH` pointing to `22`
4. Click “Remap Ports”
5. **Note the Host Port of the newly added SSH port. We will reference this later.** In this case, it’s `4008`.

 ![26%20AM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/3/35e5a1d7721f0ee5da3cdabc05f1a59fe591a9b4.png)

* * *

### Step 2: Install OpenSSH Server in the site’s container:

1. Right-click on the site in Local’s sidebar
2. Click “Open Site SSH” (If you’re curious, “Open Site SSH” isn’t true SSH, it’s attaching to a TTY)
3. Run `apt-get update && apt-get install -y openssh-server`

 ![14%20AM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/3/361ebadbca0fea59b559f2c77b35512698e7f168.jpg)

1. Run the follow command to tell OpenSSH to start when the site is [re]started: `sed -i "/service mysql start/aservice ssh start" /etc/scripts/startup.sh`
2. Change the `root` password to `root` by running: `passwd` and then entering `root` twice.
3. Allow the `root` user to log in with SSH by running the following: `sed -i "s/PermitRootLogin without-password/PermitRootLogin yes/" /etc/ssh/sshd_config`
4. **Restart the site in Local**

 ![13%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/1/119861e65b5444760a510c3754acf54ca326e2ae.jpg)

* * *

### Step 3: Install PHPUnit in the site’s container

**Reference:** [PHPUnit – Make WordPress Core](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/)

_(If you still have the site’s SSH terminal window open, skip to #3 below)_

1. Right-click on the site in Local’s sidebar
2. Click “Open Site SSH”
3. Run `wget https://phar.phpunit.de/phpunit-6.5.phar && chmod +x phpunit-6.5.phar && mv phpunit-6.5.phar /usr/local/bin/phpunit`
4. Run `phpunit --version` to verify that PHPUnit was installed correctly

 ![25%20AM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/4/42437a871b753c63e72afe880b251d9a03b4b434.png)

* * *

### Step 4: Configure PhpStorm

1. Navigate to PhpStorm » Preferences » Languages & Frameworks » PHP

 ![58%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/b/b6b270026dc8ae3297afcd0e3059289884ac1a0a.png)

1. Click `...` beside CLI Interpreter to open the following window

 ![42%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/9/9bcedad1375fbd20cc0ac2a1c0ef9fd0791ea862.jpg)

1. Click the `+` button and then go to "From Docker, Vagrant, VM, Remote…` (if this option is not available, you may need to enable the Remote PHP Interpreter plugin in PhpStorm) ![51%20PM](https://sea1.discourse-cdn.com/flex019/images/transparent.png)

2. Enter the following details:

- **Host:** This can be found by going to the site in Local and then copying the “Remote Host” option in the “Database” tab
- **Port:** See Step #1.5 at the beginning of this article
- **User name:** `root`
- **Password:** `root`
- **PHP interpreter path:** `/usr/local/bin/php`

1. Hit OK then Apply

2. Change the PHP language level option to whatever matches the PHP version that the Local site is running

3. Click on `...` beside “Path mapping”

4. Map the site’s `public` folder in the project to `/app/public`

 ![18%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/5/5f7cc12be088d61b779cc1254f24b4c1daf15cf4.jpg)

1. When you’re done adding the CLI Interpreter and Path Mappings, it should look something like this. Make sure you hit Apply.

 ![23%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/5/5dea70e3d151209c2a815f8f1306850c7a678fca.png)

1. Go to Languages & Frameworks » PHP » Test Frameworks and click the `+` to add a new Test Framework

2. Select the newly created Interpreter

 ![53%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/b/b0844c224f66dd3fbec2d861bbbc2c9a17bb9824.jpg)

1. Select “Path to phpunit.phar” under “PHPUnit library”

2. Enter `/usr/local/bin/phpunit` for “Path to phpunit.phar”

 ![06%20PM](https://us1.discourse-cdn.com/flex019/uploads/lwpforums/original/2X/4/4205139697993b740073b79cc4a6e16ddfc2f799.png)

1. Hit Apply and close the Preferences

* * *

### Using PHPUnit!

In this case I’m checking out `wordpress-develop` and running the `phpunit.xml.dist` file. See [PHPUnit – Make WordPress Core](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/).

https:/uploads/lwpforums/original/2X/d/d37b0070c5f4d2b775f04c5887cd0aa23d4003db.webm

---

<div class="post-metadata">

**Author:** ![alexstandiford](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/alexstandiford/32/4926_2.png) [@alexstandiford](https://community.localwp.com/u/alexstandiford)\
**Post date:** [May 9, 2018, 4:25pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/2 "2018-05-09T16:25:05Z")

</div>

Thank you Clay. While I went through this, I decided to take notes on the issues I ran into to help anyone who’s going through these steps.

**Problem 1** :  
When I ran `phpunit --verison`, I ran into this error:  
`cannot use PHPUnit\Framework\MockObject\Stub as Stub because the name is already in use in phar:///usr/local/bin/phpunit/phpunit-mock-objects/Builder/InvocationMocker.php on line 16`

**Solution 1:**  
And I resolved it by updating my PHP version to 7.1.4.

**Problem 2** :  
After clicking "From Docker, Vagrant, VM, Remote I didn’t see “Host”, “User Name”, etc…

**Solution 2** :  
I had to click the **SSH Credentials** radio button to display these configurations

**Problem 3** :  
It wasn’t clear to me that I needed to click "PHPUnit By Remote Interpreter on step 11

**Solution 3** :  
Well, I clicked on “PHPUnit By Remote Interpreter” before moving on to step 11 🙂

**Problem 4** :  
I was getting errors on step 13.

**Solution 4** :  
This was solved, again, by using PHP 7.1.4

---

<div class="post-metadata">

**Author:** ![JJJ](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/jjj/32/5110_2.png) [@JJJ](https://community.localwp.com/u/JJJ)\
**Post date:** [September 21, 2018, 2:37am UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/3 "2018-09-21T02:37:59Z")

</div>

This seems broken in Local 2.4.0.

I got to step 4 (Click “Remap Ports”) and now it just says “Provisioning” with no indicator that anything is happening.

Stuff I also did:

- Fully restarted my Mac.
- VirtualBox version 5.2.18 r124319 (Qt5.6.3)
- Updated Xcode to 10 (also tried 10.1 beta)

The logs haven’t been updated in 10+ minutes, which I’ll take as an indication that it’s hung up on something:

```
Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom] Empty /etc/mysql
Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom] Copying MySQL config to container prior to starting.
Sep 20, 2018, 9:28 PM CDT - info: [main/waitForFile] Waiting for /conf/php/7.2.0/etc/php-fpm.conf c7a3fc178a3456574ae80167a555156d941199f0a38d1773d081f2def739e409
Sep 20, 2018, 9:28 PM CDT - info: [main/waitForFile] /conf/php/7.2.0/etc/php-fpm.conf exists
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] getRouterContainers()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] teardown()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] Removing router container 2afa58d51be84875b1b51621c30c6ec94d3c4dd6bce42c6a5f715bc7f4bb428c
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] updateProxyManager()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] runContainer()
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-network-manager] removeExistingNetworks
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-network-manager] createNetwork
Sep 20, 2018, 9:28 PM CDT - info: [EnvironmentCustom] Starting php-fpm done
Sep 20, 2018, 9:28 PM CDT - info: [main/docker-router] reconnectNetwork()
```

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [September 21, 2018, 8:02pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/4 "2018-09-21T20:02:39Z")

</div>

Hey @JJJ,

Are you still running into this issue? I wasn’t able to reproduce it with Custom or Preferred on Local 2.4.0.

---

<div class="post-metadata">

**Author:** ![nyrsimon](https://avatars.discourse-cdn.com/v4/letter/n/9de053/32.png) [@nyrsimon](https://community.localwp.com/u/nyrsimon)\
**Post date:** [September 23, 2018, 7:10pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/5 "2018-09-23T19:10:05Z")

</div>

Hi Clay,

I’m experiencing exactly the same: I hit Remap ports and it spins on ‘Provisioning’ forever…

I’m running on Local 2.4.0 on a Windows10 machine.

Any thoughts???

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [September 26, 2018, 9:28pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/6 "2018-09-26T21:28:35Z")

</div>

Simon,

Sorry about that! It’s tough to say what’s going on without more details.

Can you please provide your `local-by-flywheel.log` file? See [How do I retrieve Local's log file?](https://local.getflywheel.com/community/t/how-do-i-retrieve-locals-log-file/3720?u=clay) for instructions on how to do so.

---

<div class="post-metadata">

**Author:** ![davide.prevosto](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/davide.prevosto/32/4602_2.png) [@davide.prevosto](https://community.localwp.com/u/davide.prevosto)\
**Post date:** [October 6, 2018, 1:56pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/7 "2018-10-06T13:56:12Z")

</div>

…and the same here. Mac OS X Mojave, Local 2.4.2, VirtualBox 5.2.18  
Provisioning forever.

---

<div class="post-metadata">

**Author:** ![davide.prevosto](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/davide.prevosto/32/4602_2.png) [@davide.prevosto](https://community.localwp.com/u/davide.prevosto)\
**Post date:** [October 6, 2018, 1:57pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/8 "2018-10-06T13:57:12Z")

</div>

@JJJ Have you solved it in any way?

---

<div class="post-metadata">

**Author:** ![Reskator](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@Reskator](https://community.localwp.com/u/Reskator)\
**Post date:** [October 8, 2018, 2:53pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/9 "2018-10-08T14:53:19Z")

</div>

I want to clarify that it works for me.  
(MacPro under Mac OS X Mojave, LBF 2.4.2, VirtualBox 5.2.18)

Maybe your problems come from elsewhere.

---

<div class="post-metadata">

**Author:** ![davidshq](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/davidshq/32/5766_2.png) [@davidshq](https://community.localwp.com/u/davidshq)\
**Post date:** [October 28, 2018, 10:02pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/10 "2018-10-28T22:02:28Z")

</div>

First problem I ran into was that a /etc/scripts/startup.sh file did not exist.

Next issue was that after creating it and running sed, it didn’t create any update in the file.

Any ideas?

Running 2.4.3 on Windows 10.

Thanks!

---

<div class="post-metadata">

**Author:** ![nyrsimon](https://avatars.discourse-cdn.com/v4/letter/n/9de053/32.png) [@nyrsimon](https://community.localwp.com/u/nyrsimon)\
**Post date:** [November 9, 2018, 4:27pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/11 "2018-11-09T16:27:07Z")

</div>

Hi Clay,

Sorry it’s been a while I got sidetracked but still need to set up automated testing!

Yes the problem still occurs. I’m on local 2.4.6 on Windows 10

Here is a link for the log file - I took a look but nothing obvious stuck out.  
[https://drive.google.com/file/d/17SAIXT1fC25EzZ6r6JYwkr1GzcwqVXYh/view?usp=sharing](https://drive.google.com/file/d/17SAIXT1fC25EzZ6r6JYwkr1GzcwqVXYh/view?usp=sharing)

FYI I also tried on my laptop and got exactly the same results

Any help is much aprpeciated  
Thanks

---

<div class="post-metadata">

**Author:** ![athorne](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/athorne/32/6351_2.png) [@athorne](https://community.localwp.com/u/athorne)\
**Post date:** [November 16, 2018, 3:43am UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/12 "2018-11-16T03:43:03Z")

</div>

I believe I have the same issue, stuck on Provisioning, does not go past that point.  
Also I noticed if I force quit after 20min or so and restart and try again the new port when trying to add SSH has incremented by one, i.e from 4033, 4034, 4035 each time I try and you cant change that field.

LBFW 2.4.5  
VB 5.2.20

````auto
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-machine] checking IP
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-machine] checked IP 192.168.95.100

Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom] Empty /etc/mysql
Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom] Copying MySQL config to container prior to starting.
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/waitForFile] Waiting for /conf/php/7.1.4/etc/php-fpm.conf da8509b02a193c18fa1fa75689a865fc791c8e5b5508d498b208f009eb84260b
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] getRouterContainers()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] teardown()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] Removing router container 76979bc2f905bd7e2da32b48b7789cc587933000a587cd77ef4bc2975ffadec1
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] updateProxyManager()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] runContainer()
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-network-manager] removeExistingNetworks
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-network-manager] createNetwork
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/waitForFile] /conf/php/7.1.4/etc/php-fpm.conf exists
Nov 16, 2018, 11:38 AM GMT+10 - info: [main/docker-router] reconnectNetwork()
Nov 16, 2018, 11:38 AM GMT+10 - info: [EnvironmentCustom] Starting php-fpm done```
````

---

<div class="post-metadata">

**Author:** ![VBlank](https://avatars.discourse-cdn.com/v4/letter/v/f1d935/32.png) [@VBlank](https://community.localwp.com/u/VBlank)\
**Post date:** [January 10, 2019, 7:06pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/13 "2019-01-10T19:06:33Z")

</div>

My need wasn’t for PHP unit, but searching if it was possible to connect with SSH to container. And how to do it with security (adding this possibility only for a user with a specific password …)  
As I read this tutorial carefully, I have followed Step1 and Step2 and I wonder… Isn’t it dangerous to install OpenSSH-server in a Local By Flywheel container and give the ability to connect to container with root / root ? Anyone discover your Remote Host and Port can connect with SSH and then break everything… isn’t it?  
… …  
Finally, I tried an SSH connection with an external PC to the one containing LBFW and the result is a connection timed out! So, everything is OK!!! 😊

---

<div class="post-metadata">

**Author:** ![brianhogg](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/brianhogg/32/24521_2.png) [@brianhogg](https://community.localwp.com/u/brianhogg)\
**Post date:** [February 4, 2019, 7:20pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/14 "2019-02-04T19:20:16Z")

</div>

I’m also getting the provisioning forever bug (OSX 10.14.3, Local 3.0.4). Is the ports add-on still being maintained?

---

<div class="post-metadata">

**Author:** ![alexstandiford](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/alexstandiford/32/4926_2.png) [@alexstandiford](https://community.localwp.com/u/alexstandiford)\
**Post date:** [February 14, 2019, 5:45pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/15 "2019-02-14T17:45:29Z")

</div>

Just had to do this again in 2019. My working process was:

1. Download and run this script in my local environment: [https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba](https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba)
2. Follow the steps above, but skip step 3

---

<div class="post-metadata">

**Author:** ![alexstandiford](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/alexstandiford/32/4926_2.png) [@alexstandiford](https://community.localwp.com/u/alexstandiford)\
**Post date:** [June 5, 2019, 1:07pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/16 "2019-06-05T13:07:28Z")

</div>

I just ran into this exact same issue today. The only way I was able to fix it was by completely creating a new site and starting over 😕

---

<div class="post-metadata">

**Author:** ![alexstandiford](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/alexstandiford/32/4926_2.png) [@alexstandiford](https://community.localwp.com/u/alexstandiford)\
**Post date:** [July 24, 2019, 7:36pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/17 "2019-07-24T19:36:04Z")

</div>

Current process:

1. Set up ports as detailed in step 1 above
2. open site SSH and run this script: [https://gist.github.com/alexstandiford/0728ba7b21caa323a5ecf67c6e98abd2](https://gist.github.com/alexstandiford/0728ba7b21caa323a5ecf67c6e98abd2)
3. Restart local
4. Open site SSH and run this script:  
[https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba](https://gist.github.com/keesiemeijer/a888f3d9609478b310c2d952644891ba)
5. Start on step 4 - Configure PHPStorm above.

---

<div class="post-metadata">

**Author:** ![wpalchemy](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/wpalchemy/32/9602_2.png) [@wpalchemy](https://community.localwp.com/u/wpalchemy)\
**Post date:** [March 3, 2020, 11:58pm UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/18 "2020-03-03T23:58:31Z")

</div>

The Ports extension is deprecated, and I don’t see any way to add ports in Local Lightning. Is there any way to use PHPUnit and PhpStorm with Local Lightning?

---

<div class="post-metadata">

**Author:** ![afragen](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/afragen/32/31_2.png) [@afragen](https://community.localwp.com/u/afragen)\
**Post date:** [March 4, 2020, 12:40am UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/19 "2020-03-04T00:40:38Z")

</div>

> **[afragen/setup-phpunit](https://github.com/afragen/setup-phpunit)**
>
> Setup PHPUnit for use in Local Lightning. Contribute to afragen/setup-phpunit development by creating an account on GitHub.

> **[WP Core Development with Local Lightning - Surgical Diversions](https://thefragens.com/wp-core-dev-with-local-lightning/)**
>
> Firstly, this is only meant as a how I do it. I’m using MacOS. core.git.wordpress.org It is based on using git://core.git.wordpress.org/. This would be similar to WP core development on a regular install using the WordPress Beta Tester plugin set for...

Sorry I can’t help you get setup with PhpStorm, but the above should help.

---

<div class="post-metadata">

**Author:** ![wpalchemy](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/wpalchemy/32/9602_2.png) [@wpalchemy](https://community.localwp.com/u/wpalchemy)\
**Post date:** [March 4, 2020, 1:25am UTC](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203/20 "2020-03-04T01:25:52Z")

</div>

Thanks, @afragen, but the part of the process I need help with is setting up PhpStorm.

[Next page](https://community.localwp.com/t/local-classic-phpunit-phpstorm/6203.md?page=2)
