@@ -20,6 +20,187 @@ composer require rector/mockstan --dev
2020
2121<br >
2222
23+ ``` markdown
24+ ### ExplicitExpectsMockMethodRule
25+
26+ Require explicit ` expects() ` usage when setting up mocks to avoid silent stubs.
27+
28+ ``` yaml
29+ rules :
30+ - Rector\Mockstan\Rules\ExplicitExpectsMockMethodRule
31+ ` ` `
32+
33+ ` ` ` php
34+ // Bad (implicit stubbing)
35+ $mock = $this->createMock(Service::class);
36+ $mock->method('calculate')->willReturn(10);
37+ ```
38+
39+ :x :
40+
41+ ``` php
42+ // Good (explicit expects)
43+ $mock = $this->createMock(Service::class);
44+ $mock->expects($this->any())->method('calculate')->willReturn(10);
45+ ```
46+
47+ <br >
48+
49+ ### ForbiddenClassToMockRule
50+
51+ Disallow mocking of forbidden/core classes (e.g. ` \DateTime ` , framework internals).
52+
53+ ``` yaml
54+ rules :
55+ - Rector\Mockstan\Rules\ForbiddenClassToMockRule
56+ ` ` `
57+
58+ ` ` ` php
59+ // Bad
60+ $dtMock = $this->createMock(\DateTime::class);
61+ ```
62+
63+ :x :
64+
65+ ``` php
66+ // Good
67+ $dt = new \DateTime();
68+ ```
69+
70+ <br >
71+
72+ ### NoDocumentMockingRule
73+
74+ Prevent mocking of document classes (persisted models) — use real instances or factories.
75+
76+ ``` yaml
77+ rules :
78+ - Rector\Mockstan\Rules\NoDocumentMockingRule
79+ ` ` `
80+
81+ ` ` ` php
82+ // Bad
83+ $docMock = $this->createMock(App\Document\User::class);
84+ ```
85+
86+ :x :
87+
88+ ``` php
89+ // Good
90+ $user = new App\Document\User();
91+ ```
92+
93+ <br >
94+
95+ ### NoDoubleConsecutiveTestMockRule
96+
97+ Avoid creating multiple consecutive mocks in test body that indicate poor test design.
98+
99+ ``` yaml
100+ rules :
101+ - Rector\Mockstan\Rules\NoDoubleConsecutiveTestMockRule
102+ ` ` `
103+
104+ ` ` ` php
105+ // Bad
106+ $a = $this->createMock(A::class);
107+ $b = $this->createMock(B::class);
108+ ```
109+
110+ :x :
111+
112+ ``` php
113+ // Good — combine setup or use single test-specific fixture
114+ $a = $this->createMock(A::class);
115+ // configure $a as needed, or refactor test
116+ ```
117+
118+ <br >
119+
120+ ### NoEntityMockingRule
121+
122+ Do not mock entity classes (Doctrine entities); use real entity instances.
123+
124+ ``` yaml
125+ rules :
126+ - Rector\Mockstan\Rules\NoEntityMockingRule
127+ ` ` `
128+
129+ ` ` ` php
130+ // Bad
131+ $entityMock = $this->createMock(App\Entity\Product::class);
132+ ```
133+
134+ :x :
135+
136+ ``` php
137+ // Good
138+ $product = new App\Entity\Product();
139+ ```
140+
141+ <br >
142+
143+ ### NoMockObjectAndRealObjectPropertyRule
144+
145+ Disallow assigning a mock to a property while another test uses the real object on the same property.
146+
147+ ``` yaml
148+ rules :
149+ - Rector\Mockstan\Rules\NoMockObjectAndRealObjectPropertyRule
150+ ` ` `
151+
152+ ` ` ` php
153+ $this->service = $this->createMock(Service::class);
154+ $this->service = new Service();
155+ ```
156+
157+ :x :
158+
159+ ``` php
160+ // Good — keep property consistent or isolate tests
161+ $this->service = $this->createMock(Service::class);
162+
163+ // or
164+ $this->service = new Service();
165+ ```
166+
167+ :+1 :
168+
169+
170+ <br >
171+
172+ ### NoMockOnlyTestRule
173+
174+ Detect tests that only create mocks and never assert behavior — require meaningful assertions.
175+
176+ ``` yaml
177+ rules :
178+ - Rector\Mockstan\Rules\NoMockOnlyTestRule
179+ ` ` `
180+
181+ ` ` ` php
182+ // Bad
183+ public function testSomething()
184+ {
185+ $this->createMock(Dependency::class);
186+ }
187+ ```
188+
189+ :x :
190+
191+ ``` php
192+ public function testSomething()
193+ {
194+ $dep = $this->createMock(Dependency::class);
195+ $this->assertInstanceOf(Dependency::class, $dep);
196+ }
197+ ```
198+
199+ :+1 :
200+
201+
202+
203+
23204### ParamNameToTypeConventionRule
24205
25206Interface must be located in "Contract" or "Contracts" namespace
0 commit comments