Files
iTop/test/itop-config/Validator/iTopConfigSyntaxValidatorTest.php
bruno DA SILVA 27a0de1da1 N°2154 - fix server crash in rare cases
Under undetermined circumstances, `exec('php -v')` called the current script triggering an infinite loop crashing the server
problem reported by @molkobain
see: https://stackoverflow.com/questions/43728378/running-php-files-through-shell-exec
2020-02-19 15:43:33 +01:00

52 lines
1.3 KiB
PHP

<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 31/12/2019
* Time: 12:31
*/
namespace Combodo\iTop\Config\Test\Validator;
use Combodo\iTop\Config\Validator\iTopConfigAstValidator;
use Combodo\iTop\Config\Validator\iTopConfigSyntaxValidator;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use PhpParser\Node;
use PhpParser\PrettyPrinter\Standard;
class iTopConfigAstValidatorTest extends ItopTestCase
{
public function setUp()
{
parent::setUp();
require_once __DIR__.'/../../../env-production/itop-config/src/Validator/ConfigNodesVisitor.php';
require_once __DIR__.'/../../../env-production/itop-config/src/Validator/iTopConfigSyntaxValidator.php';
}
/**
* @throws \Exception
* @doesNotPerformAssertions
*/
public function testValidCode()
{
$oiTopConfigValidator = new iTopConfigSyntaxValidator();
$oiTopConfigValidator->Validate("<?php \n echo 'foo'; ");
}
public function testThrowOnInvalidCode()
{
$oiTopConfigValidator = new iTopConfigSyntaxValidator();
$this->expectException(\Exception::class);
try{
$oiTopConfigValidator->Validate("<?php \n zef;zefzef \n zdadz = azdazd \n zerfgzaezerfgzef>");
}catch (\Exception $e)
{
$this->assertStringStartsWith('Error in configuration: syntax error, unexpected \'zdadz\' (T_STRING)', $e->getMessage());
throw $e;
}
}
}