Last active
December 16, 2015 04:49
-
-
Save JeffreyWay/5380399 to your computer and use it in GitHub Desktop.
I've been spending a lot of time lately figuring out how to make testing as simple as possible. Mocking is a sore point for lots of folks. What do you think of this, for more natural mocking?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function testIndex() | |
{ | |
// Mock the Dog class | |
// Expect all() method to be called | |
// and return 'foo' | |
$this->dog->all()->shouldReturn('foo'); | |
// Call /dogs (DB won't be hit) | |
$this->call('GET', '/dogs'); | |
// Make sure view has $dogs var | |
$this->assertViewHas('dogs', 'foo'); | |
} | |
public function testShow() | |
{ | |
// Mock the Dog class | |
// Expect find() method to be called | |
// with argument, 1 | |
// and return 'foo'' | |
$this->dog->find(1)->shouldReturn('foo'); | |
$this->call('GET', '/dogs/1'); | |
$this->assertViewHas('dog', 'foo'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I decided to extend it just a bit to allow people to write the mocks however they wish.
All of the same will achieve the same result: