2018-07-08 20:50:19 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace common\tests\unit\tasks;
|
2018-07-08 20:50:19 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
use Carbon\Exceptions\UnreachableException;
|
2020-10-01 04:10:28 +05:30
|
|
|
use common\notifications\NotificationInterface;
|
2018-07-08 20:50:19 +05:30
|
|
|
use common\tasks\CreateWebHooksDeliveries;
|
|
|
|
use common\tasks\DeliveryWebHook;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures;
|
|
|
|
use common\tests\unit\TestCase;
|
2018-07-08 20:50:19 +05:30
|
|
|
use yii\queue\Queue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \common\tasks\CreateWebHooksDeliveries
|
|
|
|
*/
|
|
|
|
class CreateWebHooksDeliveriesTest extends TestCase {
|
|
|
|
|
|
|
|
public function _fixtures(): array {
|
|
|
|
return [
|
|
|
|
'webhooks' => fixtures\WebHooksFixture::class,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testExecute(): void {
|
2020-10-01 04:10:28 +05:30
|
|
|
$notification = new class implements NotificationInterface {
|
|
|
|
public static function getType(): string {
|
|
|
|
return 'account.edit';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPayloads(): array {
|
|
|
|
return ['key' => 'value'];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$queue = $this->createMock(Queue::class);
|
2024-12-02 15:40:55 +05:30
|
|
|
$invocationCount = $this->exactly(2);
|
|
|
|
$queue->expects($invocationCount)->method('push')->willReturnCallback(function(DeliveryWebHook $task) use ($invocationCount): bool {
|
|
|
|
if ($invocationCount->numberOfInvocations() === 1) {
|
2020-10-01 04:10:28 +05:30
|
|
|
$this->assertSame('account.edit', $task->type);
|
|
|
|
$this->assertSame(['key' => 'value'], $task->payloads);
|
|
|
|
$this->assertSame('http://localhost:80/webhooks/ely', $task->url);
|
|
|
|
$this->assertSame('my-secret', $task->secret);
|
|
|
|
|
|
|
|
return true;
|
2024-12-02 15:40:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if ($invocationCount->numberOfInvocations() === 2) {
|
2020-10-01 04:10:28 +05:30
|
|
|
$this->assertSame('account.edit', $task->type);
|
|
|
|
$this->assertSame(['key' => 'value'], $task->payloads);
|
|
|
|
$this->assertSame('http://localhost:81/webhooks/ely', $task->url);
|
|
|
|
$this->assertNull($task->secret);
|
|
|
|
|
|
|
|
return true;
|
2024-12-02 15:40:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
throw new UnreachableException();
|
|
|
|
});
|
2020-10-01 04:10:28 +05:30
|
|
|
|
|
|
|
$task = new CreateWebHooksDeliveries($notification);
|
|
|
|
$task->execute($queue);
|
2018-07-08 20:50:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|