Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

InvalidArgumentException: Return values of type 'Swift_Message' must be explicitly specified. #147

Description

@darianbr

The following code will cause an exception because function bar has defined a custom return type.

Example class: Foo.php

class Foo {
    function bar($value): Swift_Message
    {
        return new Swift_Message();
    }
}

Unit Test: FooTest.php
The below code causes the following exception: InvalidArgumentException: Return values of type 'Swift_Message' must be explicitly specified.

public function setUp()
{
    $message = Phony::mock(Swift_Message::class);
    $foo = Phony::mock(Foo::class);
    $foo->bar('x')->returns($message->mock());  // Causes InvalidArgumentException
}

But adding this line (bar method without parameters) will make the above code work.

public function setUp()
{
    $message = Phony::mock(Swift_Message::class);
    $foo = Phony::mock(Foo::class);
    $foo->bar->returns($message->mock());        // stubbing will now work
    $foo->bar('x')->returns($message->mock());  // no longer causes exception
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions