Skip to content

Commit

Permalink
PHP 8.1/LibraryInstallerTest: add missing mock expectation
Browse files Browse the repository at this point in the history
The `LibraryInstallerTest::testUninstall()` method mocks a `Package` object, but did not set an expectation for a call to `getName()`, while that method _is_ called in the `LibraryInstaller::uninstall()` method.

Without expectation, the mock returns `null`, which was subsequently being passed on to `strpos()` leading to the below error.

Fixes:
```
Deprecation triggered by Composer\Test\Installer\LibraryInstallerTest::testUninstall:
strpos(): Passing null to parameter composer#1 ($haystack) of type string is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 202)
1 src/Composer/Installer/LibraryInstaller.php(202): strpos(NULL, '...')
2 vendor/react/promise/src/FulfilledPromise.php(28): Composer\Installer\LibraryInstaller->Composer\Installer\{closure}(NULL)
3 src/Composer/Installer/LibraryInstaller.php(208): React\Promise\FulfilledPromise->then(Object(Closure))
4 tests/Composer/Test/Installer/LibraryInstallerTest.php(221): Composer\Installer\LibraryInstaller->uninstall(Object(Mock_InstalledRepositoryInterface_e3699f95), Object(Mock_Package_e4571076))
...
```
  • Loading branch information
jrfnl committed Aug 12, 2021
1 parent c65bd83 commit 7004e0d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/Composer/Test/Installer/LibraryInstallerTest.php
Expand Up @@ -201,6 +201,10 @@ public function testUninstall()
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('pkg'));
$package
->expects($this->any())
->method('getName')
->will($this->returnValue('pkg'));

$this->repository
->expects($this->exactly(2))
Expand Down

0 comments on commit 7004e0d

Please sign in to comment.