Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Merge 3085aea into fc126f2
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldyrynda committed May 30, 2018
2 parents fc126f2 + 3085aea commit 11f39ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
2 changes: 0 additions & 2 deletions .styleci.yml
@@ -1,3 +1 @@
preset: laravel

linting: true
12 changes: 8 additions & 4 deletions src/CardAttribute.php
Expand Up @@ -110,11 +110,11 @@ public function icon($icon, $icon2 = null)
*/
public function __construct($value = null, $label = null)
{
if (! empty($value)) {
if (trim($value) !== '') {
$this->value($value);
}

if (! empty($label)) {
if (trim($label) !== '') {
$this->label($label);
}
}
Expand All @@ -138,14 +138,18 @@ public function toArray()
'label' => $this->value,
'url' => $this->url,
'style' => $this->style,
]),
], function ($value) {
return trim($value) !== '';
}),
];

if (! empty($this->icon)) {
$attribute['value']['icon'] = array_filter([
'url' => $this->icon,
'url@2x' => $this->icon2,
]);
], function ($value) {
return trim($value) !== '';
});
}

if (! empty($this->label)) {
Expand Down
35 changes: 35 additions & 0 deletions tests/CardAttributeTest.php
Expand Up @@ -59,4 +59,39 @@ public function test_it_transforms_to_array_being_partially_populated()
],
], $attribute->toArray());
}

public function test_it_allows_empty_values_in_attributes()
{
$attribute = CardAttribute::create()
->value(0)
->label('Signups today');

$this->assertEquals([
'value' => [
'label' => '0',
],
'label' => 'Signups today',
], $attribute->toArray());
}

public function test_it_allows_empty_values_in_create()
{
$attribute = CardAttribute::create(0, 'Signups today');

$this->assertEquals([
'value' => [
'label' => '0',
],
'label' => 'Signups today',
], $attribute->toArray());

$attribute = new CardAttribute(0, 'Signups today');

$this->assertEquals([
'value' => [
'label' => '0',
],
'label' => 'Signups today',
], $attribute->toArray());
}
}

0 comments on commit 11f39ec

Please sign in to comment.