test: Replace deprecated setExpectedException()

This commit is contained in:
Koji Tanaka 2023-01-07 13:10:05 +09:00 committed by Kamil Wylegala
parent b1417587ad
commit 75437a4a85
5 changed files with 26 additions and 32 deletions

View file

@ -171,9 +171,8 @@ class MemcachedEngineTest extends CakeTestCase {
'serialize' => 'invalid_serializer' 'serialize' => 'invalid_serializer'
); );
$this->setExpectedException( $this->expectException('CacheException');
'CacheException', 'invalid_serializer is not a valid serializer engine for Memcached' $this->expectExceptionMessage('invalid_serializer is not a valid serializer engine for Memcached');
);
$Memcached->init($settings); $Memcached->init($settings);
} }
@ -283,9 +282,8 @@ class MemcachedEngineTest extends CakeTestCase {
'serialize' => 'json' 'serialize' => 'json'
); );
$this->setExpectedException( $this->expectException('CacheException');
'CacheException', 'Memcached extension is not compiled with json support' $this->expectExceptionMessage('Memcached extension is not compiled with json support');
);
$Memcached->init($settings); $Memcached->init($settings);
} }
@ -308,9 +306,8 @@ class MemcachedEngineTest extends CakeTestCase {
'serialize' => 'msgpack' 'serialize' => 'msgpack'
); );
$this->setExpectedException( $this->expectException('CacheException');
'CacheException', 'msgpack is not a valid serializer engine for Memcached' $this->expectExceptionMessage('msgpack is not a valid serializer engine for Memcached');
);
$Memcached->init($settings); $Memcached->init($settings);
} }
@ -333,9 +330,8 @@ class MemcachedEngineTest extends CakeTestCase {
'serialize' => 'igbinary' 'serialize' => 'igbinary'
); );
$this->setExpectedException( $this->expectException('CacheException');
'CacheException', 'Memcached extension is not compiled with igbinary support' $this->expectExceptionMessage('Memcached extension is not compiled with igbinary support');
);
$Memcached->init($settings); $Memcached->init($settings);
} }
@ -356,7 +352,7 @@ class MemcachedEngineTest extends CakeTestCase {
'password' => 'password' 'password' => 'password'
); );
$this->setExpectedException('PHPUnit_Framework_Error_Warning'); $this->expectWarning();
$Memcached->init($settings); $Memcached->init($settings);
} }

View file

@ -283,19 +283,15 @@ class PhpAclTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testInvalidConfigWithAroMissing() { public function testInvalidConfigWithAroMissing() {
$this->setExpectedException( $this->expectException('AclException');
'AclException', $this->expectExceptionMessage('"roles" section not found in configuration');
'"roles" section not found in configuration'
);
$config = array('aco' => array('allow' => array('foo' => ''))); $config = array('aco' => array('allow' => array('foo' => '')));
$this->PhpAcl->build($config); $this->PhpAcl->build($config);
} }
public function testInvalidConfigWithAcosMissing() { public function testInvalidConfigWithAcosMissing() {
$this->setExpectedException( $this->expectException('AclException');
'AclException', $this->expectExceptionMessage('Neither "allow" nor "deny" rules were provided in configuration.');
'Neither "allow" nor "deny" rules were provided in configuration.'
);
$config = array( $config = array(
'roles' => array('Role/foo' => null), 'roles' => array('Role/foo' => null),

View file

@ -2482,7 +2482,7 @@ XML;
$this->assertEquals(array('Allow' => 'POST, DELETE'), $e->responseHeader()); $this->assertEquals(array('Allow' => 'POST, DELETE'), $e->responseHeader());
} }
$this->setExpectedException('MethodNotAllowedException'); $this->expectException('MethodNotAllowedException');
$request->allowMethod('POST'); $request->allowMethod('POST');
} }

View file

