 [ ← blog / phpstorm ](/) Jun 04, 2020  ·  \#phpstorm  ·  2 min read 

# Boost your test writing productivity with PHPUnit for PhpStorm



I write a lot of tests for all of my Drupal code. I try to live by Test Driven Development. It delivers cleaner code. It helps define your architecture without full implementation details. I also *despise* clicking and manually testing things.

However, testing in Drupal is still somewhat painful. **Time**. Since so many things require the database tests can get slow. Even the `Kernel` test suite which uses a most minimally bootstrapped environment.

Because of this, I'm a huge fan of using mocked objects. If you're not familiar with mocking in tests, check out the Drupal.org [documentation for using Prophecy](https://www.drupal.org/docs/testing/phpunit-in-drupal/using-prophecy) and the [PHPUnit documentation](https://phpunit.readthedocs.io/en/9.1/test-doubles.html). The one "problem" was always having PhpStorm give warnings about type errors for mocked objects.

But, earlier this week, I finally installed the [PHPUnit Enhancement plugin](https://plugins.jetbrains.com/plugin/9674-phpunit-enhancement), and my mind is blown 🤩

Once you have called `$this->prophesize` on a class or interface you will see autocomplete suggestions for the mocked item.

     ![Mocked class](/sites/default/files/styles/large/public/2020-06/Screen%20Shot%202020-06-04%20at%202.59.15%20PM.png?itok=_sNElbPB) 

 

It gets *even better*. After you pick a method from that mocked item, it will autocomplete the Prophecy mocking methods. 😱

     ![mocked methods autocomplete](/sites/default/files/styles/large/public/2020-06/Screen%20Shot%202020-06-04%20at%202.59.27%20PM.png?itok=xDAtsb77) 

 

I don't know why I waited so long to install this.

My methods now understand the object returned by `reveal()` matches the expected interfaces. I have also learned about some new things in Prophecy that I haven't used.

 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

Sponsoring Jeff Geerling's work

 ](/blog/sponsoring-jeff-geerlings-work) [Newer →

Hugs Not Mace

 ](/blog/hugs-not-mace)