compiler = new FunctionDefinitionCompiler(); } public function test_function_is_compiled_correctly(): void { $function = new FunctionDefinition( 'foo', 'foo:42-1337', 'foo/bar', stdClass::class, new Parameters( new ParameterDefinition( 'bar', 'foo::bar', NativeStringType::get(), false, false, 'foo', EmptyAttributes::get() ) ), NativeStringType::get() ); $code = $this->compiler->compile($function); $compiledFunction = $this->eval($code); self::assertInstanceOf(FunctionDefinition::class, $compiledFunction); self::assertSame('foo', $compiledFunction->name()); self::assertSame('foo:42-1337', $compiledFunction->signature()); self::assertSame('foo/bar', $compiledFunction->fileName()); self::assertSame(stdClass::class, $compiledFunction->class()); self::assertTrue($compiledFunction->parameters()->has('bar')); self::assertInstanceOf(NativeStringType::class, $compiledFunction->returnType()); } /** * @return FunctionDefinition|bool */ private function eval(string $code) { try { return eval("return $code;"); } catch (Error $exception) { self::fail($exception->getMessage()); } } }