Skip to content

Commit 3bb924a

Browse files
committed
Make stubs more SA-friendly via @template
1 parent a3ba014 commit 3bb924a

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

src/Stub.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ class Stub
5252
* ], $this);
5353
* ```
5454
*
55-
* @param mixed $class - A class to be mocked
55+
* @template RealInstanceType of object
56+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
5657
* @param array $params - properties and methods to set
5758
* @param bool|\PHPUnit\Framework\TestCase $testCase
5859
*
59-
* @return object - mock
60+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType - mock
6061
* @throws \RuntimeException when class does not exist
6162
* @throws \Exception
6263
*/
@@ -159,13 +160,13 @@ public static function factory($class, $num = 1, $params = [])
159160
* 'save' => \Codeception\Stub\Expected::once()
160161
* ], $this);
161162
* ```
162-
*
163-
* @param mixed $class
163+
* @template
164+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
164165
* @param string $method
165166
* @param array $params
166167
* @param bool|\PHPUnit\Framework\TestCase $testCase
167168
*
168-
* @return object
169+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
169170
* @throws \Exception
170171
*/
171172
public static function makeEmptyExcept($class, $method, $params = [], $testCase = false)
@@ -240,11 +241,12 @@ function ($m) {
240241
* ], $this);
241242
* ```
242243
*
243-
* @param mixed $class
244+
* @template RealInstanceType of object
245+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
244246
* @param array $params
245247
* @param bool|\PHPUnit\Framework\TestCase $testCase
246248
*
247-
* @return object
249+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
248250
* @throws \Exception
249251
*/
250252
public static function makeEmpty($class, $params = [], $testCase = false)
@@ -322,12 +324,13 @@ public static function copy($obj, $params = [])
322324
* ], $this);
323325
* ```
324326
*
325-
* @param mixed $class
327+
* @template RealInstanceType of object
328+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
326329
* @param array $constructorParams
327330
* @param array $params
328331
* @param bool|\PHPUnit\Framework\TestCase $testCase
329332
*
330-
* @return object
333+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
331334
* @throws \Exception
332335
*/
333336
public static function construct($class, $constructorParams = [], $params = [], $testCase = false)
@@ -381,12 +384,13 @@ public static function construct($class, $constructorParams = [], $params = [],
381384
* ], $this);
382385
* ```
383386
*
384-
* @param mixed $class
387+
* @template RealInstanceType of object
388+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
385389
* @param array $constructorParams
386390
* @param array $params
387391
* @param bool|\PHPUnit\Framework\TestCase $testCase
388392
*
389-
* @return object
393+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
390394
*/
391395
public static function constructEmpty($class, $constructorParams = [], $params = [], $testCase = false)
392396
{
@@ -446,13 +450,14 @@ function ($i) {
446450
* ], $this);
447451
* ```
448452
*
449-
* @param mixed $class
453+
* @template RealInstanceType of object
454+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
450455
* @param string $method
451456
* @param array $constructorParams
452457
* @param array $params
453458
* @param bool|\PHPUnit\Framework\TestCase $testCase
454459
*
455-
* @return object
460+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
456461
*/
457462
public static function constructEmptyExcept(
458463
$class,

src/Test/Feature/Stub.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ protected function stubEnd($status, $time)
7777
* $this->make('User', ['save' => function () { return true; }]);
7878
* $this->make('User', ['save' => true]);
7979
* ```
80-
*
81-
* @param mixed $class - A class to be mocked
80+
* @template RealInstanceType of object
81+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
8282
* @param array $params - properties and methods to set
8383
*
84-
* @return object - mock
84+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType - mock
8585
* @throws \RuntimeException when class does not exist
8686
* @throws \Exception
8787
*/
@@ -118,14 +118,14 @@ public function make($class, $params = [])
118118
* $this->makeEmpty('User', ['save' => true));
119119
* ```
120120
*
121-
* @param mixed $class
121+
* @template RealInstanceType of object
122+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
122123
* @param array $params
123124
* @param bool|\PHPUnit\Framework\TestCase $testCase
124125
*
125-
* @return object
126+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
126127
* @throws \Exception
127128
*/
128-
129129
public function makeEmpty($class, $params = [])
130130
{
131131
return $this->mocks[] = \Codeception\Stub::makeEmpty($class, $params, $this);
@@ -161,11 +161,12 @@ public function makeEmpty($class, $params = [])
161161
* $this->makeEmptyExcept('User', 'save', ['isValid' => true]);
162162
* ```
163163
*
164-
* @param mixed $class
164+
* @template RealInstanceType of object
165+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
165166
* @param string $method
166167
* @param array $params
167168
*
168-
* @return object
169+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
169170
* @throws \Exception
170171
*/
171172
public function makeEmptyExcept($class, $method, $params = [])
@@ -204,12 +205,13 @@ public function makeEmptyExcept($class, $method, $params = [])
204205
* ?>
205206
* ```
206207
*
207-
* @param mixed $class
208+
* @template RealInstanceType of object
209+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
208210
* @param array $constructorParams
209211
* @param array $params
210212
* @param bool|\PHPUnit\Framework\TestCase $testCase
211213
*
212-
* @return object
214+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
213215
* @throws \Exception
214216
*/
215217
public function construct($class, $constructorParams = [], $params = [])
@@ -254,13 +256,13 @@ public function construct($class, $constructorParams = [], $params = [])
254256
* ]);
255257
* ```
256258
*
257-
* @param mixed $class
259+
* @template RealInstanceType of object
260+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
258261
* @param array $constructorParams
259262
* @param array $params
260263
*
261-
* @return object
264+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
262265
*/
263-
264266
public function constructEmpty($class, $constructorParams = [], $params = [])
265267
{
266268
return $this->mocks[] = \Codeception\Stub::constructEmpty($class, $constructorParams, $params, $this);
@@ -297,12 +299,13 @@ public function constructEmpty($class, $constructorParams = [], $params = [])
297299
* ?>
298300
* ```
299301
*
300-
* @param mixed $class
302+
* @template RealInstanceType of object
303+
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
301304
* @param string $method
302305
* @param array $constructorParams
303306
* @param array $params
304307
*
305-
* @return object
308+
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
306309
*/
307310
public function constructEmptyExcept($class, $method, $constructorParams = [], $params = [])
308311
{

0 commit comments

Comments
 (0)