Skip to content

Commit 6ccb138

Browse files
author
Robin Cawser
committed
Generator created at point of calling generate()
1 parent 1757768 commit 6ccb138

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

spec/Vivait/StringGeneratorBundle/Generator/SecureStringGeneratorSpec.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
class SecureStringGeneratorSpec extends ObjectBehavior
1313
{
14-
15-
/**
16-
* @var Factory
17-
*/
18-
private $factory;
19-
2014
function it_is_initializable()
2115
{
2216
$this->shouldHaveType('Vivait\StringGeneratorBundle\Generator\SecureStringGenerator');
@@ -37,11 +31,6 @@ function let(Factory $factory, Generator $low, Generator $medium)
3731
$this->setOptions($defaults);
3832
}
3933

40-
function it_chooses_medium_strength_gen_by_default(Generator $medium)
41-
{
42-
$this->getGenerator()->shouldReturn($medium);
43-
}
44-
4534
function it_chooses_a_specified_strength_gen(Generator $medium, Generator $low)
4635
{
4736
$this->getGenerator('medium')->shouldReturn($medium);

src/Vivait/StringGeneratorBundle/Generator/SecureStringGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public function __construct(Factory $factory)
4444
*/
4545
public function generate()
4646
{
47-
return $this->generator->generateString($this->length, $this->chars);
47+
return $this->getGenerator($this->strength)->generateString($this->length, $this->chars);
4848
}
4949

50-
public function getGenerator($strength = 'medium')
50+
public function getGenerator($strength)
5151
{
5252
switch ($strength) {
5353
case 'low':
@@ -63,7 +63,7 @@ public function getGenerator($strength = 'medium')
6363

6464
public function setOptions(array $options)
6565
{
66-
$this->generator = $this->getGenerator($options['strength']);
66+
$this->strength = $options['strength'];
6767
$this->length = $options['length'];
6868
$this->chars = $options['chars'];
6969
}

0 commit comments

Comments
 (0)