From f0ca34fa8805c6da6bdad8dbda02f27bd45869b3 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 15 May 2021 09:24:17 +0200 Subject: [PATCH 1/2] add text value parser creator --- src/Value/TextValueParserCreator.php | 30 ++++++++++ src/Value/TextValueParserCreatorTest.php | 71 ++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/Value/TextValueParserCreator.php create mode 100644 src/Value/TextValueParserCreatorTest.php diff --git a/src/Value/TextValueParserCreator.php b/src/Value/TextValueParserCreator.php new file mode 100644 index 0000000..d9b9ce7 --- /dev/null +++ b/src/Value/TextValueParserCreator.php @@ -0,0 +1,30 @@ +parse($valueToParse); + + Assert::assertSame($expectedParsedResult, $actualValue); + } + + + /** + * @return string[][] + */ + public function validTextValueProvider(): array + { + return [ + [ + 'expectedParsedResult' => 'hello world', + 'valueToParse' => '"hello world"', + ], + [ + 'expectedParsedResult' => 'foobar', + 'valueToParse' => '\'foobar\'', + ], + [ + 'expectedParsedResult' => '1234', + 'valueToParse' => '"1234"', + ], + ]; + } + + + /** + * @dataProvider invalidTextValueProvider + */ + public function testParsingInvalidTextValue(string $valueToParse): void + { + $parser = TextValueParserCreator::create(); + + $this->expectException(ParseFailureException::class); + + $parser->parse($valueToParse); + } + + + /** + * @return string[][] + */ + public function invalidTextValueProvider(): array + { + return [ + ['valueToParse' => 'hello world'], + ['valueToParse' => '"foo bar'], + ['valueToParse' => 'foo bar\''], + ['valueToParse' => '"foo bar\''], + ]; + } +} From 50ffd3404a502ab9fd5cf3f12a2ea80e923b5670 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sat, 15 May 2021 10:06:44 +0200 Subject: [PATCH 2/2] fix wrong interface name --- examples/Car/QueryLanguage/CarColorQueryLanguageField.php | 4 ++-- src/Operator/IsNull/IsNullQueryLanguageOperator.php | 4 ++-- ...tor.php => QueryLanguageFieldSupportingIsNullOperator.php} | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/Operator/IsNull/{QueryLanguageFieldSupportIsNullOperator.php => QueryLanguageFieldSupportingIsNullOperator.php} (80%) diff --git a/examples/Car/QueryLanguage/CarColorQueryLanguageField.php b/examples/Car/QueryLanguage/CarColorQueryLanguageField.php index ecb6440..7000f07 100644 --- a/examples/Car/QueryLanguage/CarColorQueryLanguageField.php +++ b/examples/Car/QueryLanguage/CarColorQueryLanguageField.php @@ -8,7 +8,7 @@ use BrandEmbassy\QueryLanguageParser\Operator\EqualTo\QueryLanguageFieldSupportingEqualToOperator; use BrandEmbassy\QueryLanguageParser\Operator\In\QueryLanguageFieldSupportingInOperator; use BrandEmbassy\QueryLanguageParser\Operator\IsNotNull\QueryLanguageFieldSupportingIsNotNullOperator; -use BrandEmbassy\QueryLanguageParser\Operator\IsNull\QueryLanguageFieldSupportIsNullOperator; +use BrandEmbassy\QueryLanguageParser\Operator\IsNull\QueryLanguageFieldSupportingIsNullOperator; use BrandEmbassy\QueryLanguageParser\Operator\NotEqualTo\QueryLanguageFieldSupportingNotEqualToOperator; use BrandEmbassy\QueryLanguageParser\Operator\NotIn\QueryLanguageFieldSupportingNotInOperator; use BrandEmbassy\QueryLanguageParser\Value\MultipleValuesExpressionParserCreator; @@ -22,7 +22,7 @@ final class CarColorQueryLanguageField QueryLanguageFieldSupportingNotEqualToOperator, QueryLanguageFieldSupportingInOperator, QueryLanguageFieldSupportingNotInOperator, - QueryLanguageFieldSupportIsNullOperator, + QueryLanguageFieldSupportingIsNullOperator, QueryLanguageFieldSupportingIsNotNullOperator { public function getFieldIdentifier(): string diff --git a/src/Operator/IsNull/IsNullQueryLanguageOperator.php b/src/Operator/IsNull/IsNullQueryLanguageOperator.php index 53bc3c6..acf0aa4 100644 --- a/src/Operator/IsNull/IsNullQueryLanguageOperator.php +++ b/src/Operator/IsNull/IsNullQueryLanguageOperator.php @@ -32,13 +32,13 @@ public function createOperatorParser(): MonoParser public function isFieldSupported(QueryLanguageField $field): bool { - return $field instanceof QueryLanguageFieldSupportIsNullOperator; + return $field instanceof QueryLanguageFieldSupportingIsNullOperator; } public function createFieldExpressionParser(QueryLanguageField $field): MonoParser { - assert($field instanceof QueryLanguageFieldSupportIsNullOperator); + assert($field instanceof QueryLanguageFieldSupportingIsNullOperator); return new ConcParser( [ diff --git a/src/Operator/IsNull/QueryLanguageFieldSupportIsNullOperator.php b/src/Operator/IsNull/QueryLanguageFieldSupportingIsNullOperator.php similarity index 80% rename from src/Operator/IsNull/QueryLanguageFieldSupportIsNullOperator.php rename to src/Operator/IsNull/QueryLanguageFieldSupportingIsNullOperator.php index 15475b3..13624a5 100644 --- a/src/Operator/IsNull/QueryLanguageFieldSupportIsNullOperator.php +++ b/src/Operator/IsNull/QueryLanguageFieldSupportingIsNullOperator.php @@ -4,7 +4,7 @@ use BrandEmbassy\QueryLanguageParser\Field\QueryLanguageField; -interface QueryLanguageFieldSupportIsNullOperator extends QueryLanguageField +interface QueryLanguageFieldSupportingIsNullOperator extends QueryLanguageField { /** * @param mixed $fieldName output of field name parser