-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathWebhookSystemConfigHelperTest.php
83 lines (73 loc) · 2.43 KB
/
WebhookSystemConfigHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php declare(strict_types=1);
/*
* (c) shopware AG <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Swag\PayPal\Test\Webhook\Registration;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Swag\PayPal\Setting\Service\SettingsValidationServiceInterface;
use Swag\PayPal\Setting\Settings;
use Swag\PayPal\Webhook\Registration\WebhookSystemConfigHelper;
use Swag\PayPal\Webhook\WebhookServiceInterface;
/**
* @internal
*/
#[Package('checkout')]
#[CoversClass(WebhookSystemConfigHelper::class)]
class WebhookSystemConfigHelperTest extends TestCase
{
private const WEBHOOK_KEYS = [
Settings::CLIENT_ID,
Settings::CLIENT_SECRET,
Settings::CLIENT_ID_SANDBOX,
Settings::CLIENT_SECRET_SANDBOX,
Settings::SANDBOX,
Settings::WEBHOOK_ID,
];
private WebhookSystemConfigHelper $helper;
protected function setUp(): void
{
$this->helper = new WebhookSystemConfigHelper(
new NullLogger(),
$this->createMock(WebhookServiceInterface::class),
$this->createMock(SystemConfigService::class),
$this->createMock(SettingsValidationServiceInterface::class),
);
}
/**
* @param array<string, mixed> $config
*/
#[DataProvider('providerNeedsCheck')]
public function testNeedsCheck(bool $expected, array $config): void
{
static::assertSame($expected, $this->helper->needsCheck($config));
}
public static function providerNeedsCheck(): \Generator
{
foreach (self::WEBHOOK_KEYS as $key) {
yield \sprintf('needs check for "%s"', $key) => [
true,
[$key => 'some-value'],
];
yield \sprintf('needs check for "%s" with null value', $key) => [
true,
[$key => null],
];
}
foreach (Settings::DEFAULT_VALUES as $key => $value) {
if (\in_array($key, self::WEBHOOK_KEYS, true)) {
continue;
}
yield \sprintf('no check for "%s"', $key) => [
false,
[$key => $value],
];
}
}
}