Skip to content

Commit

Permalink
Fix type error tests to work in PHP5 & PHP7.1
Browse files Browse the repository at this point in the history
Catch the TypeErrors that are raised and make the match the PHP5
behavior of a converted error.
  • Loading branch information
markstory committed Dec 7, 2016
1 parent e3221b1 commit 0a2a400
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Expand Up @@ -47,14 +47,15 @@ public function setUp() {
/**
* 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__);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Core/ConfigureTest.php
Expand Up @@ -449,16 +449,16 @@ public function testReaderSetup() {
/**
* test reader() throwing exceptions on missing interface.
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testReaderExceptionOnIncorrectClass() {
$reader = new StdClass();

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

Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -2908,14 +2908,15 @@ public function testSchema() {
/**
* 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__);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -2223,14 +2223,15 @@ public function testValidatorOverride() {
/**
* 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__);
}
}

Expand Down

0 comments on commit 0a2a400

Please sign in to comment.