Skip to content

Commit d057c86

Browse files
committed
Increase code coverage.
1 parent cf8a720 commit d057c86

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/php/Gomoob/Filter/Sql/SqlFilterConverter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
*/
4444
class SqlFilterConverter implements SqlFilterConverterInterface
4545
{
46-
4746
/**
4847
* {@inheritDoc}
4948
*/
@@ -59,7 +58,7 @@ public function transform($key, /* string */ $value, /* array */ $context = [])
5958
throw new ConverterException('Complex filters are currently not implemented !');
6059
} // Otherwise this is an error
6160
else {
62-
throw new ConverterException('Invalid filter key class !');
61+
throw new ConverterException('Invalid filter key type !');
6362
}
6463

6564
return $sqlFilterWithParams;

src/test/php/Gomoob/Filter/Sql/SqlFilterConverterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ public function testTransform()
7878
$this->assertSame('property = ?', $sqlFilter->getExpression());
7979
$this->assertCount(1, $sqlFilter->getParams());
8080
$this->assertSame('Sample string', $sqlFilter->getParams()[0]);
81+
82+
// Test with a complex filter and only one property (currently not supported so considered as string for now)
83+
// Sample complex filters with only one property would be
84+
// "<10->2" : Lower than 10 or greater than 2
85+
// "'Handball'-'Football'" : Equals to 'Hand ball' or 'Foot ball'
86+
// "'*ball*'+'*tennis*'" : Like 'ball' and like 'tennis'
87+
$sqlFilter = $this->filterConverter->transform('property', '<10->2');
88+
$this->assertSame('property = ?', $sqlFilter->getExpression());
89+
$this->assertCount(1, $sqlFilter->getParams());
90+
$this->assertSame('<10->2', $sqlFilter->getParams()[0]);
91+
92+
// Test with a complex filter with multiple properties (currently not supported and will fail)
93+
try {
94+
$this->filterConverter->transform(0, 'price:<90-validity:>=3');
95+
$this->fail('Must have thrown a ConverterException !');
96+
} catch (ConverterException $cex) {
97+
$this->assertSame('Complex filters are currently not implemented !', $cex->getMessage());
98+
}
99+
100+
// Test with a key which has a bad type
101+
try {
102+
$this->filterConverter->transform(0.26, '>10');
103+
$this->fail('Must have thrown a ConverterException !');
104+
} catch (ConverterException $cex) {
105+
$this->assertSame('Invalid filter key type !', $cex->getMessage());
106+
}
81107
}
82108

83109
/**

0 commit comments

Comments
 (0)