Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deprecated null parameter in trim() call #124

Merged
merged 2 commits into from
Dec 19, 2021

Conversation

mtorromeo
Copy link
Contributor

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

DocScanner may raise the following error with PHP 8.1 if shortDescription is used before initialization, the default value being null.

Exception Error: "Error: Typed property Laminas\Code\Scanner\DocBlockScanner::$shortDescription must not be accessed before initialization" in .../vendor/laminas/laminas-code/src/Scanner/DocBlockScanner.php on line 94

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test (failing before this change) is needed here

@Ocramius Ocramius added Bug Something isn't working Unit Test Needed labels Dec 14, 2021
@mtorromeo mtorromeo force-pushed the fix-trim-null branch 2 times, most recently from 31a2ba0 to f986d0a Compare December 14, 2021 11:57
@mtorromeo
Copy link
Contributor Author

While trying to write the simpler test I could I ended up triggering a deprecation in a different part of the code but it represents the same issue. It is just triggered on strlen instead of on trim.

The problem is that I see a deprecation error in phpunit's output but it doesn't fail.

It seems like the error is not being converted to an exception but it I think it should.

$ vendor/bin/phpunit test/Scanner/DocBlockScannerTest.php
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

...                                                                 3 / 3 (100%)
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /laminas-code/src/Scanner/DocBlockScanner.php on line 197

