Skip to content

Commit 76e27fb

Browse files
committed
fix withCredentials method
Signed-off-by: mesilov <[email protected]>
1 parent 60a8a7b commit 76e27fb

File tree

7 files changed

+58
-27
lines changed

7 files changed

+58
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646
* method `Services\Main\Service::getAllMethods` marks as deprecated
4747
* method `Services\Main\Service::getMethodsByScope` marks as deprecated
4848
* fabric methods for `Bitrix24\SDK\Core\Credentials`
49-
are [consistent](https://github.com/mesilov/bitrix24-php-sdk/issues/303): `createFromWebhook`, `createFromOAuth`, `createFromPlacementRequest`
49+
are [consistent](https://github.com/mesilov/bitrix24-php-sdk/issues/303): `createFromWebhook`, `createFromOAuth`
50+
, `createFromPlacementRequest`
5051
* deleted [unused class](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `Bitrix24\SDK\Core\Response\DTO\ResponseDataCollection`
51-
52+
* deleted [method](https://github.com/mesilov/bitrix24-php-sdk/issues/303) `CoreBuilder::withWebhookUrl`, use
53+
method `CoreBuilder::withCredentials`
5254

5355
### Bugfix
5456

src/Core/CoreBuilder.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class CoreBuilder
2727
protected HttpClientInterface $httpClient;
2828
protected EventDispatcherInterface $eventDispatcher;
2929
protected LoggerInterface $logger;
30-
protected ?WebhookUrl $webhookUrl;
3130
protected ?Credentials $credentials;
3231
protected ApiLevelErrorHandler $apiLevelErrorHandler;
3332

@@ -44,7 +43,6 @@ public function __construct()
4443
'timeout' => 120,
4544
]
4645
);
47-
$this->webhookUrl = null;
4846
$this->credentials = null;
4947
$this->apiClient = null;
5048
$this->apiLevelErrorHandler = new ApiLevelErrorHandler($this->logger);
@@ -62,20 +60,6 @@ public function withCredentials(Credentials $credentials): self
6260
return $this;
6361
}
6462

65-
/**
66-
* @param string $webhookUrl
67-
*
68-
* @return $this
69-
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
70-
* @deprecated use withCredentials
71-
*/
72-
public function withWebhookUrl(string $webhookUrl): self
73-
{
74-
$this->webhookUrl = new WebhookUrl($webhookUrl);
75-
76-
return $this;
77-
}
78-
7963
/**
8064
* @param ApiClientInterface $apiClient
8165
*
@@ -118,10 +102,8 @@ public function withEventDispatcher(EventDispatcherInterface $eventDispatcher):
118102
*/
119103
public function build(): CoreInterface
120104
{
121-
if ($this->webhookUrl !== null) {
122-
$this->credentials = Credentials::createFromWebhook($this->webhookUrl);
123-
} elseif ($this->credentials === null) {
124-
throw new InvalidArgumentException('you must set webhook url or oauth credentials before call method build');
105+
if ($this->credentials === null) {
106+
throw new InvalidArgumentException('you must set credentials before call method build');
125107
}
126108

127109
if ($this->apiClient === null) {

tests/Integration/Fabric.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface;
1010
use Bitrix24\SDK\Core\Contracts\CoreInterface;
1111
use Bitrix24\SDK\Core\CoreBuilder;
12+
use Bitrix24\SDK\Core\Credentials\Credentials;
1213
use Bitrix24\SDK\Services\ServiceBuilder;
1314
use Monolog\Handler\StreamHandler;
1415
use Monolog\Logger;
@@ -57,7 +58,7 @@ public static function getCore(): CoreInterface
5758
{
5859
return (new CoreBuilder())
5960
->withLogger(self::getLogger())
60-
->withWebhookUrl($_ENV['BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK'] ?? $_ENV['BITRIX24_WEBHOOK'])
61+
->withCredentials(Credentials::createFromWebhook($_ENV['BITRIX24_PHP_SDK_PLAYGROUND_WEBHOOK'] ?? $_ENV['BITRIX24_WEBHOOK']))
6162
->build();
6263
}
6364

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Tests\Unit\Core;
6+
7+
use Bitrix24\SDK\Core\CoreBuilder;
8+
use Bitrix24\SDK\Core\Credentials\Credentials;
9+
use Bitrix24\SDK\Core\Credentials\WebhookUrl;
10+
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
11+
use Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class CoreBuilderTest extends TestCase
15+
{
16+
/**
17+
* @throws UnknownScopeCodeException
18+
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
19+
*/
20+
public function testBuildWithCredentialsFromWebhook(): void
21+
{
22+
$core = (new CoreBuilder())
23+
->withCredentials(Credentials::createFromWebhook(new WebhookUrl('https://127.0.0.1')))
24+
->build();
25+
// successful build core
26+
$this->assertTrue(true);
27+
}
28+
29+
/**
30+
* @throws UnknownScopeCodeException
31+
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
32+
*/
33+
public function testBuildWithoutCredentials(): void
34+
{
35+
$this->expectException(InvalidArgumentException::class);
36+
$core = (new CoreBuilder())
37+
->build();
38+
}
39+
}

tools/DemoDataGenerators/CRM/Contacts/GenerateContactsCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Bitrix24\SDK\Core\Batch;
88
use Bitrix24\SDK\Core\BulkItemsReader\BulkItemsReaderBuilder;
99
use Bitrix24\SDK\Core\CoreBuilder;
10+
use Bitrix24\SDK\Core\Credentials\Credentials;
11+
use Bitrix24\SDK\Core\Credentials\WebhookUrl;
1012
use Bitrix24\SDK\Core\Exceptions\BaseException;
1113
use Bitrix24\SDK\Services\ServiceBuilder;
1214
use InvalidArgumentException;
@@ -114,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
114116
// todo create service builder factory
115117
$core = (new CoreBuilder())
116118
->withLogger($this->logger)
117-
->withWebhookUrl($b24Webhook)
119+
->withCredentials(Credentials::createFromWebhook(new WebhookUrl($b24Webhook)))
118120
->build();
119121
$batch = new Batch(
120122
$core,

tools/PerformanceBenchmarks/ListCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Bitrix24\SDK\Core\Contracts\BatchInterface;
99
use Bitrix24\SDK\Core\Contracts\CoreInterface;
1010
use Bitrix24\SDK\Core\CoreBuilder;
11+
use Bitrix24\SDK\Core\Credentials\Credentials;
12+
use Bitrix24\SDK\Core\Credentials\WebhookUrl;
1113
use Bitrix24\SDK\Core\Exceptions\BaseException;
1214
use Bitrix24\SDK\Core\Exceptions\TransportException;
1315
use Psr\Log\LoggerInterface;
@@ -147,7 +149,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
147149

148150
$this->core = (new CoreBuilder())
149151
->withLogger($this->logger)
150-
->withWebhookUrl($b24Webhook)
152+
->withCredentials(Credentials::createFromWebhook(new WebhookUrl($b24Webhook)))
151153
->build();
152154
$this->batch = new Batch(
153155
$this->core,

tools/ShowFieldsDescriptionCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Bitrix24\SDK\Tools;
66

77
use Bitrix24\SDK\Core\Contracts\CoreInterface;
8+
use Bitrix24\SDK\Core\CoreBuilder;
9+
use Bitrix24\SDK\Core\Credentials\Credentials;
10+
use Bitrix24\SDK\Core\Credentials\WebhookUrl;
811
use Bitrix24\SDK\Core\Exceptions\BaseException;
912
use Bitrix24\SDK\Core\Response\Response;
1013
use Psr\Log\LoggerInterface;
@@ -80,9 +83,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8083

8184
$io = new SymfonyStyle($input, $output);
8285
try {
83-
$this->core = (new \Bitrix24\SDK\Core\CoreBuilder())
86+
$this->core = (new CoreBuilder())
8487
->withLogger($this->logger)
85-
->withWebhookUrl($b24Webhook)
88+
->withCredentials(Credentials::createFromWebhook(new WebhookUrl($b24Webhook)))
8689
->build();
8790

8891
$methods = $this->core->call('methods', ['full' => true])->getResponseData()->getResult()->getResultData();

0 commit comments

Comments
 (0)