Skip to content

Commit

Permalink
Improve testing traits.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Aug 3, 2014
1 parent b16e2fb commit b6cb732
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
6 changes: 3 additions & 3 deletions tests/Traits/MacroableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,11 +29,11 @@ public function testMacroIsExecutable()
*/
public function testMacroThrowsExceptionWhenMacroIsntExecutable()
{
with(new Macroable)->foo();
with(new MacroableStub)->foo();
}
}

class Macroable
class MacroableStub
{
use MacroableTrait;
}
23 changes: 4 additions & 19 deletions tests/Traits/QueryFilterTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class QueryFilterTraitTest extends \PHPUnit_Framework_TestCase
{
use QueryFilterTrait;

/**
* Teardown the test environment.
*/
Expand All @@ -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',
]));
Expand All @@ -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'))
Expand All @@ -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']));
}
}
15 changes: 5 additions & 10 deletions tests/Traits/ValidationTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

class ValidationTraitTest extends \PHPUnit_Framework_TestCase
{
use ValidationTrait;

/**
* Test Orchestra\Support\Traits\ValidationTrait.
*
* @test
*/
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;
}

0 comments on commit b6cb732

Please sign in to comment.