Skip to content

Commit

Permalink
Improve testcase coverage.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jul 8, 2014
1 parent 7946777 commit 1e03987
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Testbench/Testing/UnitAssertionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php namespace Orchestra\Testbench\Testing;

use Illuminate\Support\Fluent;
use Illuminate\View\View;
use Mockery as m;

trait UnitAssertionTrait
{
public function testAssertResponseOkMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('getResponse')->once()->andReturnSelf()
->shouldReceive('getStatusCode')->once()->andReturn(200)
->shouldReceive('isOk')->once()->andReturn(true);

$this->assertResponseOk();
}

public function testAssertResponseStatusMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');

$client->shouldReceive('getResponse')->once()->andReturnSelf()
->shouldReceive('getStatusCode')->once()->andReturn(400);

$this->assertResponseStatus(400);
}

public function testAssertViewHasMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', [
'foo' => 'bar',
'hello' => 'world',
]);

$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewHas('foo');
$this->assertViewHas('hello', 'world');
}

public function testAssertViewHasAllMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', [
'foo' => 'bar',
'bar' => 'foo',
]);
$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewHas(['foo', 'bar', 'foo' => 'bar']);
}

public function testAssertViewMissingMethod()
{
$this->client = $client = m::mock('\Illuminate\Foundation\Testing\Client');
$view = new View(m::mock('\Illuminate\View\Factory'), m::mock('\Illuminate\View\Engines\EngineInterface'), 'hello', '/var/laravel/views', []);
$response = new Fluent([
'original' => $view,
]);

$client->shouldReceive('getResponse')->once()->andReturn($response);

$this->assertViewMissing('foo');
}
}
10 changes: 10 additions & 0 deletions tests/Traits/BehatPHPAssertionsTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace Orchestra\Testbench\TestCase\Traits;

use Mockery as m;
use Orchestra\Testbench\Testing\UnitAssertionTrait;
use Orchestra\Testbench\Traits\BehatPHPUnitAssertionsTrait;

class BehatPHPAssertionsTraitTest extends \PHPUnit_Framework_TestCase
{
use BehatPHPUnitAssertionsTrait, UnitAssertionTrait;
}
10 changes: 10 additions & 0 deletions tests/Traits/PHPUnitAssertionsTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace Orchestra\Testbench\TestCase\Traits;

use Mockery as m;
use Orchestra\Testbench\Testing\UnitAssertionTrait;
use Orchestra\Testbench\Traits\PHPUnitAssertionsTrait;

class PHPUnitAssertionsTraitTest extends \PHPUnit_Framework_TestCase
{
use PHPUnitAssertionsTrait, UnitAssertionTrait;
}

0 comments on commit 1e03987

Please sign in to comment.