From 0a2a400ea42d73d4f9d111e5485646dfc91630b4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 6 Dec 2016 21:20:32 -0500 Subject: [PATCH] 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. --- .../Controller/Component/Auth/ControllerAuthorizeTest.php | 5 +++-- lib/Cake/Test/Case/Core/ConfigureTest.php | 6 +++--- lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php | 5 +++-- lib/Cake/Test/Case/Model/ModelValidationTest.php | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/Cake/Test/Case/Controller/Component/Auth/ControllerAuthorizeTest.php b/lib/Cake/Test/Case/Controller/Component/Auth/ControllerAuthorizeTest.php index ce92d6b14..3ed011262 100644 --- a/lib/Cake/Test/Case/Controller/Component/Auth/ControllerAuthorizeTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Auth/ControllerAuthorizeTest.php @@ -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__); } } diff --git a/lib/Cake/Test/Case/Core/ConfigureTest.php b/lib/Cake/Test/Case/Core/ConfigureTest.php index d8d3e33b2..8a738fd30 100644 --- a/lib/Cake/Test/Case/Core/ConfigureTest.php +++ b/lib/Cake/Test/Case/Core/ConfigureTest.php @@ -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__); } } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 6dc888223..e4c28cae0 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -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__); } } diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index 7f2a73e43..f00c1a250 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -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__); } }