@ -212,7 +212,7 @@ class CakeEmailTest extends CakeTestCase {
$this->assertSame($expected, $this->CakeEmail->from()); $this->assertSame($expected, $this->CakeEmail->from());
$this->assertSame($this->CakeEmail, $result); $this->assertSame($this->CakeEmail, $result);
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address')); $this->CakeEmail->from(array('cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address'));
} }
@ -879,7 +879,7 @@ class CakeEmailTest extends CakeTestCase {
); );
$this->assertSame($expected, $this->CakeEmail->attachments()); $this->assertSame($expected, $this->CakeEmail->attachments());
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->attachments(array(array('nofile' => CAKE . 'basics.php', 'mimetype' => 'text/plain'))); $this->CakeEmail->attachments(array(array('nofile' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
} }
@ -896,7 +896,7 @@ class CakeEmailTest extends CakeTestCase {
$result = $this->CakeEmail->transportClass(); $result = $this->CakeEmail->transportClass();
$this->assertInstanceOf('DebugTransport', $result); $this->assertInstanceOf('DebugTransport', $result);
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->transport('Invalid'); $this->CakeEmail->transport('Invalid');
$this->CakeEmail->transportClass(); $this->CakeEmail->transportClass();
} }
@ -907,7 +907,7 @@ class CakeEmailTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testExtendTransport() { public function testExtendTransport() {
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->transport('Extend'); $this->CakeEmail->transport('Extend');
$this->CakeEmail->transportClass(); $this->CakeEmail->transportClass();
} }
@ -1068,7 +1068,7 @@ class CakeEmailTest extends CakeTestCase {
$this->CakeEmail->to('cake@cakephp.org'); $this->CakeEmail->to('cake@cakephp.org');
$this->CakeEmail->subject('My title'); $this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty')); $this->CakeEmail->config(array('empty'));
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->send("Forgot to set From"); $this->CakeEmail->send("Forgot to set From");
} }
@ -1082,7 +1082,7 @@ class CakeEmailTest extends CakeTestCase {
$this->CakeEmail->from('cake@cakephp.org'); $this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->subject('My title'); $this->CakeEmail->subject('My title');
$this->CakeEmail->config(array('empty')); $this->CakeEmail->config(array('empty'));
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->send("Forgot to set To"); $this->CakeEmail->send("Forgot to set To");
} }
@ -1724,7 +1724,7 @@ class CakeEmailTest extends CakeTestCase {
$this->assertStringContainsString('Here is your value: 12345', $result['message']); $this->assertStringContainsString('Here is your value: 12345', $result['message']);
$this->assertStringContainsString('This email was sent using the TestPlugin.', $result['message']); $this->assertStringContainsString('This email was sent using the TestPlugin.', $result['message']);
$this->setExpectedException('MissingViewException'); $this->expectException('MissingViewException');
$this->CakeEmail->template('test_plugin_tpl', 'plug_default')->send(); $this->CakeEmail->template('test_plugin_tpl', 'plug_default')->send();
} }
@ -2095,7 +2095,7 @@ class CakeEmailTest extends CakeTestCase {
$result = $this->CakeEmail->emailFormat(); $result = $this->CakeEmail->emailFormat();
$this->assertEquals('html', $result); $this->assertEquals('html', $result);
$this->setExpectedException('SocketException'); $this->expectException('SocketException');
$this->CakeEmail->emailFormat('invalid'); $this->CakeEmail->emailFormat('invalid');
} }

View file

@ -1842,9 +1842,11 @@ TEXT;
protected function _checkException($message) { protected function _checkException($message) {
if (version_compare(PHP_VERSION, '7.4', '>=')) { if (version_compare(PHP_VERSION, '7.4', '>=')) {
$this->setExpectedException('Error', $message); $this->expectException(Error::class);
$this->expectExceptionMessage($message);
} else { } else {
$this->setExpectedException('PHPUnit_Framework_Error', $message); $this->expectError();
$this->expectErrorMessage($message);
} }
} }
} }