Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic types for ObjectProphecy #574

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Prophecy/Prophecy/ObjectProphecy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
* Object prophecy.
*
* @author Konstantin Kudryashov <[email protected]>
*
* @template-covariant T of object
* @template-implements ProphecyInterface<T>
*/
class ObjectProphecy implements ProphecyInterface
{
Expand Down Expand Up @@ -66,6 +69,10 @@ public function __construct(
* @param string $class
*
* @return $this
*
* @template U
* @phpstan-param class-string<U> $class
* @phpstan-this-out static<T&U>
*/
public function willExtend($class)
{
Expand All @@ -80,6 +87,10 @@ public function willExtend($class)
* @param string $interface
*
* @return $this
*
* @template U
* @phpstan-param class-string<U> $class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof should be $interface here, not $class

* @phpstan-this-out static<T&U>
*/
public function willImplement($interface)
{
Expand Down Expand Up @@ -108,6 +119,8 @@ public function willBeConstructedWith(array $arguments = null)
* @return object
*
* @throws \Prophecy\Exception\Prophecy\ObjectProphecyException If double doesn't implement needed interface
*
* @phpstan-return T
*/
public function reveal()
{
Expand Down
4 changes: 4 additions & 0 deletions src/Prophecy/Prophecy/ProphecyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
* Core Prophecy interface.
*
* @author Konstantin Kudryashov <[email protected]>
*
* @template-covariant T of object
*/
interface ProphecyInterface
{
/**
* Reveals prophecy object (double) .
*
* @return object
*
* @phpstan-return T
*/
public function reveal();
}
4 changes: 4 additions & 0 deletions src/Prophecy/Prophet.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function __construct(
* @param null|string $classOrInterface Class or interface name
*
* @return ObjectProphecy
*
* @template T of object
* @phpstan-param class-string<T>|null $classOrInterface
* @phpstan-return ObjectProphecy<T>
*/
public function prophesize($classOrInterface = null)
{
Expand Down