File tree Expand file tree Collapse file tree
src/Requests/PostSubscription
tests/Requests/PostSubscription Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828 "php" : " ^7.4" ,
2929 "ext-json" : " *" ,
3030 "guzzlehttp/guzzle" : " ^6.3|^7.2" ,
31+ "myclabs/php-enum" : " ^1.8" ,
3132 "psr/log" : " ^1.1" ,
3233 "symfony/validator" : " ^5.2"
3334 },
Original file line number Diff line number Diff line change @@ -10,21 +10,26 @@ class Filter implements JsonSerializable
1010{
1111 private string $ field ;
1212 private string $ value ;
13+ private ?FilterOperator $ operator ;
1314
14- public function __construct (string $ field , string $ value )
15+ public function __construct (string $ field , string $ value, ? FilterOperator $ operator = null )
1516 {
1617 $ this ->field = $ field ;
1718 $ this ->value = $ value ;
19+ $ this ->operator = $ operator ;
1820 }
1921
20- /**
21- * @return mixed
22- */
23- public function jsonSerialize ()
22+ public function jsonSerialize (): array
2423 {
25- return [
24+ $ data = [
2625 'field ' => $ this ->field ,
2726 'value ' => $ this ->value ,
2827 ];
28+
29+ if ($ this ->operator !== null ) {
30+ $ data ['operator ' ] = $ this ->operator ->getValue ();
31+ }
32+
33+ return $ data ;
2934 }
3035}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Keboola \NotificationClient \Requests \PostSubscription ;
6+
7+ use DomainException ;
8+ use MyCLabs \Enum \Enum ;
9+
10+ /**
11+ * @method static self EQUAL()
12+ * @method static self LESS_THAN()
13+ * @method static self GREATER_THAN()
14+ * @method static self LESS_THAN_OR_EQUAL()
15+ * @method static self GREATER_THAN_OR_EQUAL()
16+ *
17+ * @phpstan-extends Enum<string>
18+ */
19+ class FilterOperator extends Enum
20+ {
21+ // phpcs:disable SlevomatCodingStandard.Classes.UnusedPrivateElements
22+ private const EQUAL = '== ' ; // can't be called EQUALS because there is a method called `equals` on base Enum class
23+ private const LESS_THAN = '< ' ;
24+ private const GREATER_THAN = '> ' ;
25+ private const LESS_THAN_OR_EQUAL = '<= ' ;
26+ private const GREATER_THAN_OR_EQUAL = '>= ' ;
27+ // phpcs:enable SlevomatCodingStandard.Classes.UnusedPrivateElements
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Keboola \NotificationClient \Tests \Requests \PostSubscription ;
6+
7+ use Keboola \NotificationClient \Requests \PostSubscription \FilterOperator ;
8+ use PHPUnit \Framework \TestCase ;
9+
10+ class FilterOperatorTest extends TestCase
11+ {
12+ /**
13+ * @dataProvider provideOperatorValues
14+ */
15+ public function testOperatorValues (FilterOperator $ operator , string $ expectedValue ): void
16+ {
17+ self ::assertSame ($ expectedValue , $ operator ->getValue ());
18+ }
19+
20+ public function provideOperatorValues (): iterable
21+ {
22+ yield 'equals ' => [FilterOperator::EQUAL (), '== ' ];
23+ yield 'less than ' => [FilterOperator::LESS_THAN (), '< ' ];
24+ yield 'greater than ' => [FilterOperator::GREATER_THAN (), '> ' ];
25+ yield 'less than or equals ' => [FilterOperator::LESS_THAN_OR_EQUAL (), '<= ' ];
26+ yield 'greater than or equals ' => [FilterOperator::GREATER_THAN_OR_EQUAL (), '>= ' ];
27+ }
28+ }
Original file line number Diff line number Diff line change 55namespace Keboola \NotificationClient \Tests \Requests \PostSubscription ;
66
77use Keboola \NotificationClient \Requests \PostSubscription \Filter ;
8+ use Keboola \NotificationClient \Requests \PostSubscription \FilterOperator ;
89use PHPUnit \Framework \TestCase ;
910
1011class FilterTest extends TestCase
@@ -20,4 +21,17 @@ public function testJsonSerialize(): void
2021 $ filter ->jsonSerialize ()
2122 );
2223 }
24+
25+ public function testJsonSerializeWithOperator (): void
26+ {
27+ $ filter = new Filter ('someName ' , 'someValue ' , FilterOperator::GREATER_THAN_OR_EQUAL ());
28+ self ::assertSame (
29+ [
30+ 'field ' => 'someName ' ,
31+ 'value ' => 'someValue ' ,
32+ 'operator ' => '>= ' ,
33+ ],
34+ $ filter ->jsonSerialize ()
35+ );
36+ }
2337}
You can’t perform that action at this time.
0 commit comments