Skip to content

Commit 73d0144

Browse files
OskarStarkfabpot
authored andcommitted
[Mailer][Notifier] Add and use Dsn::getBooleanOption()
1 parent 217ed65 commit 73d0144

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add `Dsn::getBooleanOption()`
8+
49
7.2
510
---
611

Tests/Transport/DsnTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,29 @@ public static function getRequiredOptionThrowsMissingRequiredOptionExceptionProv
259259
'with_empty_string',
260260
];
261261
}
262+
263+
/**
264+
* @dataProvider getBooleanOptionProvider
265+
*/
266+
public function testGetBooleanOption(bool $expected, string $dsnString, string $option, bool $default)
267+
{
268+
$dsn = new Dsn($dsnString);
269+
270+
$this->assertSame($expected, $dsn->getBooleanOption($option, $default));
271+
}
272+
273+
public static function getBooleanOptionProvider(): iterable
274+
{
275+
yield [true, 'scheme://localhost?enabled=1', 'enabled', false];
276+
yield [true, 'scheme://localhost?enabled=true', 'enabled', false];
277+
yield [true, 'scheme://localhost?enabled=on', 'enabled', false];
278+
yield [true, 'scheme://localhost?enabled=yes', 'enabled', false];
279+
yield [false, 'scheme://localhost?enabled=0', 'enabled', false];
280+
yield [false, 'scheme://localhost?enabled=false', 'enabled', false];
281+
yield [false, 'scheme://localhost?enabled=off', 'enabled', false];
282+
yield [false, 'scheme://localhost?enabled=no', 'enabled', false];
283+
284+
yield [false, 'scheme://localhost', 'not_existant', false];
285+
yield [true, 'scheme://localhost', 'not_existant', true];
286+
}
262287
}

Transport/Dsn.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public function getRequiredOption(string $key): mixed
9393
return $this->options[$key];
9494
}
9595

96+
public function getBooleanOption(string $key, bool $default = false): bool
97+
{
98+
return filter_var($this->getOption($key, $default), \FILTER_VALIDATE_BOOLEAN);
99+
}
100+
96101
public function getOptions(): array
97102
{
98103
return $this->options;

0 commit comments

Comments
 (0)