Skip to content

Instantly share code, notes, and snippets.

@flyingluscas
Created March 14, 2017 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flyingluscas/b21e51960741b36b0633c98541f1d88d to your computer and use it in GitHub Desktop.
Save flyingluscas/b21e51960741b36b0633c98541f1d88d to your computer and use it in GitHub Desktop.
PHPUnit: Mocking Interface
use PHPUnit\Framework\TestCase;

interface Greeting
{
    public function hello($name);
}

class GreetingTest extends TestCase
{
    public function testSayHello()
    {
        $greeting = $this->getMockForAbstractClass(Greeting::class);

        $greeting->method('hello')->will($this->returnValue('Hello Lucas'));

        $this->assertEquals('Hello Lucas', $greeting->hello('Lucas'));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment