Use try catch instead of expectException from framework
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
parent
2709edfc8c
commit
eb33bbb76f
@ -12,7 +12,6 @@ use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Tests\PmaTestCase;
|
||||
use PhpMyAdmin\Theme;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\Exception;
|
||||
|
||||
/**
|
||||
* Tests behaviour of PhpMyAdmin\Config class
|
||||
@ -1338,18 +1337,25 @@ class ConfigTest extends PmaTestCase
|
||||
*/
|
||||
public function testCheckServers($settings, $expected, $error = false)
|
||||
{
|
||||
if ($error) {
|
||||
$this->expectException(Exception::class);
|
||||
try {
|
||||
$this->object->settings['Servers'] = $settings;
|
||||
$this->object->checkServers();
|
||||
if (is_null($expected)) {
|
||||
$expected = $this->object->default_server;
|
||||
} else {
|
||||
$expected = array_merge($this->object->default_server, $expected);
|
||||
}
|
||||
$this->assertEquals($expected, $this->object->settings['Servers'][1]);
|
||||
if ($error) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($error) {
|
||||
$this->assertTrue(true);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$this->object->settings['Servers'] = $settings;
|
||||
$this->object->checkServers();
|
||||
if (is_null($expected)) {
|
||||
$expected = $this->object->default_server;
|
||||
} else {
|
||||
$expected = array_merge($this->object->default_server, $expected);
|
||||
}
|
||||
$this->assertEquals($expected, $this->object->settings['Servers'][1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -65,8 +65,12 @@ class ContainerTest extends PmaTestCase
|
||||
*/
|
||||
public function testGetThrowsNotFoundException()
|
||||
{
|
||||
$this->expectException(NotFoundExceptionInterface::class);
|
||||
$this->container->get('name');
|
||||
try {
|
||||
$this->container->get('name');
|
||||
$this->assertTrue(false);
|
||||
} catch (NotFoundExceptionInterface $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -10,8 +10,6 @@ namespace PhpMyAdmin\Tests\Navigation;
|
||||
use PhpMyAdmin\Navigation\NodeFactory;
|
||||
use PhpMyAdmin\Navigation\Nodes\Node;
|
||||
use PhpMyAdmin\Tests\PmaTestCase;
|
||||
use PhpMyAdmin\Theme;
|
||||
use PHPUnit\Framework\Exception;
|
||||
|
||||
/**
|
||||
* Tests for NodeFactory class
|
||||
@ -85,8 +83,12 @@ class NodeFactoryTest extends PmaTestCase
|
||||
*/
|
||||
public function testFileError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
NodeFactory::getInstance('NodeDoesNotExist');
|
||||
try {
|
||||
NodeFactory::getInstance('NodeDoesNotExist');
|
||||
$this->assertTrue(false);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,7 +98,11 @@ class NodeFactoryTest extends PmaTestCase
|
||||
*/
|
||||
public function testClassNameError()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
NodeFactory::getInstance('Invalid');
|
||||
try {
|
||||
NodeFactory::getInstance('Invalid');
|
||||
$this->assertTrue(false);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,8 +90,12 @@ class TemplateTest extends PmaTestCase
|
||||
*/
|
||||
public function testRenderTemplateNotFound()
|
||||
{
|
||||
$this->expectException(LoaderError::class);
|
||||
Template::get('template not found')->render();
|
||||
try {
|
||||
Template::get('template not found')->render();
|
||||
$this->assertTrue(false);
|
||||
} catch (LoaderError $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user