diff --git a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php index 86aa53e..f0c28e4 100644 --- a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php +++ b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php @@ -202,8 +202,16 @@ public function testSetConfigurationBcLevel() { * @covers ::resolveBcConfiguration */ public function testDeprecationErrorTriggering() { - $config = ['handler_settings' => ['settings1' => TRUE]]; + // Configuration with no BC level. + $config = ['setting1' => TRUE]; new TestSelection($config, 'test_selector', []); + // Check that deprecation errors has not been triggered. + $this->assertNoError("Settings under 'handler_settings' are deprecated since version 8.3.x and will be removed before 9.0.0. Move the settings in the root of the configuration array.", E_USER_DEPRECATED); + + // Configuration with BC level. + $config = ['handler_settings' => ['setting1' => TRUE]]; + new TestSelection($config, 'test_selector', []); + // Check that deprecation errors has been triggered. $this->assertError("Settings under 'handler_settings' are deprecated since version 8.3.x and will be removed before 9.0.0. Move the settings in the root of the configuration array.", E_USER_DEPRECATED); } @@ -212,13 +220,13 @@ public function testDeprecationErrorTriggering() { * * @param string $message * The error message. - * @param int $code - * The error code. + * @param int $level + * The error level. */ - protected function assertError($message, $code) { - $assertion_message = "Triggered error '$message' (code $code)."; + protected function assertError($message, $level) { + $assertion_message = "Triggered error '$message' (level $level)."; foreach ($this->errors as $error) { - if ($error['message'] === $message && $error['code'] == $code) { + if ($error['message'] === $message && $error['level'] == $level) { $this->assertTrue(TRUE, $assertion_message); return; } @@ -227,16 +235,35 @@ protected function assertError($message, $code) { } /** + * Asserts a specific error has not been triggered. + * + * @param string $message + * The error message. + * @param int $level + * The error level. + */ + protected function assertNoError($message, $level) { + $assertion_message = "Not triggered error '$message' (level $level) ."; + foreach ($this->errors as $error) { + if ($error['message'] === $message && $error['level'] == $level) { + $this->fail($assertion_message); + return; + } + } + $this->assertTrue(TRUE, $assertion_message); + } + + /** * Provides a testing error handler. * - * @param int $code + * @param int $level * @param string $message * @param string $file * @param int $line * @param array $context */ - public function errorHandler($code, $message, $file, $line, $context) { - $this->errors[] = compact('code', 'message', 'file', 'line', 'context'); + public function errorHandler($level, $message, $file, $line, $context) { + $this->errors[] = compact('level', 'message', 'file', 'line', 'context'); } }