getMethod('setName'); $method = new Method($reflectionMethod, 'Example', $reflectionClass); $this->assertInstanceOf(Method::class, $method); } /** * Test the output of a class */ public function testOutput() { $reflectionClass = new \ReflectionClass(ExampleClass::class); $reflectionMethod = $reflectionClass->getMethod('setName'); $method = new Method($reflectionMethod, 'Example', $reflectionClass); $output = <<<'DOC' /** * * * @param string $last * @param string $first * @param string $middle * @static */ DOC; $this->assertSame($output, $method->getDocComment('')); $this->assertSame('setName', $method->getName()); $this->assertSame('\\' . ExampleClass::class, $method->getDeclaringClass()); $this->assertSame('$last, $first, ...$middle', $method->getParams(true)); $this->assertSame(['$last', '$first', '...$middle'], $method->getParams(false)); $this->assertSame('$last, $first = \'Barry\', ...$middle', $method->getParamsWithDefault(true)); $this->assertSame(['$last', '$first = \'Barry\'', '...$middle'], $method->getParamsWithDefault(false)); $this->assertTrue($method->shouldReturn()); } /** * Test the output of a class */ public function testEloquentBuilderOutput() { if ((int) Application::VERSION < 8) { $this->markTestSkipped('This test requires Laravel 8.0 or higher'); } $reflectionClass = new \ReflectionClass(Builder::class); $reflectionMethod = $reflectionClass->getMethod('with'); $method = new Method($reflectionMethod, 'Builder', $reflectionClass); $output = <<<'DOC' /** * Set the relationships that should be eager loaded. * * @param string|array $relations * @param string|\Closure|null $callback * @return \Illuminate\Database\Eloquent\Builder|static * @static */ DOC; $this->assertSame($output, $method->getDocComment('')); $this->assertSame('with', $method->getName()); $this->assertSame('\\' . Builder::class, $method->getDeclaringClass()); $this->assertSame('$relations, $callback', $method->getParams(true)); $this->assertSame(['$relations', '$callback'], $method->getParams(false)); $this->assertSame('$relations, $callback = null', $method->getParamsWithDefault(true)); $this->assertSame(['$relations', '$callback = null'], $method->getParamsWithDefault(false)); $this->assertTrue($method->shouldReturn()); } /** * Test special characters in methods default values */ public function testDefaultSpecialChars() { $reflectionClass = new \ReflectionClass(ExampleClass::class); $reflectionMethod = $reflectionClass->getMethod('setSpecialChars'); $method = new Method($reflectionMethod, 'Example', $reflectionClass); $this->assertSame('$chars', $method->getParams(true)); $this->assertSame(['$chars'], $method->getParams(false)); $this->assertSame('$chars = \'$\\\'\\\\\'', $method->getParamsWithDefault(true)); $this->assertSame(['$chars = \'$\\\'\\\\\''], $method->getParamsWithDefault(false)); } } class ExampleClass { /** * @param string $last * @param string $first * @param string $middle */ public function setName($last, $first = 'Barry', ...$middle) { return; } public function setSpecialChars($chars = "\$'\\") { return; } }