Call Stack:
    0.0060     477072   1. {main}() /laminas-code/vendor/phpunit/phpunit/phpunit:0
    0.0119    1375336   2. PHPUnit\TextUI\Command::main($exit = ???) /laminas-code/vendor/phpunit/phpunit/phpunit:92
    0.0119    1375448   3. PHPUnit\TextUI\Command->run($argv = [0 => 'vendor/bin/phpunit', 1 => 'test/Scanner/DocBlockScannerTest.php'], $exit = TRUE) /laminas-code/vendor/phpunit/phpunit/src/TextUI/Command.php:96
    0.0281    3929072   4. PHPUnit\TextUI\TestRunner->run($suite = class PHPUnit\Framework\TestSuite { protected $backupGlobals = NULL; protected $backupStaticAttributes = NULL; protected $runTestInSeparateProcess = FALSE; protected $name = 'LaminasTest\\Code\\Scanner\\DocBlockScannerTest'; protected $groups = ['Laminas_Code_Scanner' => [...], 'Laminas-110' => [...]]; protected $tests = [0 => class LaminasTest\Code\Scanner\DocBlockScannerTest { ... }, 1 => class LaminasTest\Code\Scanner\DocBlockScannerTest { ... }, 2 => class LaminasTest\Code\Scanner\DocBlockScannerTest { ... }]; protected $numTests = 3; protected $testCase = TRUE; protected $foundClasses = []; protected $providedTests = NULL; protected $requiredTests = NULL; private $beStrictAboutChangesToGlobalState = NULL; private $iteratorFilter = NULL; private $declaredClasses = [0 => 'stdClass', 1 => 'InternalIterator', 2 => 'Exception', 3 => 'ErrorException', 4 => 'Error', 5 => 'CompileError', 6 => 'ParseError', 7 => 'TypeError', 8 => 'ArgumentCountError', 9 => 'ValueError', 10 => 'ArithmeticError', 11 => 'DivisionByZeroError', 12 => 'UnhandledMatchError', 13 => 'Closure', 14 => 'Generator', 15 => 'ClosedGeneratorException', 16 => 'WeakReference', 17 => 'WeakMap', 18 => 'Attribute', 19 => 'ReturnTypeWillChange', 20 => 'Fiber', 21 => 'FiberError', 22 => 'DateTime', 23 => 'DateTimeImmutable', 24 => 'DateTimeZone', 25 => 'DateInterval', 26 => 'DatePeriod', 27 => 'LibXMLError', 28 => 'OpenSSLCertificate', 29 => 'OpenSSLCertificateSigningRequest', 30 => 'OpenSSLAsymmetricKey', 31 => 'InflateContext', 32 => 'DeflateContext', 33 => 'HashContext', 34 => 'JsonException', 35 => 'ReflectionException', 36 => 'Reflection', 37 => 'ReflectionFunctionAbstract', 38 => 'ReflectionFunction', 39 => 'ReflectionGenerator', 40 => 'ReflectionParameter', 41 => 'ReflectionType', 42 => 'ReflectionNamedType', 43 => 'ReflectionUnionType', 44 => 'ReflectionIntersectionType', 45 => 'ReflectionMethod', 46 => 'ReflectionClass', 47 => 'ReflectionObject', 48 => 'ReflectionProperty', 49 => 'ReflectionClassConstant', 50 => 'ReflectionExtension', 51 => 'ReflectionZendExtension', 52 => 'ReflectionReference', 53 => 'ReflectionAttribute', 54 => 'ReflectionEnum', 55 => 'ReflectionEnumUnitCase', 56 => 'ReflectionEnumBackedCase', 57 => 'ReflectionFiber', 58 => 'LogicException', 59 => 'BadFunctionCallException', 60 => 'BadMethodCallException', 61 => 'DomainException', 62 => 'InvalidArgumentException', 63 => 'LengthException', 64 => 'OutOfRangeException', 65 => 'RuntimeException', 66 => 'OutOfBoundsException', 67 => 'OverflowException', 68 => 'RangeException', 69 => 'UnderflowException', 70 => 'UnexpectedValueException', 71 => 'RecursiveIteratorIterator', 72 => 'IteratorIterator', 73 => 'FilterIterator', 74 => 'RecursiveFilterIterator', 75 => 'CallbackFilterIterator', 76 => 'RecursiveCallbackFilterIterator', 77 => 'ParentIterator', 78 => 'LimitIterator', 79 => 'CachingIterator', 80 => 'RecursiveCachingIterator', 81 => 'NoRewindIterator', 82 => 'AppendIterator', 83 => 'InfiniteIterator', 84 => 'RegexIterator', 85 => 'RecursiveRegexIterator', 86 => 'EmptyIterator', 87 => 'RecursiveTreeIterator', 88 => 'ArrayObject', 89 => 'ArrayIterator', 90 => 'RecursiveArrayIterator', 91 => 'SplFileInfo', 92 => 'DirectoryIterator', 93 => 'FilesystemIterator', 94 => 'RecursiveDirectoryIterator', 95 => 'GlobIterator', 96 => 'SplFileObject', 97 => 'SplTempFileObject', 98 => 'SplDoublyLinkedList', 99 => 'SplQueue', 100 => 'SplStack', 101 => 'SplHeap', 102 => 'SplMinHeap', 103 => 'SplMaxHeap', 104 => 'SplPriorityQueue', 105 => 'SplFixedArray', 106 => 'SplObjectStorage', 107 => 'MultipleIterator', 108 => 'SessionHandler', 109 => '__PHP_Incomplete_Class', 110 => 'AssertionError', 111 => 'php_user_filter', 112 => 'Directory', 113 => 'CurlHandle', 114 => 'CurlMultiHandle', 115 => 'CurlShareHandle', 116 => 'CURLFile', 117 => 'CURLStringFile', 118 => 'DOMException', 119 => 'DOMImplementation', 120 => 'DOMNode', 121 => 'DOMNameSpaceNode', 122 => 'DOMDocumentFragment', 123 => 'DOMDocument', 124 => 'DOMNodeList', 125 => 'DOMNamedNodeMap', 126 => 'DOMCharacterData', 127 => 'DOMAttr', ...]; private $warnings = [] }, $arguments = ['extensions' => [], 'listGroups' => FALSE, 'listSuites' => FALSE, 'listTests' => FALSE, 'listTestsXml' => FALSE, 'loader' => NULL, 'useDefaultConfiguration' => TRUE, 'loadedExtensions' => [], 'unavailableExtensions' => [], 'notLoadedExtensions' => [], 'testSuffixes' => [0 => 'Test.php', 1 => '.phpt'], 'configuration' => '/laminas-code/phpunit.xml.dist', 'configurationObject' => class PHPUnit\TextUI\XmlConfiguration\Configuration { private $filename = '/laminas-code/phpunit.xml.dist'; private $validationResult = class PHPUnit\Util\Xml\ValidationResult { ... }; private $extensions = class PHPUnit\TextUI\XmlConfiguration\ExtensionCollection { ... }; private $codeCoverage = class PHPUnit\TextUI\XmlConfiguration\CodeCoverage\CodeCoverage { ... }; private $groups = class PHPUnit\TextUI\XmlConfiguration\Groups { ... }; private $testdoxGroups = class PHPUnit\TextUI\XmlConfiguration\Groups { ... }; private $listeners = class PHPUnit\TextUI\XmlConfiguration\ExtensionCollection { ... }; private $logging = class PHPUnit\TextUI\XmlConfiguration\Logging\Logging { ... }; private $php = class PHPUnit\TextUI\XmlConfiguration\Php { ... }; private $phpunit = class PHPUnit\TextUI\XmlConfiguration\PHPUnit { ... }; private $testSuite = class PHPUnit\TextUI\XmlConfiguration\TestSuiteCollection { ... } }, 'stderr' => FALSE, 'columns' => 80], $warnings = [], $exit = TRUE) /laminas-code/vendor/phpunit/phpunit/src/TextUI/Command.php:143
    0.0327    4221488   5. PHPUnit\Framework\TestSuite->run($result = class PHPUnit\Framework\TestResult { private $passed = ['LaminasTest\Code\Scanner\DocBlockScannerTest::testDocBlockScannerParsesTagsWithNoValuesProperly' => [...], 'LaminasTest\Code\Scanner\DocBlockScannerTest::testDocBlockScannerDescriptions' => [...]]; private $passedTestClasses = []; private $currentTestSuiteFailed = FALSE; private $errors = []; private $failures = []; private $warnings = []; private $notImplemented = []; private $risky = []; private $skipped = []; private $listeners = [0 => class PHPUnit\Runner\TestListenerAdapter { ... }, 1 => class PHPUnit\TextUI\DefaultResultPrinter { ... }]; private $runTests = 3; private $time = 0.003453809; private $codeCoverage = NULL; private $convertDeprecationsToExceptions = FALSE; private $convertErrorsToExceptions = TRUE; private $convertNoticesToExceptions = TRUE; private $convertWarningsToExceptions = TRUE; private $stop = FALSE; private $stopOnError = FALSE; private $stopOnFailure = FALSE; private $stopOnWarning = FALSE; private $beStrictAboutTestsThatDoNotTestAnything = TRUE; private $beStrictAboutOutputDuringTests = FALSE; private $beStrictAboutTodoAnnotatedTests = FALSE; private $beStrictAboutResourceUsageDuringSmallTests = FALSE; private $enforceTimeLimit = FALSE; private $forceCoversAnnotation = FALSE; private $timeoutForSmallTests = 1; private $timeoutForMediumTests = 10; private $timeoutForLargeTests = 60; private $stopOnRisky = FALSE; private $stopOnIncomplete = FALSE; private $stopOnSkipped = FALSE; private $lastTestFailed = FALSE; private $defaultTimeLimit = 1; private $stopOnDefect = FALSE; private $registerMockObjectsFromTestArgumentsRecursively = FALSE }) /laminas-code/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:670
    0.0370    4472544   6. PHPUnit\Framework\TestCase->run($result = class PHPUnit\Framework\TestResult { private $passed = ['LaminasTest\Code\Scanner\DocBlockScannerTest::testDocBlockScannerParsesTagsWithNoValuesProperly' => [...], 'LaminasTest\Code\Scanner\DocBlockScannerTest::testDocBlockScannerDescriptions' => [...]]; private $passedTestClasses = []; private $currentTestSuiteFailed = FALSE; private $errors = []; private $failures = []; private $warnings = []; private $notImplemented = []; private $risky = []; private $skipped = []; private $listeners = [0 => class PHPUnit\Runner\TestListenerAdapter { ... }, 1 => class PHPUnit\TextUI\DefaultResultPrinter { ... }]; private $runTests = 3; private $time = 0.003453809; private $codeCoverage = NULL; private $convertDeprecationsToExceptions = FALSE; private $convertErrorsToExceptions = TRUE; private $convertNoticesToExceptions = TRUE; private $convertWarningsToExceptions = TRUE; private $stop = FALSE; private $stopOnError = FALSE; private $stopOnFailure = FALSE; private $stopOnWarning = FALSE; private $beStrictAboutTestsThatDoNotTestAnything = TRUE; private $beStrictAboutOutputDuringTests = FALSE; private $beStrictAboutTodoAnnotatedTests = FALSE; private $beStrictAboutResourceUsageDuringSmallTests = FALSE; private $enforceTimeLimit = FALSE; private $forceCoversAnnotation = FALSE; private $timeoutForSmallTests = 1; private $timeoutForMediumTests = 10; private $timeoutForLargeTests = 60; private $stopOnRisky = FALSE; private $stopOnIncomplete = FALSE; private $stopOnSkipped = FALSE; private $lastTestFailed = FALSE; private $defaultTimeLimit = 1; private $stopOnDefect = FALSE; private $registerMockObjectsFromTestArgumentsRecursively = FALSE }) /laminas-code/vendor/phpunit/phpunit/src/Framework/TestSuite.php:678
    0.0370    4472544   7. PHPUnit\Framework\TestResult->run($test = class LaminasTest\Code\Scanner\DocBlockScannerTest { protected $backupGlobals = NULL; protected $backupGlobalsExcludeList = []; protected $backupGlobalsBlacklist = []; protected $backupStaticAttributes = NULL; protected $backupStaticAttributesExcludeList = []; protected $backupStaticAttributesBlacklist = []; protected $runTestInSeparateProcess = FALSE; protected $preserveGlobalState = TRUE; protected $providedTests = [0 => class PHPUnit\Framework\ExecutionOrderDependency { ... }]; private ${PHPUnit\Framework\TestCase}runClassInSeparateProcess = NULL; private ${PHPUnit\Framework\TestCase}inIsolation = FALSE; private ${PHPUnit\Framework\TestCase}data = []; private ${PHPUnit\Framework\TestCase}dataName = ''; private ${PHPUnit\Framework\TestCase}expectedException = NULL; private ${PHPUnit\Framework\TestCase}expectedExceptionMessage = NULL; private ${PHPUnit\Framework\TestCase}expectedExceptionMessageRegExp = NULL; private ${PHPUnit\Framework\TestCase}expectedExceptionCode = NULL; private ${PHPUnit\Framework\TestCase}name = 'testEmptyDocBlock'; private ${PHPUnit\Framework\TestCase}dependencies = []; private ${PHPUnit\Framework\TestCase}dependencyInput = []; private ${PHPUnit\Framework\TestCase}iniSettings = []; private ${PHPUnit\Framework\TestCase}locale = []; private ${PHPUnit\Framework\TestCase}mockObjects = []; private ${PHPUnit\Framework\TestCase}mockObjectGenerator = NULL; private ${PHPUnit\Framework\TestCase}status = -1; private ${PHPUnit\Framework\TestCase}statusMessage = ''; private ${PHPUnit\Framework\TestCase}numAssertions = 0; private ${PHPUnit\Framework\TestCase}result = class PHPUnit\Framework\TestResult { private $passed = [...]; private $passedTestClasses = [...]; private $currentTestSuiteFailed = FALSE; private $errors = [...]; private $failures = [...]; private $warnings = [...]; private $notImplemented = [...]; private $risky = [...]; private $skipped = [...]; private $listeners = [...]; private $runTests = 3; private $time = 0.003453809; private $codeCoverage = NULL; private $convertDeprecationsToExceptions = FALSE; private $convertErrorsToExceptions = TRUE; private $convertNoticesToExceptions = TRUE; private $convertWarningsToExceptions = TRUE; private $stop = FALSE; private $stopOnError = FALSE; private $stopOnFailure = FALSE; private $stopOnWarning = FALSE; private $beStrictAboutTestsThatDoNotTestAnything = TRUE; private $beStrictAboutOutputDuringTests = FALSE; private $beStrictAboutTodoAnnotatedTests = FALSE; private $beStrictAboutResourceUsageDuringSmallTests = FALSE; private $enforceTimeLimit = FALSE; private $forceCoversAnnotation = FALSE; private $timeoutForSmallTests = 1; private $timeoutForMediumTests = 10; private $timeoutForLargeTests = 60; private $stopOnRisky = FALSE; private $stopOnIncomplete = FALSE; private $stopOnSkipped = FALSE; private $lastTestFailed = FALSE; private $defaultTimeLimit = 1; private $stopOnDefect = FALSE; private $registerMockObjectsFromTestArgumentsRecursively = FALSE }; private ${PHPUnit\Framework\TestCase}testResult = NULL; private ${PHPUnit\Framework\TestCase}output = ''; private ${PHPUnit\Framework\TestCase}outputExpectedRegex = NULL; private ${PHPUnit\Framework\TestCase}outputExpectedString = NULL; private ${PHPUnit\Framework\TestCase}outputCallback = FALSE; private ${PHPUnit\Framework\TestCase}outputBufferingActive = TRUE; private ${PHPUnit\Framework\TestCase}outputBufferingLevel = 1; private ${PHPUnit\Framework\TestCase}outputRetrievedForAssertion = FALSE; private ${PHPUnit\Framework\TestCase}snapshot = NULL; private ${PHPUnit\Framework\TestCase}prophet = NULL; private ${PHPUnit\Framework\TestCase}beStrictAboutChangesToGlobalState = NULL; private ${PHPUnit\Framework\TestCase}registerMockObjectsFromTestArgumentsRecursively = FALSE; private ${PHPUnit\Framework\TestCase}warnings = []; private ${PHPUnit\Framework\TestCase}groups = [0 => 'Laminas_Code_Scanner']; private ${PHPUnit\Framework\TestCase}doesNotPerformAssertions = FALSE; private ${PHPUnit\Framework\TestCase}customComparators = []; private ${PHPUnit\Framework\TestCase}doubledTypes = [] }) /laminas-code/vendor/phpunit/phpunit/src/Framework/TestCase.php:885
    0.0370    4473160   8. PHPUnit\Framework\TestCase->runBare() /laminas-code/vendor/phpunit/phpunit/src/Framework/TestResult.php:722
    0.0370    4490616   9. PHPUnit\Framework\TestCase->runTest() /laminas-code/vendor/phpunit/phpunit/src/Framework/TestCase.php:1133
    0.0370    4490616  10. LaminasTest\Code\Scanner\DocBlockScannerTest->testEmptyDocBlock() /laminas-code/vendor/phpunit/phpunit/src/Framework/TestCase.php:1527
    0.0370    4490744  11. Laminas\Code\Scanner\DocBlockScanner->getShortDescription() /laminas-code/test/Scanner/DocBlockScannerTest.php:59
    0.0370    4490744  12. Laminas\Code\Scanner\DocBlockScanner->scan() /laminas-code/src/Scanner/DocBlockScanner.php:49
    0.0370    4490744  13. Laminas\Code\Scanner\DocBlockScanner->tokenize() /laminas-code/src/Scanner/DocBlockScanner.php:85
    0.0371    4498592  14. Laminas\Code\Scanner\DocBlockScanner->Laminas\Code\Scanner\{closure:/laminas-code/src/Scanner/DocBlockScanner.php:196-198}() /laminas-code/src/Scanner/DocBlockScanner.php:300



