Skip to content

Commit

Permalink
Merge pull request #25 from ostrolucky/psalm-template
Browse files Browse the repository at this point in the history
Make stubs more SA-friendly via @template
  • Loading branch information
Naktibalda authored Jul 3, 2020
2 parents a3ba014 + 3bb924a commit 468dd5f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
31 changes: 18 additions & 13 deletions src/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class Stub
* ], $this);
* ```
*
* @param mixed $class - A class to be mocked
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $params - properties and methods to set
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object - mock
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType - mock
* @throws \RuntimeException when class does not exist
* @throws \Exception
*/
Expand Down Expand Up @@ -159,13 +160,13 @@ public static function factory($class, $num = 1, $params = [])
* 'save' => \Codeception\Stub\Expected::once()
* ], $this);
* ```
*
* @param mixed $class
* @template
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param string $method
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/
public static function makeEmptyExcept($class, $method, $params = [], $testCase = false)
Expand Down Expand Up @@ -240,11 +241,12 @@ function ($m) {
* ], $this);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/
public static function makeEmpty($class, $params = [], $testCase = false)
Expand Down Expand Up @@ -322,12 +324,13 @@ public static function copy($obj, $params = [])
* ], $this);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $constructorParams
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/
public static function construct($class, $constructorParams = [], $params = [], $testCase = false)
Expand Down Expand Up @@ -381,12 +384,13 @@ public static function construct($class, $constructorParams = [], $params = [],
* ], $this);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $constructorParams
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
*/
public static function constructEmpty($class, $constructorParams = [], $params = [], $testCase = false)
{
Expand Down Expand Up @@ -446,13 +450,14 @@ function ($i) {
* ], $this);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param string $method
* @param array $constructorParams
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
*/
public static function constructEmptyExcept(
$class,
Expand Down
33 changes: 18 additions & 15 deletions src/Test/Feature/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ protected function stubEnd($status, $time)
* $this->make('User', ['save' => function () { return true; }]);
* $this->make('User', ['save' => true]);
* ```
*
* @param mixed $class - A class to be mocked
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $params - properties and methods to set
*
* @return object - mock
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType - mock
* @throws \RuntimeException when class does not exist
* @throws \Exception
*/
Expand Down Expand Up @@ -118,14 +118,14 @@ public function make($class, $params = [])
* $this->makeEmpty('User', ['save' => true));
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/

public function makeEmpty($class, $params = [])
{
return $this->mocks[] = \Codeception\Stub::makeEmpty($class, $params, $this);
Expand Down Expand Up @@ -161,11 +161,12 @@ public function makeEmpty($class, $params = [])
* $this->makeEmptyExcept('User', 'save', ['isValid' => true]);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param string $method
* @param array $params
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/
public function makeEmptyExcept($class, $method, $params = [])
Expand Down Expand Up @@ -204,12 +205,13 @@ public function makeEmptyExcept($class, $method, $params = [])
* ?>
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $constructorParams
* @param array $params
* @param bool|\PHPUnit\Framework\TestCase $testCase
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
* @throws \Exception
*/
public function construct($class, $constructorParams = [], $params = [])
Expand Down Expand Up @@ -254,13 +256,13 @@ public function construct($class, $constructorParams = [], $params = [])
* ]);
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param array $constructorParams
* @param array $params
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
*/

public function constructEmpty($class, $constructorParams = [], $params = [])
{
return $this->mocks[] = \Codeception\Stub::constructEmpty($class, $constructorParams, $params, $this);
Expand Down Expand Up @@ -297,12 +299,13 @@ public function constructEmpty($class, $constructorParams = [], $params = [])
* ?>
* ```
*
* @param mixed $class
* @template RealInstanceType of object
* @param class-string<RealInstanceType>|RealInstanceType|callable(): class-string<RealInstanceType> $class - A class to be mocked
* @param string $method
* @param array $constructorParams
* @param array $params
*
* @return object
* @return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
*/
public function constructEmptyExcept($class, $method, $constructorParams = [], $params = [])
{
Expand Down

0 comments on commit 468dd5f

Please sign in to comment.