From 527e1d2e5769200318f66e5df34816e36cf5fb57 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 26 Jun 2022 12:15:40 +0200 Subject: [PATCH] [BUGFIX] Avoid using deprecated classes and methods Fixes #828 --- CHANGELOG.md | 2 +- .../AbstractConfigurationCheck.php | 17 ++- Classes/Domain/Repository/PageRepository.php | 16 ++- Classes/Mapper/AbstractDataMapper.php | 30 ++++- Classes/Mapper/FrontEndUserMapper.php | 14 ++- Classes/Testing/CacheNullifyer.php | 4 +- Classes/Testing/TestingFramework.php | 118 ++++++++++++++---- .../Functional/Testing/CacheNullifyerTest.php | 10 +- .../Testing/TestingFrameworkTest.php | 6 +- Tests/Unit/Geocoding/GoogleGeocodingTest.php | 18 +-- 10 files changed, 178 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10662290d..e72655b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Always drop empty values for `intExplode` calls (#1000) - Discard invalid gender values (#996) - Avoid some version-specific tests (#964, #967) -- Avoid deprecated `settingLanguage` calls (#955) +- Avoid calls to deprecated classes and methods (#955, #1014) - Build a more complete fake frontend (#954) - Use proper mocking with 11LTS in the storage-related tests (#951) - Fix compatibility with newer DBAL versions (#950) diff --git a/Classes/Configuration/AbstractConfigurationCheck.php b/Classes/Configuration/AbstractConfigurationCheck.php index 0244c36d4..7ad888204 100644 --- a/Classes/Configuration/AbstractConfigurationCheck.php +++ b/Classes/Configuration/AbstractConfigurationCheck.php @@ -208,10 +208,21 @@ protected function buildWarningStartWithKeyAndValue(string $key, $value): string private function getDbColumnNames(string $tableName): array { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName); - $statement = $connection->query('SHOW FULL COLUMNS FROM `' . $tableName . '`'); + $query = 'SHOW FULL COLUMNS FROM `' . $tableName . '`'; + if (\method_exists($connection, 'executeQuery')) { + $statement = $connection->executeQuery($query); + } else { + $statement = $connection->query($query); + } $columns = []; - foreach ($statement->fetchAll() as $row) { - $columns[] = $row['Field']; + if (\method_exists($statement, 'fetchAllAssociative')) { + foreach ($statement->fetchAllAssociative() as $row) { + $columns[] = $row['Field']; + } + } else { + foreach ($statement->fetchAll() as $row) { + $columns[] = $row['Field']; + } } return $columns; diff --git a/Classes/Domain/Repository/PageRepository.php b/Classes/Domain/Repository/PageRepository.php index 029dfcb1d..3911c17ec 100644 --- a/Classes/Domain/Repository/PageRepository.php +++ b/Classes/Domain/Repository/PageRepository.php @@ -84,10 +84,18 @@ private function findDirectSubpages(array $pageUids): array $subpageUids = []; $queryResult = $query->execute(); if ($queryResult instanceof ResultStatement) { - foreach ($queryResult->fetchAll() as $row) { - /** @var positive-int $uid */ - $uid = (int)$row['uid']; - $subpageUids[] = $uid; + if (\method_exists($queryResult, 'fetchAllAssociative')) { + foreach ($queryResult->fetchAllAssociative() as $row) { + /** @var positive-int $uid */ + $uid = (int)$row['uid']; + $subpageUids[] = $uid; + } + } else { + foreach ($queryResult->fetchAll() as $row) { + /** @var positive-int $uid */ + $uid = (int)$row['uid']; + $subpageUids[] = $uid; + } } } return $subpageUids; diff --git a/Classes/Mapper/AbstractDataMapper.php b/Classes/Mapper/AbstractDataMapper.php index eb79a7518..7dff4f17e 100644 --- a/Classes/Mapper/AbstractDataMapper.php +++ b/Classes/Mapper/AbstractDataMapper.php @@ -651,7 +651,11 @@ protected function retrieveRecord(array $whereClauseParts): array throw new \UnexpectedValueException('Expected ResultStatement, got int instead.', 1646321598); } - $data = $result->fetch(); + if (\method_exists($result, 'fetchAssociative')) { + $data = $result->fetchAssociative(); + } else { + $data = $result->fetch(); + } if ($data === false) { throw new NotFoundException( 'No records found in the table "' . $tableName . '" matching: ' . \json_encode($whereClauseParts) @@ -1227,7 +1231,13 @@ public function findByPageUid($pageUids, string $sorting = ''): Collection throw new \UnexpectedValueException('Expected ResultStatement, got int instead.', 1646321575); } - return $this->getListOfModels($result->fetchAll()); + if (\method_exists($result, 'fetchAllAssociative')) { + $modelData = $result->fetchAllAssociative(); + } else { + $modelData = $result->fetchAll(); + } + + return $this->getListOfModels($modelData); } /** @@ -1517,7 +1527,13 @@ public function findAllByRelation( throw new \UnexpectedValueException('Expected ResultStatement, got int instead.', 1646321551); } - return $this->getListOfModels($result->fetchAll()); + if (\method_exists($result, 'fetchAllAssociative')) { + $modelData = $result->fetchAllAssociative(); + } else { + $modelData = $result->fetchAll(); + } + + return $this->getListOfModels($modelData); } /** @@ -1536,7 +1552,13 @@ public function countByPageUid(string $pageUids): int throw new \UnexpectedValueException('Expected ResultStatement, got int instead.', 1646321386); } - return (int)$result->fetchColumn(); + if (\method_exists($result, 'fetchOne')) { + $count = (int)$result->fetchOne(); + } else { + $count = (int)$result->fetchColumn(); + } + + return $count; } /** diff --git a/Classes/Mapper/FrontEndUserMapper.php b/Classes/Mapper/FrontEndUserMapper.php index 3e41c6a4a..410dea8d6 100644 --- a/Classes/Mapper/FrontEndUserMapper.php +++ b/Classes/Mapper/FrontEndUserMapper.php @@ -78,8 +78,18 @@ public function getGroupMembers($commaSeparatedGroupUids): Collection $tableName = $this->getTableName(); $where = 'deleted = 0 AND disable = 0 AND usergroup REGEXP \'(^|,)(' . \implode('|', $groupUids) . ')($|,)\''; $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName); - $statement = $connection->query('SELECT * FROM `' . $tableName . '` WHERE ' . $where); + $query = 'SELECT * FROM `' . $tableName . '` WHERE ' . $where; + if (\method_exists($connection, 'executeQuery')) { + $statement = $connection->executeQuery($query); + } else { + $statement = $connection->query($query); + } + if (\method_exists($statement, 'fetchAllAssociative')) { + $modelData = $statement->fetchAllAssociative(); + } else { + $modelData = $statement->fetchAll(); + } - return $this->getListOfModels($statement->fetchAll()); + return $this->getListOfModels($modelData); } } diff --git a/Classes/Testing/CacheNullifyer.php b/Classes/Testing/CacheNullifyer.php index 951ad951d..4003c84b4 100644 --- a/Classes/Testing/CacheNullifyer.php +++ b/Classes/Testing/CacheNullifyer.php @@ -4,12 +4,12 @@ namespace OliverKlee\Oelib\Testing; -use OliverKlee\Oelib\System\Typo3Version; use TYPO3\CMS\Core\Cache\Backend\NullBackend; use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend; use TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache; @@ -24,7 +24,7 @@ final class CacheNullifyer */ public function setAllCoreCaches(): void { - if (Typo3Version::isNotHigherThan(9)) { + if ((new Typo3Version())->getMajorVersion() <= 9) { $this->disableCoreCachesForVersion9(); } else { $this->disableCoreCachesForVersion10(); diff --git a/Classes/Testing/TestingFramework.php b/Classes/Testing/TestingFramework.php index 630e669c0..b62dd7df5 100644 --- a/Classes/Testing/TestingFramework.php +++ b/Classes/Testing/TestingFramework.php @@ -11,7 +11,6 @@ use OliverKlee\Oelib\Mapper\FrontEndUserMapper; use OliverKlee\Oelib\Mapper\MapperRegistry; use OliverKlee\Oelib\Model\FrontEndUserGroup; -use OliverKlee\Oelib\System\Typo3Version; use Psr\Log\NullLogger; use TYPO3\CMS\Core\Configuration\SiteConfiguration; use TYPO3\CMS\Core\Context\Context; @@ -21,6 +20,7 @@ use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Exception\Page\PageNotFoundException; use TYPO3\CMS\Core\Http\Uri; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Localization\Locales; use TYPO3\CMS\Core\Routing\PageArguments; use TYPO3\CMS\Core\Site\Entity\Site; @@ -860,12 +860,26 @@ private function retrieveColumnsForTable(string $table): void return; } + $connection = $this->getConnectionForTable($table); + $query = 'SHOW FULL COLUMNS FROM `' . $table . '`'; + if (\method_exists($connection, 'executeQuery')) { + $queryResult = $connection->executeQuery($query); + } else { + $queryResult = $connection->query($query); + } $columns = []; - $queryResult = $this->getConnectionForTable($table)->query('SHOW FULL COLUMNS FROM `' . $table . '`'); - /** @var array $fieldRow */ - foreach ($queryResult->fetchAll() as $fieldRow) { - $field = $fieldRow['Field']; - $columns[$field] = $fieldRow; + if (\method_exists($queryResult, 'fetchAllAssociative')) { + /** @var array $fieldRow */ + foreach ($queryResult->fetchAllAssociative() as $fieldRow) { + $field = $fieldRow['Field']; + $columns[$field] = $fieldRow; + } + } else { + /** @var array $fieldRow */ + foreach ($queryResult->fetchAll() as $fieldRow) { + $field = $fieldRow['Field']; + $columns[$field] = $fieldRow; + } } self::$tableColumnCache[$table] = $columns; @@ -1204,7 +1218,7 @@ public function createFakeFrontEnd(int $pageUid = 0): int $frontEndUser->unpack_uc(); $frontEndUser->fetchGroupData(); - if (Typo3Version::isAtLeast(10)) { + if ((new Typo3Version())->getMajorVersion() >= 10) { if ($pageUid > 0) { $this->createDummySite($pageUid); $allSites = GeneralUtility::makeInstance(SiteConfiguration::class)->getAllExistingSites(false); @@ -1253,7 +1267,7 @@ public function createFakeFrontEnd(int $pageUid = 0): int $frontEnd->tmpl->runThroughTemplates($rootLine); $frontEnd->tmpl->generateConfig(); $frontEnd->tmpl->loaded = true; - if (Typo3Version::isAtLeast(10)) { + if ((new Typo3Version())->getMajorVersion() >= 10) { Locales::setSystemLocaleFromSiteLanguage($frontEnd->getLanguage()); } else { $frontEnd->settingLocale(); @@ -1541,13 +1555,27 @@ private function retrieveTableNames(): void } $connection = $this->getConnectionPool()->getConnectionByName('Default'); - $queryResult = $connection->query('SHOW TABLE STATUS FROM `' . $connection->getDatabase() . '`'); + $query = 'SHOW TABLE STATUS FROM `' . $connection->getDatabase() . '`'; + if (\method_exists($connection, 'executeQuery')) { + $queryResult = $connection->executeQuery($query); + } else { + $queryResult = $connection->query($query); + } $tableNames = []; - /** @var array $tableInformation */ - foreach ($queryResult->fetchAll() as $tableInformation) { - /** @var non-empty-string $tableName */ - $tableName = $tableInformation['Name']; - $tableNames[$tableName] = $tableInformation; + if (\method_exists($queryResult, 'fetchAllAssociative')) { + /** @var array $tableInformation */ + foreach ($queryResult->fetchAllAssociative() as $tableInformation) { + /** @var non-empty-string $tableName */ + $tableName = $tableInformation['Name']; + $tableNames[$tableName] = $tableInformation; + } + } else { + /** @var array $tableInformation */ + foreach ($queryResult->fetchAll() as $tableInformation) { + /** @var non-empty-string $tableName */ + $tableName = $tableInformation['Name']; + $tableNames[$tableName] = $tableInformation; + } } self::$tableNameCache = $tableNames; @@ -1743,7 +1771,13 @@ public function count(string $table, array $criteria = []): int throw new \UnexpectedValueException('Expected ResultStatement, got int instead.', 1646321756); } - return (int)$result->fetchColumn(); + if (\method_exists($result, 'fetchOne')) { + $count = (int)$result->fetchOne(); + } else { + $count = (int)$result->fetchColumn(); + } + + return $count; } /** @@ -1775,9 +1809,14 @@ public function existsRecordWithUid(string $table, int $uid): bool $dummyColumn = $this->getDummyColumnName($table); $queryResult = $this->getConnectionForTable($table) - ->select(['*'], $table, ['uid' => $uid, $dummyColumn => 1])->fetchAll(); + ->select(['*'], $table, ['uid' => $uid, $dummyColumn => 1]); + if (\method_exists($queryResult, 'fetchAllAssociative')) { + $data = $queryResult->fetchAllAssociative(); + } else { + $data = $queryResult->fetchAll(); + } - return $queryResult !== []; + return $data !== []; } /** @@ -1814,7 +1853,12 @@ public function resetAutoIncrement(string $table): void // Updates the auto increment index for this table. The index will be // set to one UID above the highest existing UID. $connection = $this->getConnectionPool()->getConnectionByName('Default'); - $connection->query('ALTER TABLE `' . $table . '` AUTO_INCREMENT=' . $newAutoIncrementValue . ';'); + $query = 'ALTER TABLE `' . $table . '` AUTO_INCREMENT=' . $newAutoIncrementValue . ';'; + if (\method_exists($connection, 'executeQuery')) { + $connection->executeQuery($query); + } else { + $connection->query($query); + } } /** @@ -1887,10 +1931,20 @@ public function setResetAutoIncrementThreshold(int $threshold): void */ private function getMaximumUidFromTable(string $table): int { - $queryResult = $this->getConnectionForTable($table) - ->query('SELECT MAX(uid) AS uid FROM `' . $table . '`')->fetch(); + $connection = $this->getConnectionForTable($table); + $query = 'SELECT MAX(uid) AS uid FROM `' . $table . '`'; + if (\method_exists($connection, 'executeQuery')) { + $queryResult = $connection->executeQuery($query); + } else { + $queryResult = $connection->query($query); + } + if (\method_exists($queryResult, 'fetchAllAssociative')) { + $data = $queryResult->fetchAllAssociative(); + } else { + $data = $queryResult->fetchAll(); + } - return (int)$queryResult['uid']; + return (int)$data['uid']; } /** @@ -1916,8 +1970,18 @@ public function getAutoIncrement(string $table): int ); } + $connection = $this->getConnectionForTable($table); $query = 'SHOW TABLE STATUS WHERE Name = \'' . $table . '\';'; - $row = $this->getConnectionForTable($table)->query($query)->fetch(); + if (\method_exists($connection, 'executeQuery')) { + $queryResult = $connection->executeQuery($query); + } else { + $queryResult = $connection->query($query); + } + if (\method_exists($queryResult, 'fetchAssociative')) { + $row = $queryResult->fetchAssociative(); + } else { + $row = $queryResult->fetch(); + } $autoIncrement = $row['Auto_increment']; if ($autoIncrement === null) { @@ -2015,8 +2079,14 @@ private function increaseRelationCounter(string $tableName, int $uid, string $fi ); } + $connection = $this->getConnectionForTable($tableName); $query = 'UPDATE ' . $tableName . ' SET ' . $fieldName . '=' . $fieldName . '+1 WHERE uid=' . $uid; - $numberOfAffectedRows = $this->getConnectionForTable($tableName)->query($query)->rowCount(); + if (\method_exists($connection, 'executeQuery')) { + $queryResult = $connection->executeQuery($query); + } else { + $queryResult = $connection->query($query); + } + $numberOfAffectedRows = $queryResult->rowCount(); if ($numberOfAffectedRows === 0) { throw new \BadMethodCallException( 'The table ' . $tableName . ' does not contain a record with UID ' . $uid . '.', @@ -2077,6 +2147,6 @@ private function getFrontEndController(): TypoScriptFrontendController */ public function disableCoreCaches(): void { - $this->cacheNullifyer->disableCoreCaches(); + $this->cacheNullifyer->setAllCoreCaches(); } } diff --git a/Tests/Functional/Testing/CacheNullifyerTest.php b/Tests/Functional/Testing/CacheNullifyerTest.php index 2aa4f54f0..58c10a3cf 100644 --- a/Tests/Functional/Testing/CacheNullifyerTest.php +++ b/Tests/Functional/Testing/CacheNullifyerTest.php @@ -5,13 +5,13 @@ namespace OliverKlee\Oelib\Tests\Functional\Testing; use Nimut\TestingFramework\TestCase\FunctionalTestCase; -use OliverKlee\Oelib\System\Typo3Version; use OliverKlee\Oelib\Testing\CacheNullifyer; use TYPO3\CMS\Core\Cache\Backend\AbstractBackend; use TYPO3\CMS\Core\Cache\Backend\NullBackend; use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend; use TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend; use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -63,7 +63,7 @@ public function coreCachesVersion9DataProvider(): array */ public function disableCoreCachesSetsAllCoreCachesForVersion9(string $identifier, string $backend): void { - if (Typo3Version::isAtLeast(10)) { + if ((new Typo3Version())->getMajorVersion() >= 10) { self::markTestSkipped('This test is specific to TYPO3 9LTS.'); } @@ -81,7 +81,7 @@ public function disableCoreCachesSetsAllCoreCachesForVersion9(string $identifier */ public function setAllCoreCachesSetsAllCoreCachesForVersion9(string $identifier, string $backend): void { - if (Typo3Version::isAtLeast(10)) { + if ((new Typo3Version())->getMajorVersion() >= 10) { self::markTestSkipped('This test is specific to TYPO3 9LTS.'); } @@ -119,7 +119,7 @@ public function coreCachesVersion10DataProvider(): array */ public function disableCoreCachesSetsAllCoreCachesForVersion10(string $identifier, string $backend): void { - if (Typo3Version::isNotHigherThan(9)) { + if ((new Typo3Version())->getMajorVersion() <= 9) { self::markTestSkipped('This test is specific to TYPO3 10LTS.'); } @@ -137,7 +137,7 @@ public function disableCoreCachesSetsAllCoreCachesForVersion10(string $identifie */ public function setAllCoreCachesSetsAllCoreCachesForVersion10(string $identifier, string $backend): void { - if (Typo3Version::isNotHigherThan(9)) { + if ((new Typo3Version())->getMajorVersion() <= 9) { self::markTestSkipped('This test is specific to TYPO3 10LTS.'); } diff --git a/Tests/Functional/Testing/TestingFrameworkTest.php b/Tests/Functional/Testing/TestingFrameworkTest.php index d2f4e252b..c615af3a9 100644 --- a/Tests/Functional/Testing/TestingFrameworkTest.php +++ b/Tests/Functional/Testing/TestingFrameworkTest.php @@ -6,7 +6,6 @@ use Nimut\TestingFramework\TestCase\FunctionalTestCase; use OliverKlee\Oelib\Authentication\FrontEndLoginManager; -use OliverKlee\Oelib\System\Typo3Version; use OliverKlee\Oelib\Testing\TestingFramework; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Cache\Backend\AbstractBackend; @@ -16,6 +15,7 @@ use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\TypoScript\TemplateService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; @@ -3111,7 +3111,7 @@ public function coreCachesVersion9DataProvider(): array */ public function disableCoreCachesSetsAllCoreCachesForVersion9(string $identifier, string $backend): void { - if (Typo3Version::isAtLeast(10)) { + if ((new Typo3Version())->getMajorVersion() >= 10) { self::markTestSkipped('This test is specific to TYPO3 9LTS.'); } @@ -3149,7 +3149,7 @@ public function coreCachesVersion10DataProvider(): array */ public function disableCoreCachesSetsAllCoreCachesForVersion10(string $identifier, string $backend): void { - if (Typo3Version::isNotHigherThan(9)) { + if ((new Typo3Version())->getMajorVersion() <= 9) { self::markTestSkipped('This test is specific to TYPO3 10LTS.'); } diff --git a/Tests/Unit/Geocoding/GoogleGeocodingTest.php b/Tests/Unit/Geocoding/GoogleGeocodingTest.php index 767446626..e1b2a8a0d 100644 --- a/Tests/Unit/Geocoding/GoogleGeocodingTest.php +++ b/Tests/Unit/Geocoding/GoogleGeocodingTest.php @@ -87,7 +87,7 @@ public function lookUpForEmptyAddressWithErrorSendsNoRequest(): void $geo = new TestingGeo(); $geo->setGeoError(); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->expects(self::never())->method('sendRequest'); @@ -106,7 +106,7 @@ public function lookUpForAFullGermanAddressWithCoordinatesSendsNoRequest(): void ['latitude' => 50.7335500, 'longitude' => 7.1014300] ); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->expects(self::never())->method('sendRequest'); @@ -123,7 +123,7 @@ public function lookUpForAFullGermanAddressWithErrorSendsNoRequest(): void $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); $geo->setGeoError(); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->expects(self::never())->method('sendRequest'); @@ -162,7 +162,7 @@ public function lookUpWithErrorSetsGeoProblem(string $status): void $geo = new TestingGeo(); $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->method('sendRequest')->willReturn($jsonResult); @@ -188,7 +188,7 @@ public function lookUpWithErrorSetsGeoProblemAndLogsError(string $status): void $geo = new TestingGeo(); $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->method('sendRequest')->willReturn($jsonResult); @@ -215,7 +215,7 @@ public function lookUpWithErrorLogsErrorDetails(string $status): void $geo = new TestingGeo(); $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->method('sendRequest')->willReturn($jsonResult); @@ -235,7 +235,7 @@ public function lookUpForAFullGermanAddressWithNetworkErrorSetsGeoProblemAndLogs $geo = new TestingGeo(); $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->method('sendRequest')->willReturn(false); @@ -271,7 +271,7 @@ public function lookUpSetsCoordinatesFromSendRequest(): void $geo = new TestingGeo(); $geo->setGeoAddress('Am Hof 1, 53113 Zentrum, Bonn, DE'); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->setMaximumDelay(1); $subject->method('sendRequest')->willReturn($jsonResult); @@ -348,7 +348,7 @@ public function lookUpUsesApiKey(): void $geo = new TestingGeo(); $geo->setGeoAddress($address); - $subject = $this->getMockBuilder(GoogleGeocoding::class)->setMethods(['sendRequest']) + $subject = $this->getMockBuilder(GoogleGeocoding::class)->onlyMethods(['sendRequest']) ->disableOriginalConstructor()->getMock(); $subject->method('sendRequest')->with($expectedUrl)->willReturn($jsonResult);