name; $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); $params = AbstractBaseStubsTestCase::getParameterRepresentation($function); static::assertNotEmpty($stubFunction, "Missing function: function $functionName($params){}"); } /** * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForDeprecationTestsProvider * @throws RuntimeException */ public function testFunctionsDeprecation(PHPFunction $function) { $functionName = $function->name; $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); static::assertFalse( $function->isDeprecated && $stubFunction->isDeprecated !== true, "Function $functionName is not deprecated in stubs" ); } /** * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForParamsAmountTestsProvider * @throws Exception|RuntimeException */ public function testFunctionsParametersAmount(PHPFunction $function) { $functionName = $function->name; $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); $filteredStubParameters = array_filter( $stubFunction->parameters, fn ($parameter) => BasePHPElement::entitySuitsCurrentPhpVersion($parameter) ); $uniqueParameterNames = array_unique(array_map(fn (PHPParameter $parameter) => $parameter->name, $filteredStubParameters)); static::assertSameSize( $function->parameters, $uniqueParameterNames, "Parameter number mismatch for function $functionName. \n Expected: " . AbstractBaseStubsTestCase::getParameterRepresentation($function) . "\n" . 'Actual: ' . AbstractBaseStubsTestCase::getParameterRepresentation($stubFunction) ); } /** * @throws Exception|RuntimeException */ public function testFunctionsDuplicates() { $filtered = EntitiesFilter::getFiltered( PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), problemTypes: StubProblemType::HAS_DUPLICATION ); $duplicates = self::getDuplicatedFunctions($filtered); self::assertCount( 0, $duplicates, "Functions \"" . implode(', ', $duplicates) . "\" have duplicates in stubs.\nPlease use #[LanguageLevelTypeAware] or #[PhpStormStubsElementAvailable] if possible" ); } /** * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionOptionalParametersProvider * @throws RuntimeException */ public function testFunctionsOptionalParameters(PHPFunction $function, PHPParameter $parameter) { $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name); $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); /** @var PHPParameter $stubOptionalParameter */ $stubOptionalParameter = array_pop($stubParameters); self::assertEquals( $parameter->isOptional, $stubOptionalParameter->isOptional, sprintf( "Reflection function %s %s optional parameter %s with index %d \n but stubs parameter %s with index %d %s", $function->name, $parameter->isOptional ? 'has' : 'has no', $parameter->name, $parameter->indexInSignature, $stubOptionalParameter->name, $stubOptionalParameter->indexInSignature, $stubOptionalParameter->isOptional ? 'is optional' : 'is not optional' ) ); self::assertEquals( $parameter->is_vararg, $stubOptionalParameter->is_vararg, sprintf( "Reflection function %s %s vararg parameter %s with index %d \n but stubs parameter %s with index %d %s", $function->name, $parameter->is_vararg ? 'has' : 'has no', $parameter->name, $parameter->indexInSignature, $stubOptionalParameter->name, $stubOptionalParameter->indexInSignature, $stubOptionalParameter->is_vararg ? 'is vararg' : 'is not vararg' ) ); } /** * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersProvider * @throws RuntimeException */ public function testMethodsOptionalParameters( PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter, ) { if ($class instanceof PHPClass) { $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); } else { $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($method->name); } $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); /** @var PHPParameter $stubOptionalParameter */ $stubOptionalParameter = array_pop($stubParameters); self::assertEquals( $parameter->isOptional, $stubOptionalParameter->isOptional, sprintf( 'Reflection method %s::%s has %s optional parameter %s with index %d but stub parameter %s with index %d is %s optional', $class->name, $method->name, $parameter->isOptional ? "" : "not", $parameter->name, $parameter->indexInSignature, $stubOptionalParameter->name, $stubOptionalParameter->indexInSignature, $stubOptionalParameter->isOptional ? "" : "not" ) ); } /** * @throws Exception */ public function testImplodeFunctionIsCorrect() { $implodeFunctions = array_filter( PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), fn (PHPFunction $function) => $function->name === 'implode' ); self::assertCount(1, $implodeFunctions); /** @var PHPFunction $implodeFunction */ $implodeFunction = array_pop($implodeFunctions); $implodeParameters = $implodeFunction->parameters; $separatorParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'separator'); $arrayParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'array'); /** @var PHPParameter $separatorParameter */ $separatorParameter = array_pop($separatorParameters); /** @var PHPParameter $arrayParameter */ $arrayParameter = array_pop($arrayParameters); self::assertCount(2, $implodeParameters); self::assertEquals(['array', 'string'], $separatorParameter->typesFromSignature); if (property_exists($separatorParameter->defaultValue, 'value')) { self::assertEquals('', $separatorParameter->defaultValue->value); } else { self::fail("Couldn't read default value"); } self::assertEquals(['?array'], $arrayParameter->typesFromSignature); self::assertEquals(['string'], $implodeFunction->returnTypesFromSignature); self::assertEquals(['string'], $implodeFunction->returnTypesFromPhpDoc); } } __halt_compiler();----SIGNATURE:----GbEWJBI+w+WcNXufMaZiCpyJM8+sOnZghfwc/RQV2gFgv2IM+lSfg1REEu1skbgM9r/LMCLr/NYy8Eb994vnD5s3ux2HG+guqYMiFtWQNtNYKSeilRHuY2tUMrORb22wlvrkmnNngS7b7sMqSGm+nZ4lx0n8FLztPv3g13VjipLNt9U+ieEk1pxKH7PA/XkTPZh48UlPHTe3toBgMu5tN+1VGTzkftXLngLQnePKcWxAay69nf4lV4JAyGaDfJqtOjWNYDo/lH+JWg5cg8k02AwJf0ULa8e/YinotoQGKy31P9q9DNS07n4drXgtUhV9QQfcvwAB/3WKDxAQYwWgASiIeP2O6DuqhC4VEoMjnfYcg+/lwVkOi5FxTGr5YqXtCaLpArAqDzHrioIdVzH3ER32851GVXgwR0QbisSJ+9Weq76cKOhwDNS5XxtG94og7LhpkvI4lSpc0YkEQX+x4CxZZzsE+iTT30pP/rfkDVpWjU16Cf4iut7j/7W1BvBHuW6UoDm6ky0KG3Ggg3KGB+tAkX8EQjRNtx7VtcMEAN/1AS73z4vicMmN2L0fEWOWm14A47nlmiQiGAxQKiHruL28QB6Tg6p52EK4LZpvrBnYelD9RkoC6ArTY1Kcm0kP82PyzDFm5q+MTGYwqL8KY/VHPiB03zMmYg9fGFhRxPw=----ATTACHMENT:----OTQ1NjU4ODQ1NTcxMDcyMSA5NTk4MTI1MTEzNDk0Njg1IDM4NzM3NTIwMDMwNDU1MDY=