<?php use UFOException\FacadeException; use UFOException\Interfaces\TypesExceptionHandlers; require_once '/vendor/autoload.php'; function testException($q = 1) { if ($q == 1) { throw new Exception('My exception message'); } echo $q; } $myException = new FacadeException(); $myException->config->setTypeHandler(TypesExceptionHandlers::E_TYPE_WRITE | TypesExceptionHandlers::E_TYPE_LOG)->setLogFileName("tmp/qwe/asd/logfile.log"); $myException->registerHandler(); try { testException(1); } catch (\Exception $e) { $myException->getExceptionMessage($e); } echo PHP_EOL . " The script continues to run " . PHP_EOL; throw new Exception('My exception message2');
$tokens->extract(1, 3); test($tokens->key(), 1, 'extract multiple over position'); // insert() $tokens = clone $tokenStream; $tokens->seek(2); $tokens->insert(1, array('(', ')')); test($tokens->key(), 4, 'insert before position'); $tokens->insert(1, array('(', ')', array('(', ')'))); test($tokens->key(), 8, 'insert recursive before position'); }); group('interface ArrayAccess', function () use($tokenStream) { $tokenStream = clone $tokenStream; test($tokenStream[0]->content, "<?php\n", 'get offset'); $tokenStream[0] = new Token(T_OPEN_TAG, "<?\n", 1); test($tokenStream[0]->content, "<?\n", 'set offset'); $tokenStream[] = new Token(T_CLOSE_TAG, '?>', 2); test($tokenStream[5]->content, '?>', 'append'); test(isset($tokenStream[6]), false, 'isset'); unset($tokenStream[0]); // pass if no error test(isset($tokenStream[0]), true, 'unset moves tokens down'); testException(function () use($tokenStream) { $tokenStream[5]; }, 'OutOfBoundsException', 'getting non existing offset'); testException(function () use($tokenStream) { unset($tokenStream[5]); }, 'OutOfBoundsException', 'unsetting non existing offset'); testException(function () use($tokenStream) { $tokenStream[] = 0; }, 'InvalidArgumentException', 'setting to non-token'); });
$token->undefined; }, 'InvalidArgumentException', 'getting undefined property'); test($token->type, T_OPEN_ROUND, 'getting property: type'); test($token->content, '(', 'getting property: content'); test($token->line, 0, 'getting property: line'); test($token->id, 1, 'getting property: id'); test($token->name, "'('", 'getting property: name (char token)'); test($funcToken->name, 'T_FUNCTION', 'getting property: name ("real" token)'); test((string) $token, '(', '(string) $token'); }); group('magic setters', function () use($token, $funcToken) { testException(function () use($token) { $token->undefined = 'a'; }, 'InvalidArgumentException', 'setting undefined property'); testException(function () use($token) { $token->id = 1; }, 'InvalidArgumentException', 'setting id not allowed'); testException(function () use($token) { $token->name = 1; }, 'InvalidArgumentException', 'setting name not allowed'); $token = clone $token; $token->type = T_FUNCTION; $token->content = 'function'; $token->line = 1; test(tokenEqual($token, $funcToken), true, 'setting properties'); }); group('Token->is()', function () use($token) { test($token->is(T_OPEN_ROUND), true, 'is(token)'); test($token->is(array(T_CLOSE_ROUND, T_OPEN_ROUND)), true, 'is(array(token, token))'); test($token->is(T_CLOSE_ROUND, T_OPEN_ROUND), true, 'is(token, token)'); });
/** * An exception should still be recorded. * * @test */ public function testException() { eval('function testException($foo) { throw new \\Exception(); }'); $spy = new Spy(__NAMESPACE__, "testException"); $spy->enable(); try { testException("foo"); $this->fail("Expected exception"); } catch (\Exception $e) { $invocation = $spy->getInvocations()[0]; $this->assertEquals(["foo"], $invocation->getArguments()); $this->assertNull($invocation->getReturn()); $this->assertTrue($invocation->isExceptionThrown()); $this->assertEquals($e, $invocation->getException()); } }
test($tokenStream->findEOS(6), 12, 'find eos tag'); test($tokenStream->find(0, T_OPEN_TAG), false, 'find from already matchind token'); test($tokenStream->find($max, T_EXIT, true), 2, 'find token backwards'); test($tokenStream->find(0, T_OPEN_TAG, true), false, 'find from first index backwards'); test($tokenStream->findEOS($max, true), 6, 'find eos semicolon'); // 0 123 4567890 $hacker = new TokenStream('<?php A(function(){;});'); test($hacker->findEOS(2), 10, 'find EOS skipping lambda'); test($hacker->findEOS(9, true), 0, 'find EOS skipping lambda backwards'); // 0 123 $hacker = new TokenStream('<?php {} '); test($hacker->findEOS(3, true), 2, 'find closing bracket as EOS backwards'); }); group('skip', function () use($tokenStream, $max) { test($tokenStream->skip(0, T_WHITESPACE), 2, 'skip token'); test($tokenStream->skip(0, array(T_WHITESPACE, T_EXIT)), 3, 'skip tokens'); test($tokenStream->skip($max, array(T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING), true), 8, 'skip tokens backwards'); test($tokenStream->skipWhitespace(0), 2, 'skip whitespace'); }); // 0 12 34 5678901 234 56 789 $tokenStream = new TokenStream('<?php (hi,hi,(),((hi),hi)) (()'); group('complementaryBracket', function () use($tokenStream) { test($tokenStream->complementaryBracket(1), 16, 'find forward'); test($tokenStream->complementaryBracket(15), 9, 'find backwards'); testException(function () use($tokenStream) { $tokenStream->complementaryBracket(17); }, 'TokenException', 'brackets not matching'); testException(function () use($tokenStream) { $tokenStream->complementaryBracket(2); }, 'TokenException', 'not a bracket'); });