Skip to content

Commit 4eabd75

Browse files
Add one more test case
1 parent 2292980 commit 4eabd75

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/StringConfig.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Stfn\RandomString;
66

7+
use Closure;
8+
79
class StringConfig
810
{
911
const CHARSET_UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
@@ -24,7 +26,7 @@ class StringConfig
2426

2527
protected bool $unique = false;
2628

27-
protected \Closure|null $skipCallback = null;
29+
protected Closure|null $skipCallback = null;
2830

2931
public function __construct($length = 16)
3032
{
@@ -149,7 +151,7 @@ public function hasSkipCallback(): bool
149151
return is_callable($this->skipCallback);
150152
}
151153

152-
public function getSkipCallback(): \Closure|null
154+
public function getSkipCallback(): Closure|null
153155
{
154156
return $this->skipCallback;
155157
}
@@ -179,7 +181,7 @@ public function isUnique(): bool
179181
return $this->unique;
180182
}
181183

182-
public function getCount()
184+
public function getCount(): int
183185
{
184186
return $this->count;
185187
}

tests/RandomStringTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ public function test_if_it_fails_after_max_possible_combination_reached()
209209
$instance->generate();
210210
}
211211

212+
public function test_if_it_fails_when_count_is_greater_than_possible_combinations()
213+
{
214+
$config = new StringConfig();
215+
$config->length(2)
216+
->count(5)
217+
->unique()
218+
->charset('01');
219+
220+
$instance = new RandomString($config);
221+
222+
$this->expectException(InvalidStringConfigException::class);
223+
$instance->generate();
224+
}
225+
212226
public function test_if_it_fails_after_max_possible_combination_reached_using_unique()
213227
{
214228
$config = new StringConfig();

0 commit comments

Comments
 (0)