Jimmix
Jimmix

Reputation: 6506

PHP Prophecy mocking not existing class

I'm writing a package that I would like to write tests in Prophecy instead of Mockery. The package class Bar has a method sayName that requires an object implementing FooInterface as a parameter.

with Mockery there is no problem for creating a mock of non existing class:

<?php
use \Prophecy\Prophet;
use \Mockery;

class Bar 
{
    public function sayName(\FooInterface $foo)
    {
        echo $foo->test();
    }
}

$mock = Mockery::mock('Foo', 'FooInterface');
$mock->shouldReceive('test')->times(1)->andReturn('This is a mock test');

$bar = new Bar();
$bar->sayName($mock);

gives:

This is a mock test

How to achieve the same with Prophecy?

Upvotes: 1

Views: 305

Answers (0)

Related Questions