Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Mockery as m;
- use Way\Tests\Factory;
- use Madserver\Tests\TestCase;
- class BannersTest extends TestCase {
- public function __construct()
- {
- $this->mock = m::mock('Eloquent', 'Banner');
- $this->collection = m::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();
- }
- public function setUp()
- {
- parent::setUp();
- $this->attributes = Way\Tests\Factory::banner(['id' => 1]);
- $this->app->instance('Banner', $this->mock);
- }
- public function tearDown()
- {
- m::close();
- }
- public function testIndex()
- {
- $this->mock->shouldReceive('all')->once()->andReturn($this->collection);
- $this->call('GET', 'banners');
- $this->assertViewHas('banners');
- }
- public function testCreate()
- {
- $this->call('GET', 'banners/create');
- $this->assertResponseOk();
- }
- public function testStore()
- {
- $this->mock->shouldReceive('create')->once();
- $this->validate(true);
- $this->call('POST', 'banners');
- $this->assertRedirectedToRoute('banners.index');
- }
- public function testStoreFails()
- {
- $this->mock->shouldReceive('create')->once();
- $this->validate(false);
- $this->call('POST', 'banners');
- $this->assertRedirectedToRoute('banners.create');
- $this->assertSessionHasErrors();
- $this->assertSessionHas('message');
- }
- public function testShow()
- {
- $this->mock->shouldReceive('findOrFail')
- ->with(1)
- ->once()
- ->andReturn($this->attributes);
- $this->call('GET', 'banners/1');
- $this->assertViewHas('banner');
- }
- public function testEdit()
- {
- $this->collection->id = 1;
- $this->mock->shouldReceive('find')
- ->with(1)
- ->once()
- ->andReturn($this->collection);
- $this->call('GET', 'banners/1/edit');
- $this->assertViewHas('banner');
- }
- public function testUpdate()
- {
- $this->mock->shouldReceive('find')
- ->with(1)
- ->andReturn(m::mock(['update' => true]));
- $this->validate(true);
- $this->call('PATCH', 'banners/1');
- $this->assertRedirectedTo('banners/1');
- }
- public function testUpdateFails()
- {
- $this->mock->shouldReceive('find')->with(1)->andReturn(m::mock(['update' => true]));
- $this->validate(false);
- $this->call('PATCH', 'banners/1');
- $this->assertRedirectedTo('banners/1/edit');
- $this->assertSessionHasErrors();
- $this->assertSessionHas('message');
- }
- public function testDestroy()
- {
- $this->mock->shouldReceive('find')->with(1)->andReturn(m::mock(['delete' => true]));
- $this->call('DELETE', 'banners/1');
- }
- protected function validate($bool)
- {
- Validator::shouldReceive('make')
- ->once()
- ->andReturn(m::mock(['passes' => $bool]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement