Skip to content

Commit

Permalink
BBCodes\Configurator\Repository: improved error message on bad reposi…
Browse files Browse the repository at this point in the history
…tory file
  • Loading branch information
JoshyPHP committed Apr 14, 2018
1 parent 4096d35 commit cbeb3c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
17 changes: 3 additions & 14 deletions src/Plugins/BBCodes/Configurator/Repository.php
Expand Up @@ -35,28 +35,17 @@ public function __construct($value, BBCodeMonkey $bbcodeMonkey)
{
if (!($value instanceof DOMDocument))
{
if (!file_exists($value))
{
throw new InvalidArgumentException('Not a DOMDocument or the path to a repository file');
}

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;

$useErrors = libxml_use_internal_errors(true);
$success = $dom->load($value);
libxml_use_internal_errors($useErrors);

if (!$success)
if (!@$dom->load($value))
{
throw new InvalidArgumentException('Invalid repository file');
throw new InvalidArgumentException(var_export($value, true) . ' is not a valid BBCode repository file');
}

$value = $dom;
}

$this->bbcodeMonkey = $bbcodeMonkey;
$this->dom = $value;
$this->dom = $value;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Plugins/BBCodes/Configurator/RepositoryTest.php
Expand Up @@ -36,7 +36,7 @@ public function testConstructorDOMDocument()
/**
* @testdox __construct() throws an exception if passed anything else
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Not a DOMDocument or the path to a repository file
* @expectedExceptionMessage NULL is not a valid BBCode repository file
*/
public function testConstructorInvalidPath()
{
Expand All @@ -46,7 +46,7 @@ public function testConstructorInvalidPath()
/**
* @testdox __construct() throws an exception if passed the path to a file that is not valid XML
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid repository file
* @expectedExceptionMessage is not a valid BBCode repository file
*/
public function testConstructorInvalidFile()
{
Expand Down

0 comments on commit cbeb3c8

Please sign in to comment.