<commit_before>---
layout: post
title: Auto Complete with PHPSpec
summary: Unit testing with PHPSpec is GREAT! Unfortunately it is missing some nice to haves
comments: true
---

What is **PHPSpec**, from their documentation:

> phpspec is a tool which can help you write clean and working PHP code using behaviour driven development or BDD. BDD is a technique derived from test-first development.

> BDD is a technique used at story level and spec level. phpspec is a tool for use at the spec level or SpecBDD. The technique is to first use a tool like phpspec to describe the behaviour of an object you are about to write. Next you write just enough code to meet that specification and finally you refactor this code.

This is not an introduction to **PHPSpec**, this assumes you already know & use **PHPSpec**. When using **PHPSpec** you will notice that because of the *magic* the Class Under Test (CUT) does not auto complete. This is easily fixed with using **PHPStorm's** *Mixin* Annotation (`@mixin \Class\Name`).

Doing this will turn this screenshot:

![Without intellisense on PHPSpec CUT](/assets/2015-05-10-phpspec-auto-complete/phpspec-no-itellisense.png)

Into this:

![With intellisense on PHPSpec CUT](/assets/2015-05-10-phpspec-auto-complete/phpspec-with-itellisense.png)

Thus giving the usual IDE intellisense / code completion on the CUT with **PHPSpec**.

*Note: using PHPStorm v8, PHPSpec v2*

### Reference: Information discovered by [@schrotty](https://twitter.com/schrotty) at [@PHPUCEU](https://twitter.com/phpuceu)

---

### You will notice that the PHPSpec methods are not auto completing.

There is yet to be a clean solution to this.

The best solution to date for this is to put a *mixin* on the CUT (class under test) to a template class which contains the **PHPSpec** mthods. Hopefully a better solution will present itself in the near future.

Simple example (namespaces removed for simplicity):

```php
/**
 * Class Dashboard
 *
 * @mixin Template
 */<commit_msg>Changed `&` to and<commit_after>---
layout: post
title: Auto Complete with PHPSpec
summary: Unit testing with PHPSpec is GREAT! Unfortunately it is missing some nice to haves
comments: true
---

What is **PHPSpec**, from their documentation:

> phpspec is a tool which can help you write clean and working PHP code using behaviour driven development or BDD. BDD is a technique derived from test-first development.

> BDD is a technique used at story level and spec level. phpspec is a tool for use at the spec level or SpecBDD. The technique is to first use a tool like phpspec to describe the behaviour of an object you are about to write. Next you write just enough code to meet that specification and finally you refactor this code.

This is not an introduction to **PHPSpec**, this assumes you already know and use **PHPSpec**. When using **PHPSpec** you will notice that because of the *magic* the Class Under Test (CUT) does not auto complete. This is easily fixed with using **PHPStorm's** *Mixin* Annotation (`@mixin \Class\Name`).

Doing this will turn this screenshot:

![Without intellisense on PHPSpec CUT](/assets/2015-05-10-phpspec-auto-complete/phpspec-no-itellisense.png)

Into this:

![With intellisense on PHPSpec CUT](/assets/2015-05-10-phpspec-auto-complete/phpspec-with-itellisense.png)

Thus giving the usual IDE intellisense / code completion on the CUT with **PHPSpec**.

*Note: using PHPStorm v8, PHPSpec v2*

### Reference: Information discovered by [@schrotty](https://twitter.com/schrotty) at [@PHPUCEU](https://twitter.com/phpuceu)

---

### You will notice that the PHPSpec methods are not auto completing.

There is yet to be a clean solution to this.

The best solution to date for this is to put a *mixin* on the CUT (class under test) to a template class which contains the **PHPSpec** mthods. Hopefully a better solution will present itself in the near future.

Simple example (namespaces removed for simplicity):

```php
/**
 * Class Dashboard
 *
 * @mixin Template
 */
{'fraction_non_alphanumeric': 0.08293779665251062, 'fraction_numerical': 0.008993255058705971, 'mean_word_length': 4.367292225201072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4727980', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1139, 'n_words': 561}