Skip to content

Commit

Permalink
isValue improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Jan 22, 2021
1 parent 84de0eb commit b3e7389
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/Elements/Attributes/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,16 @@ public function isValue($check_value) : bool

$current_value = $this->get('value');

if ($current_value instanceof Collection) {
return $current_value->contains($check_value);
}

if (is_array($current_value)) {
return in_array($check_value, $current_value, false);
}

/** @noinspection TypeUnsafeComparisonInspection **/
return is_array($current_value)
? in_array($check_value, $current_value, false)
: $check_value == $current_value;
return $check_value == $current_value;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion tests/Unit/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,25 @@ public function test_value_equality_helper() : void

$this->assertTrue($attributes->isValue('foo'));
$this->assertFalse($attributes->isValue('bar'));
$this->assertFalse($attributes->isValue(1));

$attributes->set('value', ['foo', 'bar']);
$attributes->set('value', ['foo', 'bar', 2]);

$this->assertTrue($attributes->isValue('foo'));
$this->assertTrue($attributes->isValue('bar'));
$this->assertTrue($attributes->isValue(2));
$this->assertTrue($attributes->isValue('2'));
$this->assertFalse($attributes->isValue('baz'));
$this->assertFalse($attributes->isValue(1));

$attributes->set('value', collect(['foo', 'bar', 2]));

$this->assertTrue($attributes->isValue('foo'));
$this->assertTrue($attributes->isValue('bar'));
$this->assertTrue($attributes->isValue(2));
$this->assertTrue($attributes->isValue('2'));
$this->assertFalse($attributes->isValue('baz'));
$this->assertFalse($attributes->isValue(1));
}

public function test_basic_html_rendering() : void
Expand Down

0 comments on commit b3e7389

Please sign in to comment.