Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed Jun 2, 2017
1 parent a94a1f0 commit 7ab8f07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public function __construct(array $config, Repository $cache, InitialGenerator $
$this->borderColor = $config['border']['color'];

$this->cache = $cache;
$this->initialGenerator = $initialGenerator->setUppercase($config['uppercase']);
$this->initialGenerator = $initialGenerator;

$this->initialGenerator->setUppercase($config['uppercase']);
$this->initialGenerator->setAscii($config['ascii']);
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/InitialGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ public function setName($name)
}

$this->name = $name;

return $this;
}

public function setLength($length = 2)
{
$this->length = $length;

return $this;
}

public function setAscii($ascii)
Expand All @@ -69,15 +65,11 @@ public function setAscii($ascii)
if ($this->ascii) {
$this->name = $this->name->toAscii();
}

return $this;
}

public function setUppercase($uppercase)
{
$this->uppercase = $uppercase;

return $this;
}

public function getInitial()
Expand Down
13 changes: 9 additions & 4 deletions tests/AvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public function it_can_instantiated()

$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('getInitial')->andReturn('AB');
$generator->shouldReceive('setUppercase')->andReturnSelf();
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');

new \Laravolt\Avatar\Avatar([], $cache, $generator);
}
Expand Down Expand Up @@ -40,6 +41,7 @@ public function it_can_override_attributes_when_instantiated()
$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('getInitial')->andReturn('AB');
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');

$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);

Expand All @@ -66,7 +68,8 @@ public function it_can_override_attributes_after_set_name()
$generator->shouldReceive('setName')->andReturnSelf();
$generator->shouldReceive('setLength');
$generator->shouldReceive('getInitial')->andReturn('A');
$generator->shouldReceive('setUppercase')->andReturnSelf();
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');
$generator->shouldReceive('base_path');
$config = ['backgrounds' => ['#000000', '#111111'], 'foregrounds' => ['#EEEEEE', '#FFFFFF']];

Expand All @@ -90,7 +93,8 @@ public function it_has_correct_random_background()
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');

$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('setUppercase')->andReturnSelf();
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');

$avatar = new \Laravolt\Avatar\Avatar($config, $cache, $generator);
$avatar->setFontFolder(['fonts/']);
Expand Down Expand Up @@ -119,7 +123,8 @@ public function it_has_different_random_background()
$cache = Mockery::mock('Illuminate\Contracts\Cache\Repository');

$generator = Mockery::mock('Laravolt\Avatar\InitialGenerator');
$generator->shouldReceive('setUppercase')->andReturnSelf();
$generator->shouldReceive('setUppercase');
$generator->shouldReceive('setAscii');

$name1 = 'AA';
$name2 = 'AAA';
Expand Down

0 comments on commit 7ab8f07

Please sign in to comment.