From 1e03987345a7fc53b723a5c94f8b79e9942a25d4 Mon Sep 17 00:00:00 2001 From: crynobone Date: Tue, 8 Jul 2014 09:53:08 +0800 Subject: [PATCH] Improve testcase coverage. Signed-off-by: crynobone --- src/Testbench/Testing/UnitAssertionTrait.php | 76 ++++++++++++++++++++ tests/Traits/BehatPHPAssertionsTraitTest.php | 10 +++ tests/Traits/PHPUnitAssertionsTraitTest.php | 10 +++ 3 files changed, 96 insertions(+) create mode 100644 src/Testbench/Testing/UnitAssertionTrait.php create mode 100644 tests/Traits/BehatPHPAssertionsTraitTest.php create mode 100644 tests/Traits/PHPUnitAssertionsTraitTest.php diff --git a/src/Testbench/Testing/UnitAssertionTrait.php b/src/Testbench/Testing/UnitAssertionTrait.php new file mode 100644 index 0000000..4f1f045 --- /dev/null +++ b/src/Testbench/Testing/UnitAssertionTrait.php @@ -0,0 +1,76 @@ +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'); + } +} diff --git a/tests/Traits/BehatPHPAssertionsTraitTest.php b/tests/Traits/BehatPHPAssertionsTraitTest.php new file mode 100644 index 0000000..dc78f73 --- /dev/null +++ b/tests/Traits/BehatPHPAssertionsTraitTest.php @@ -0,0 +1,10 @@ +