Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed May 3, 2020
1 parent dc8cb3f commit 4650dd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Concerns/AttributeSetter.php
Expand Up @@ -8,11 +8,11 @@ trait AttributeSetter
{
public function setTheme($theme)
{
if (!array_key_exists($theme, $this->themes)) {
return $this;
}

if (is_string($theme) || is_array($theme)) {
if (is_string($theme) && !array_key_exists($theme, $this->themes)) {
return $this;
}

$this->theme = $theme;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/AvatarPhpTest.php
Expand Up @@ -124,7 +124,7 @@ public function it_can_resolve_random_themes_and_then_overrides()
/**
* @test
*/
public function it_cannot_set_non_existant_theme()
public function it_can_handle_invalid_theme()
{
$config = [
'foregrounds' => ['#000000', '#111111'],
Expand All @@ -137,6 +137,9 @@ public function it_cannot_set_non_existant_theme()

$this->assertAttributeEquals('#000000', 'background', $avatar);
$this->assertAttributeEquals('#111111', 'foreground', $avatar);

$avatar->setTheme(new stdClass())->buildAvatar();
$avatar->setTheme(['satu', 'dua'])->buildAvatar();
}

/**
Expand Down

0 comments on commit 4650dd5

Please sign in to comment.