Fix type error tests to work in PHP5 & PHP7.1

Catch the TypeErrors that are raised and make the match the PHP5
behavior of a converted error.
This commit is contained in:
mark_story 2016-12-06 21:20:32 -05:00
parent e3221b1c38
commit 0a2a400ea4
4 changed files with 12 additions and 9 deletions

View file

@ -47,14 +47,15 @@ class ControllerAuthorizeTest extends CakeTestCase {
/**
* testControllerTypeError
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testControllerTypeError() {
try {
$this->auth->controller(new StdClass());
$this->fail('No exception thrown');
} catch (Throwable $t) {
$this->assertTrue(true, 'Exception was raised');
} catch (TypeError $e) {
throw new PHPUnit_Framework_Error('Raised an error', 100, __FILE__, __LINE__);
}
}

View file

@ -449,6 +449,7 @@ class ConfigureTest extends CakeTestCase {
/**
* test reader() throwing exceptions on missing interface.
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testReaderExceptionOnIncorrectClass() {
@ -456,9 +457,8 @@ class ConfigureTest extends CakeTestCase {
try {
Configure::config('test', $reader);
$this->fail('No error raised');
} catch (Throwable $t) {
$this->assertTrue(true, 'TypeError raised');
} catch (TypeError $e) {
throw new PHPUnit_Framework_Error('Raised an error', 100, __FILE__, __LINE__);
}
}

View file

@ -2908,14 +2908,15 @@ SQL;
/**
* testDropSchemaNoSchema method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testDropSchemaNoSchema() {
try {
$this->Dbo->dropSchema(null);
$this->fail('No exception');
} catch (Throwable $t) {
$this->assertTrue(true, 'Exception raised');
} catch (TypeError $e) {
throw new PHPUnit_Framework_Error('Raised an error', 100, __FILE__, __LINE__);
}
}

View file

@ -2223,14 +2223,15 @@ class ModelValidationTest extends BaseModelTest {
/**
* Test that type hint exception is thrown
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testValidatorTypehintException() {
try {
new ModelValidator('asdasds');
$this->fail('No exeption raised');
} catch (Throwable $t) {
$this->assertTrue(true, 'An error/exception was raised');
} catch (TypeError $e) {
throw new PHPUnit_Framework_Error('Raised an error', 100, __FILE__, __LINE__);
}
}