Skip to content

Instantly share code, notes, and snippets.

@flyingluscas
Last active March 14, 2017 01:55
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/e2ab418298339bef38d0bad70db528ab to your computer and use it in GitHub Desktop.
Save flyingluscas/e2ab418298339bef38d0bad70db528ab to your computer and use it in GitHub Desktop.
PHPUnit: Mocking Trait
use PHPUnit\Framework\TestCase;

trait Greeting
{
    public function hello($name)
    {
        return 'Hello '.$name;
    }
}

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

        $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