resetState(); } return $parser; } /** * Base method for testing exceptions * * @param string $excep Identifier of the exception (e.g. 'unexpectedtoken') * @param string $expr The expression to test * @param string $caller The function where the exception is thrown */ private function exceptionTest( $excep, $expr, $caller ) { $parser = self::getParser(); try { $parser->parse( $expr ); } catch ( AFPUserVisibleException $e ) { $this->assertEquals( $excep, $e->mExceptionID, "Exception $excep not thrown in AFPData::$caller" ); return; } $this->fail( "Exception $excep not thrown in AFPData::$caller" ); } /** * Test the 'regexfailure' exception * * @param string $expr The expression to test * @param string $caller The function where the exception is thrown * @covers AFPData::keywordRegex * @dataProvider regexFailure */ public function testRegexFailureException( $expr, $caller ) { $this->exceptionTest( 'regexfailure', $expr, $caller ); } /** * Data provider for testRegexFailureException * The second parameter is the function where the exception is raised. * One expression for each throw. * * @return array */ public function regexFailure() { return [ [ "'a' rlike '('", 'keywordRegex' ], ]; } /** * Test the 'dividebyzero' exception * * @param string $expr The expression to test * @param string $caller The function where the exception is thrown * @covers AFPData::mulRel * @dataProvider divideByZero */ public function testDivideByZeroException( $expr, $caller ) { $this->exceptionTest( 'dividebyzero', $expr, $caller ); } /** * Data provider for testRegexFailureException * The second parameter is the function where the exception is raised. * One expression for each throw. * * @return array */ public function divideByZero() { return [ [ '1/0', 'mulRel' ], ]; } }