Skip to content

Commit

Permalink
Test - possibility to ignore string parameter when it's empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mnabialek committed Jun 15, 2016
1 parent b944a92 commit 4c66cca
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/SimpleQueryParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,45 @@ public function it_returns_valid_filters_when_not_empty_request()
$this->assertEquals($filters, $parser->getFilters());
}

/** @test */
public function it_include_filter_with_empty_value_when_empty_value()
{
$request = m::mock('Illuminate\Http\Request');
$request->shouldReceive('except')->once()->with('sort')->andReturn([
'id' => '',
'email' => ' test@example.com ',
'something' => [' foo ', 'bar', 'baz'],
]);

$filters = new Collection([
new Filter('id', ''),
new Filter('email', ' test@example.com '),
new Filter('something', [' foo ', 'bar', 'baz']),
]);

$parser = new SimpleQueryParser($request, new Collection());
$this->assertEquals($filters, $parser->getFilters());
}

/** @test */
public function it_doest_not_include_filter_with_empty_value_when_empty_value_with_property_set()
{
$request = m::mock('Illuminate\Http\Request');
$request->shouldReceive('except')->once()->with('sort')->andReturn([
'id' => '',
'email' => ' test@example.com ',
'something' => [' foo ', 'bar', 'baz'],
]);

$filters = new Collection([
new Filter('email', ' test@example.com '),
new Filter('something', [' foo ', 'bar', 'baz']),
]);

$parser = new IgnoreEmptyQueryParser($request, new Collection());
$this->assertEquals($filters, $parser->getFilters());
}

/** @test */
public function it_returns_empty_sorts_when_empty_request()
{
Expand Down Expand Up @@ -142,3 +181,10 @@ public function it_returns_valid_sorts_when_array_with_duplicated_fields()
$this->assertEquals($sorts, $parser->getSorts());
}
}

// stubs

class IgnoreEmptyQueryParser extends SimpleQueryParser
{
protected $ignoreEmptyFilters = true;
}

0 comments on commit 4c66cca

Please sign in to comment.