diff options
author | Anna Larch <anna@nextcloud.com> | 2022-05-13 13:44:12 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2022-05-13 13:44:12 +0300 |
commit | 3a0b600c45f43975157d7944f8affd0c11f99e2a (patch) | |
tree | 9464154aec5584d29ce40b54ef9aaf126531c531 | |
parent | 14c76935d6e459c5f3a79ce53c31f4916a8961c7 (diff) |
fixup! Add check for empty search resultfix/undefined-offset-social-api
-rw-r--r-- | lib/Service/SocialApiService.php | 8 | ||||
-rw-r--r-- | tests/unit/Service/SocialApiServiceTest.php | 16 |
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index c2272987..c62538d3 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -38,6 +38,7 @@ use OCP\IAddressBook; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; +use Psr\Log\LoggerInterface; class SocialApiService { private $appName; @@ -57,6 +58,8 @@ class SocialApiService { private $davBackend; /** @var ITimeFactory */ private $timeFactory; + /** @var LoggerInterface */ + private $logger; public function __construct( @@ -67,7 +70,8 @@ class SocialApiService { IL10N $l10n, IURLGenerator $urlGen, CardDavBackend $davBackend, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + LoggerInterface $logger) { $this->appName = Application::APP_ID; $this->socialProvider = $socialProvider; $this->manager = $manager; @@ -77,6 +81,7 @@ class SocialApiService { $this->urlGen = $urlGen; $this->davBackend = $davBackend; $this->timeFactory = $timeFactory; + $this->logger = $logger; } @@ -183,6 +188,7 @@ class SocialApiService { $contacts = $addressBook->search($contactId, ['UID'], ['types' => true]); if (empty($contacts)) { + $this->logger->warning('Could not find contact in address book #' . urldecode($addressbookId) . ' with contact #' . $contactId); return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); } diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index cd7e1e43..014d890f 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -42,6 +42,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use PHPUnit\Framework\MockObject\MockObject; use ChristophWurst\Nextcloud\Testing\TestCase; +use Psr\Log\LoggerInterface; class SocialApiServiceTest extends TestCase { private SocialApiService $service; @@ -62,6 +63,8 @@ class SocialApiServiceTest extends TestCase { private $davBackend; /** @var ITimeFactory|MockObject */ private $timeFactory; + /** @var MockObject|LoggerInterface */ + private $logger; public function allSocialProfileProviders(): array { $body = "the body"; @@ -127,6 +130,7 @@ class SocialApiServiceTest extends TestCase { $this->urlGen = $this->createMock(IURLGenerator::class); $this->davBackend = $this->createMock(CardDavBackend::class); $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->service = new SocialApiService( $this->socialProvider, $this->manager, @@ -135,7 +139,8 @@ class SocialApiServiceTest extends TestCase { $this->l10n, $this->urlGen, $this->davBackend, - $this->timeFactory + $this->timeFactory, + $this->logger ); } @@ -175,11 +180,10 @@ class SocialApiServiceTest extends TestCase { ->method('NewClient') ->willReturn($client); - $result = $this->service - ->updateContact( - 'contacts', - '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0', - null); + $result = $this->service->updateContact( + 'contacts', + '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0', + null); $this->assertEquals($status, $result->getStatus()); } |