You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-4Lines changed: 83 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,89 @@ $bundles = [
26
26
```
27
27
28
28
## Generate unit-tests from service classes
29
-
From time to time it happens that a dev looses the strict tests-first pattern and writes a service
30
-
without a proper test, and later on he wants to add a phpunit-test for this service.
31
-
Your service probably has some dependencies in the constructor, and now you have to setup mocks for that.
29
+
From time to time it happens that a dev is confronted with a brownfield service that has no unit-test, and wants to fix that. If the service has a lot of dependencies in the constructor, preparing the mocks for that can be really annoying (yes, the clean solution is to split the service to smaller parts with nice and easy-to-mock constructor). Anyways, if you are in a situation where you want to add a proper test for a monster-service, this tool can be ver handy.
30
+
31
+
Lets say you have a simple service like this:
32
+
33
+
```php
34
+
<?php
35
+
namespace Tps\UtilBundle\Tests\Fixtures;
36
+
37
+
use Doctrine\ORM\EntityManager;
38
+
use Symfony\Bundle\TwigBundle\TwigEngine;
39
+
use Symfony\Component\Form\Form;
40
+
41
+
class ExampleClass {
42
+
/**
43
+
* @var EntityManager
44
+
*/
45
+
private $testForm;
46
+
/**
47
+
* @var TwigEngine
48
+
*/
49
+
private $templating;
50
+
/**
51
+
* @var string
52
+
*/
53
+
private $primitiveParameter;
54
+
55
+
public function __construct(Form $testForm, TwigEngine $templating, $primitiveParameter)
56
+
{
57
+
$this->testForm = $testForm;
58
+
$this->templating = $templating;
59
+
$this->primitiveParameter = $primitiveParameter;
60
+
}
61
+
[...]
62
+
```
63
+
32
64
To generate a base template for a service test, run the command
0 commit comments