Time: 00:00.023, Memory: 6.00 MB

OK (3 tests, 10 assertions)

@froschdesign
Copy link
Member

@mtorromeo

It seems like the error is not being converted to an exception but it I think it should.

See: https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md#9510---2021-09-25

@mtorromeo
Copy link
Contributor Author

@froschdesign thanks, should I change that setting as part of this PR then?

Verified

This commit was signed with the committer’s verified signature. The key has expired.
mtorromeo Massimiliano Torromeo
DocScanner may raise a Deprecated error with PHP 8.1 if shortDescription is used before initialization, the default value being null

Signed-off-by: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
@mtorromeo
Copy link
Contributor Author

I found the input that was causing the original deprecation notice and updated the test accordingly.

It's an invalid docblock, but that's what laminas-json-server passed to DocBlockParser, don't know why yet.

Still worth fixing the deprecation IMO.

…ing to upstream type improvements

Signed-off-by: Marco Pivetta <ocramius@gmail.com>
@Ocramius Ocramius changed the base branch from 4.6.x to 4.5.x December 19, 2021 18:06
@Ocramius Ocramius added this to the 4.5.1 milestone Dec 19, 2021
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mtorromeo!

@Ocramius Ocramius assigned Ocramius and unassigned mtorromeo Dec 19, 2021
@Ocramius Ocramius merged commit 6fd96d4 into laminas:4.5.x Dec 19, 2021
@Ocramius Ocramius changed the title Fixed deprecated null parameter in trim Fixed deprecated null parameter in trim() call Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants