Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Fix error when selectors empty
Browse files Browse the repository at this point in the history
  • Loading branch information
xpoback committed Aug 2, 2020
1 parent badb0c4 commit d3bda5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public function getScriptUrl() :string
public function getSelectors(): array
{
$selectors = [];
$selectorsRaw = $this->serializer->unserialize($this->getConfigValue('selectors'));
try {
$selectorsRaw = $this->serializer->unserialize($this->getConfigValue('selectors'));
} catch (\InvalidArgumentException $e) {
return $selectors;
}

if (is_array($selectorsRaw)) {
foreach ($selectorsRaw as $selectorRaw) {
Expand Down
15 changes: 15 additions & 0 deletions src/Test/Unit/Helper/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ public function testGetSelectors()
$this->assertNotEmpty($selectors);
}

/**
* @return void
*/
public function testGetSelectorsException()
{
$this->serializer->method('unserialize')->willThrowException(
new \InvalidArgumentException()
);

$selectors = $this->configHelper->getSelectors();

$this->assertEmpty($selectors);
$this->assertInternalType( 'array', $selectors);
}

/**
* @return array
*/
Expand Down

0 comments on commit d3bda5d

Please sign in to comment.