Use try catch instead of expectException from framework

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2019-10-19 11:50:03 +02:00
parent 2709edfc8c
commit eb33bbb76f
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
4 changed files with 42 additions and 22 deletions

View File

@ -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]);
}
/**

View File

@ -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);
}
}
/**

View File

@ -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);
}
}
}

View File

@ -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);
}
}
/**