Skip to content

Commit

Permalink
Xml File Check
Browse files Browse the repository at this point in the history
  • Loading branch information
svilborg committed Jul 17, 2019
1 parent 1ac497f commit 94cfd79
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Checks/File/Xml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace Health\Checks\File;

use Health\Checks\HealthCheckInterface;

class Xml extends Base implements HealthCheckInterface
{

/**
*
* @param string $file
* @return boolean
*/
protected function isValid($file)
{
$doc = new \DOMDocument();

if (! @$doc->load($file)) {
return false;
}

return true;
}
}
31 changes: 31 additions & 0 deletions tests/Checks/FileXmlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace Tests\Checks;

use Health\Checks\File\Xml;

class FileXmlTest extends CheckTestCase
{

public function testCheckFile()
{
$this->assertCheck($this->runCheck(Xml::class, []), 'UP');

$this->assertCheck($this->runCheck(Xml::class, [
'files' => [
'./tests/files/valid.xml'
]
]), 'UP');

$this->assertCheck($this->runCheck(Xml::class, [
'files' => [
'./tests/files/invalid.json.txt'
]
]), 'DOWN');

$this->assertCheck($this->runCheck(Xml::class, [
'files' => [
'./tests/files/notfound.xml'
]
]), 'DOWN');
}
}
3 changes: 3 additions & 0 deletions tests/files/valid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Comment -->
<body>test</body>

0 comments on commit 94cfd79

Please sign in to comment.