mirror of
https://github.com/BushlanovDev/max-bot-api-client-php.git
synced 2026-08-28 02:57:27 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79d406da27 |
+1
-1
@@ -48,7 +48,7 @@ use RuntimeException;
|
|||||||
*/
|
*/
|
||||||
class Api
|
class Api
|
||||||
{
|
{
|
||||||
public const string LIBRARY_VERSION = '1.4.0';
|
public const string LIBRARY_VERSION = '1.4.1';
|
||||||
|
|
||||||
public const string API_VERSION = '1.2.5';
|
public const string API_VERSION = '1.2.5';
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ final readonly class PhotoAttachmentRequestPayload extends AbstractAttachmentReq
|
|||||||
#[ArrayOf(PhotoToken::class)]
|
#[ArrayOf(PhotoToken::class)]
|
||||||
public ?array $photos = null,
|
public ?array $photos = null,
|
||||||
) {
|
) {
|
||||||
if (count(array_filter([$this->url, $this->token, $this->photos])) !== 1) {
|
if ($this->url === null && $this->token === null && $this->photos === null) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Provide exactly one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.'
|
'Provide one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ final readonly class ShareAttachmentRequestPayload extends AbstractAttachmentReq
|
|||||||
public ?string $url = null,
|
public ?string $url = null,
|
||||||
public ?string $token = null,
|
public ?string $token = null,
|
||||||
) {
|
) {
|
||||||
if (count(array_filter([$this->url, $this->token])) !== 1) {
|
if ($this->url === null && $this->token === null) {
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'Provide exactly one of "url" or "token" for ShareAttachmentRequestPayload.'
|
'Provide one of "url" or "token" for ShareAttachmentRequestPayload.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoAttachmentRequ
|
|||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoToken;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\PhotoToken;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -77,32 +76,12 @@ final class PhotoAttachmentRequestPayloadTest extends TestCase
|
|||||||
$this->assertEquals($expectedArray, $payload->toArray());
|
$this->assertEquals($expectedArray, $payload->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Data provider for invalid constructor arguments.
|
|
||||||
*
|
|
||||||
* @return array<string, array{0: string|null, 1: string|null, 2: array|null}>
|
|
||||||
*/
|
|
||||||
public static function invalidPayloadProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'all null (no arguments)' => [null, null, null],
|
|
||||||
'url and token provided' => ['https://a.com', 'token123', null],
|
|
||||||
'url and photos provided' => ['https://a.com', null, [new PhotoToken('t')]],
|
|
||||||
'token and photos provided' => [null, 'token123', [new PhotoToken('t')]],
|
|
||||||
'all three arguments provided' => ['https://a.com', 'token123', [new PhotoToken('t')]],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
#[DataProvider('invalidPayloadProvider')]
|
public function constructorThrowsExceptionForInvalidArguments(): void
|
||||||
public function constructorThrowsExceptionForInvalidArguments(
|
{
|
||||||
?string $url,
|
|
||||||
?string $token,
|
|
||||||
?array $photos
|
|
||||||
): void {
|
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Provide exactly one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.');
|
$this->expectExceptionMessage('Provide one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.');
|
||||||
|
|
||||||
new PhotoAttachmentRequestPayload($url, $token, $photos);
|
new PhotoAttachmentRequestPayload(null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,24 +38,12 @@ final class ShareAttachmentRequestPayloadTest extends TestCase
|
|||||||
$this->assertEquals($expectedArray, $payload->toArray());
|
$this->assertEquals($expectedArray, $payload->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, array{0: ?string, 1: ?string}>
|
|
||||||
*/
|
|
||||||
public static function invalidPayloadProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'both null' => [null, null],
|
|
||||||
'both set' => ['https://a.com', 'token123'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
#[DataProvider('invalidPayloadProvider')]
|
public function constructorThrowsExceptionForInvalidArguments(): void
|
||||||
public function constructorThrowsExceptionForInvalidArguments(?string $url, ?string $token): void
|
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Provide exactly one of "url" or "token" for ShareAttachmentRequestPayload.');
|
$this->expectExceptionMessage('Provide one of "url" or "token" for ShareAttachmentRequestPayload.');
|
||||||
|
|
||||||
new ShareAttachmentRequestPayload($url, $token);
|
new ShareAttachmentRequestPayload(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,29 +98,12 @@ final class PhotoAttachmentRequestTest extends TestCase
|
|||||||
$this->assertEquals($expectedArray, $request->toArray());
|
$this->assertEquals($expectedArray, $request->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, array{0: string|null, 1: string|null, 2: array|null}>
|
|
||||||
*/
|
|
||||||
public static function invalidPayloadProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'no arguments' => [null, null, null],
|
|
||||||
'url and token' => ['http://a.com', 'token123', null],
|
|
||||||
'token and photos' => [null, 'token123', [new PhotoToken('t')]],
|
|
||||||
'all arguments' => ['http://a.com', 'token123', [new PhotoToken('t')]],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
#[DataProvider('invalidPayloadProvider')]
|
public function payloadThrowsExceptionWhenNotExactlyOneArgumentIsProvided(): void
|
||||||
public function payloadThrowsExceptionWhenNotExactlyOneArgumentIsProvided(
|
{
|
||||||
?string $url,
|
|
||||||
?string $token,
|
|
||||||
?array $photos
|
|
||||||
): void {
|
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Provide exactly one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.');
|
$this->expectExceptionMessage('Provide one of "url", "token", or "photos" for PhotoAttachmentRequestPayload.');
|
||||||
|
|
||||||
new PhotoAttachmentRequestPayload($url, $token, $photos);
|
new PhotoAttachmentRequestPayload(null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Payloads\ShareAttachmentRequ
|
|||||||
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ShareAttachmentRequest;
|
use BushlanovDev\MaxMessengerBot\Models\Attachments\Requests\ShareAttachmentRequest;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
use PHPUnit\Framework\Attributes\Test;
|
use PHPUnit\Framework\Attributes\Test;
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
use PHPUnit\Framework\Attributes\UsesClass;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -42,21 +41,11 @@ final class ShareAttachmentRequestTest extends TestCase
|
|||||||
$this->assertEquals($expected, $request->toArray());
|
$this->assertEquals($expected, $request->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, array{0: ?string, 1: ?string}> */
|
|
||||||
public static function invalidPayloadProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'both null' => [null, null],
|
|
||||||
'both set' => ['https://a.com', 'token123'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Test]
|
#[Test]
|
||||||
#[DataProvider('invalidPayloadProvider')]
|
public function payloadThrowsExceptionForInvalidArguments(): void
|
||||||
public function payloadThrowsExceptionForInvalidArguments(?string $url, ?string $token): void
|
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
$this->expectExceptionMessage('Provide exactly one of "url" or "token" for ShareAttachmentRequestPayload.');
|
$this->expectExceptionMessage('Provide one of "url" or "token" for ShareAttachmentRequestPayload.');
|
||||||
new ShareAttachmentRequestPayload($url, $token);
|
new ShareAttachmentRequestPayload(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user