From b6cb732c0cca45062289b27e240b2ff5d611063c Mon Sep 17 00:00:00 2001 From: crynobone Date: Sun, 3 Aug 2014 21:36:56 +0800 Subject: [PATCH] Improve testing traits. Signed-off-by: crynobone --- tests/Traits/MacroableTraitTest.php | 6 +++--- tests/Traits/QueryFilterTraitTest.php | 23 ++++------------------- tests/Traits/ValidationTraitTest.php | 15 +++++---------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/tests/Traits/MacroableTraitTest.php b/tests/Traits/MacroableTraitTest.php index 22efbb8..e475b23 100644 --- a/tests/Traits/MacroableTraitTest.php +++ b/tests/Traits/MacroableTraitTest.php @@ -11,7 +11,7 @@ class MacroableTraitTest extends \PHPUnit_Framework_TestCase */ public function testMacroIsExecutable() { - $stub = new Macroable; + $stub = new MacroableStub; $stub->macro('foo', function () { return 'foobar'; @@ -29,11 +29,11 @@ public function testMacroIsExecutable() */ public function testMacroThrowsExceptionWhenMacroIsntExecutable() { - with(new Macroable)->foo(); + with(new MacroableStub)->foo(); } } -class Macroable +class MacroableStub { use MacroableTrait; } diff --git a/tests/Traits/QueryFilterTraitTest.php b/tests/Traits/QueryFilterTraitTest.php index 31bc014..cdeae55 100644 --- a/tests/Traits/QueryFilterTraitTest.php +++ b/tests/Traits/QueryFilterTraitTest.php @@ -5,6 +5,8 @@ class QueryFilterTraitTest extends \PHPUnit_Framework_TestCase { + use QueryFilterTrait; + /** * Teardown the test environment. */ @@ -21,12 +23,11 @@ public function tearDown() */ public function testSetupBasicQueryFilterMethod() { - $stub = new QueryFilter; $query = m::mock('\Illuminate\Database\Query\Builder'); $query->shouldReceive('orderBy')->once()->with('updated_at', 'DESC')->andReturn($query); - $this->assertInstanceOf('\Illuminate\Database\Query\Builder', $stub->stubSetupBasicQueryFilter($query, [ + $this->assertEquals($query, $this->setupBasicQueryFilter($query, [ 'order' => 'updated', 'sort' => 'desc', ])); @@ -40,7 +41,6 @@ public function testSetupBasicQueryFilterMethod() */ public function testSetupWildcardQueryFilterMethod() { - $stub = new QueryFilter; $query = m::mock('\Illuminate\Database\Query\Builder'); $query->shouldReceive('where')->once()->with(m::type('Closure')) @@ -52,21 +52,6 @@ public function testSetupWildcardQueryFilterMethod() ->shouldReceive('orWhere')->once()->with('name', 'LIKE', '%hello') ->shouldReceive('orWhere')->once()->with('name', 'LIKE', '%hello%'); - $this->assertInstanceOf('\Illuminate\Database\Query\Builder', $stub->stubSetupWildcardQueryFilter($query, 'hello', ['name'])); - } -} - -class QueryFilter -{ - use QueryFilterTrait; - - public function stubSetupBasicQueryFilter($query, $input) - { - return $this->setupBasicQueryFilter($query, $input); - } - - public function stubSetupWildcardQueryFilter($query, $keyword, $fields) - { - return $this->setupWildcardQueryFilter($query, $keyword, $fields); + $this->assertEquals($query, $this->setupWildcardQueryFilter($query, 'hello', ['name'])); } } diff --git a/tests/Traits/ValidationTraitTest.php b/tests/Traits/ValidationTraitTest.php index 93cc674..799d35f 100644 --- a/tests/Traits/ValidationTraitTest.php +++ b/tests/Traits/ValidationTraitTest.php @@ -4,6 +4,8 @@ class ValidationTraitTest extends \PHPUnit_Framework_TestCase { + use ValidationTrait; + /** * Test Orchestra\Support\Traits\ValidationTrait. * @@ -11,15 +13,8 @@ class ValidationTraitTest extends \PHPUnit_Framework_TestCase */ public function testGetValidationHelpers() { - $stub = new ValidationStub; - - $this->assertEquals(array(), $stub->getValidationEvents()); - $this->assertEquals(array(), $stub->getValidationPhrases()); - $this->assertEquals(array(), $stub->getValidationRules()); + $this->assertEquals(array(), $this->getValidationEvents()); + $this->assertEquals(array(), $this->getValidationPhrases()); + $this->assertEquals(array(), $this->getValidationRules()); } } - -class ValidationStub -{ - use ValidationTrait; -}