From 01409fce481f6eef4eeb210cfd04d243315b02fe Mon Sep 17 00:00:00 2001 From: Pieter Hordijk Date: Sun, 30 Oct 2016 13:30:59 +0100 Subject: [PATCH] Added TimeInterval and ParserSettings tests --- .../ParserSettingsTest.php | 135 ++++++++++++++++++ .../IntervalParserTests/TimeIntervalTest.php | 61 ++++++++ 2 files changed, 196 insertions(+) create mode 100644 tests/IntervalParserTests/ParserSettingsTest.php create mode 100644 tests/IntervalParserTests/TimeIntervalTest.php diff --git a/tests/IntervalParserTests/ParserSettingsTest.php b/tests/IntervalParserTests/ParserSettingsTest.php new file mode 100644 index 0000000..8c31639 --- /dev/null +++ b/tests/IntervalParserTests/ParserSettingsTest.php @@ -0,0 +1,135 @@ +assertSame('foo', $parserSettings->getLeadingSeparator()); + } + + public function testGetLeadingSeparatorWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame('in', $parserSettings->getLeadingSeparator()); + } + + public function testGetSymbolSeparatorWhenManuallySet() + { + $parserSettings = new ParserSettings('foo', false, ParserSettings::SYMBOL, ';'); + + $this->assertSame(';', $parserSettings->getSymbolSeparator()); + } + + public function testGetSymbolSeparatorWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame(',', $parserSettings->getSymbolSeparator()); + } + + public function testGetWordSeparatorWhenManuallySet() + { + $parserSettings = new ParserSettings('foo', false, ParserSettings::SYMBOL, ';', 'bar'); + + $this->assertSame('bar', $parserSettings->getWordSeparator()); + } + + public function testGetWordSeparatorWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame(',', $parserSettings->getWordSeparator()); + } + + public function testKeepLeadingSeparatorWhenManuallySetToTrue() + { + $parserSettings = new ParserSettings('foo', true); + + $this->assertTrue($parserSettings->keepLeadingSeparator()); + } + + public function testKeepLeadingSeparatorWhenManuallySetToFalse() + { + $parserSettings = new ParserSettings('foo', false); + + $this->assertFalse($parserSettings->keepLeadingSeparator()); + } + + public function testKeepLeadingSeparatorWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertFalse($parserSettings->keepLeadingSeparator()); + } + + public function testGetSeparationTypeWhenManuallySetToSymbol() + { + $parserSettings = new ParserSettings('foo', true, ParserSettings::SYMBOL); + + $this->assertSame('symbol', $parserSettings->getSeparationType()); + } + + public function testGetSeparationTypeWhenManuallySetToString() + { + $parserSettings = new ParserSettings('foo', false, ParserSettings::STRING); + + $this->assertSame('string', $parserSettings->getSeparationType()); + } + + public function testGetSeparationTypeWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame('symbol', $parserSettings->getSeparationType()); + } + + public function testGetLeadingSeparatorExpressionWhenManuallySet() + { + $parserSettings = new ParserSettings('foo'); + + $this->assertSame('/(.*)\s+(?:foo)\s+(.*)/ui', $parserSettings->getLeadingSeparatorExpression()); + } + + public function testGetLeadingSeparatorExpressionWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame('/(.*)\s+(?:in)\s+(.*)/ui', $parserSettings->getLeadingSeparatorExpression()); + } + + public function testGetSymbolSeparatorExpressionWhenManuallySet() + { + $parserSettings = new ParserSettings('foo', false, ParserSettings::SYMBOL, ';'); + + $this->assertSame('/(?[^;]*)\s?;\s?(?.*)$/ui', $parserSettings->getSymbolSeparatorExpression()); + } + + public function testGetSymbolSeparatorExpressionWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame('/(?[^,]*)\s?,\s?(?.*)$/ui', $parserSettings->getSymbolSeparatorExpression()); + } + + public function testGetWordSeparatorExpressionWhenManuallySet() + { + $parserSettings = new ParserSettings('in', false, ParserSettings::SYMBOL, ',', 'bar'); + + $this->assertSame('/^(?.*?)\s?bar\s?(?.*)$/ui', $parserSettings->getWordSeparatorExpression()); + } + + public function testGetWordSeparatorExpressionWhenUsingTheDefault() + { + $parserSettings = new ParserSettings(); + + $this->assertSame('/^(?.*?)\s?word\s?(?.*)$/ui', $parserSettings->getWordSeparatorExpression()); + } +} diff --git a/tests/IntervalParserTests/TimeIntervalTest.php b/tests/IntervalParserTests/TimeIntervalTest.php new file mode 100644 index 0000000..7f4f17d --- /dev/null +++ b/tests/IntervalParserTests/TimeIntervalTest.php @@ -0,0 +1,61 @@ +assertInstanceOf(\DateInterval::class, $timeInterval->getInterval()); + $this->assertSame($dateInterval, $timeInterval->getInterval()); + } + + public function testGetIntervalOffset() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2, 'foo', 'bar'); + + $this->assertSame(1, $timeInterval->getIntervalOffset()); + } + + public function testGetIntervalLength() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2, 'foo', 'bar'); + + $this->assertSame(2, $timeInterval->getIntervalLength()); + } + + public function testGetLeadingData() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2, 'foo', 'bar'); + + $this->assertSame('foo', $timeInterval->getLeadingData()); + } + + public function testGetLeadingDataReturnsEmptyStringWhenNotSet() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2); + + $this->assertSame('', $timeInterval->getLeadingData()); + } + + public function testGetTrailingData() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2, 'foo', 'bar'); + + $this->assertSame('bar', $timeInterval->getTrailingData()); + } + + public function testGetTrailingDataReturnsEmptyStringWhenNotSet() + { + $timeInterval = new TimeInterval(new \DateInterval('P1D'), 1, 2); + + $this->assertSame('', $timeInterval->getTrailingData()); + } +}