Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
219
Merge Requests
219
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
3634822c
Commit
3634822c
authored
Jul 20, 2015
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2533946
by alexpott: UncaughtExceptionTest is a monkey in the control room
parent
9fab1ad5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
33 deletions
+20
-33
core/modules/system/src/Tests/System/UncaughtExceptionTest.php
...modules/system/src/Tests/System/UncaughtExceptionTest.php
+20
-33
No files found.
core/modules/system/src/Tests/System/UncaughtExceptionTest.php
View file @
3634822c
...
...
@@ -87,7 +87,6 @@ public function testUncaughtException() {
$this
->
assertResponse
(
500
);
$this
->
assertText
(
'The website encountered an unexpected error. Please try again later.'
);
$this
->
assertText
(
$this
->
expectedExceptionMessage
);
$this
->
assertExceptionFailure
(
$this
->
expectedExceptionMessage
,
'Ensure that monekys are found in the control room.'
);
}
/**
...
...
@@ -99,7 +98,6 @@ public function testMissingDependency() {
$this
->
assertRaw
(
'The website encountered an unexpected error.'
);
$this
->
assertRaw
(
$this
->
expectedExceptionMessage
);
$this
->
assertExceptionFailure
(
$this
->
expectedExceptionMessage
,
'Ensure that the exception of a missing constructor argument was triggered.'
);
}
/**
...
...
@@ -125,7 +123,6 @@ public function testErrorContainer() {
$this
->
drupalGet
(
''
);
$this
->
assertRaw
(
$this
->
expectedExceptionMessage
);
$this
->
assertExceptionFailure
(
$this
->
expectedExceptionMessage
,
'Ensure that the error of the container was triggered.'
);
}
/**
...
...
@@ -153,49 +150,39 @@ public function testExceptionContainer() {
$this
->
assertRaw
(
'The website encountered an unexpected error'
);
$this
->
assertRaw
(
$this
->
expectedExceptionMessage
);
$this
->
assertExceptionFailure
(
$this
->
expectedExceptionMessage
,
'Ensure that the exception of the container was triggered.'
);
}
/**
* Tests the case when the database connection is gone.
*/
public
function
testLostDatabaseConnection
()
{
$incorrect_username
=
$this
->
randomMachineName
(
16
);
switch
(
$this
->
container
->
get
(
'database'
)
->
driver
())
{
case
'pgsql'
:
case
'mysql'
:
$this
->
expectedExceptionMessage
=
$incorrect_username
;
break
;
default
:
// We can not carry out this test.
$this
->
pass
(
'Unable to run \Drupal\system\Tests\System\UncaughtExceptionTest::testLostDatabaseConnection for this database type.'
);
return
;
}
// We simulate a broken database connection by rewrite settings.php to no
// longer have the proper data.
$settings
[
'databases'
][
'default'
][
'default'
][
'password'
]
=
(
object
)
array
(
'value'
=>
$this
->
randomMachineName
(),
$settings
[
'databases'
][
'default'
][
'default'
][
'username'
]
=
(
object
)
array
(
'value'
=>
$incorrect_username
,
'required'
=>
TRUE
,
);
$settings
[
'databases'
][
'default'
][
'default'
][
'passowrd'
]
=
(
object
)
array
(
'value'
=>
$this
->
randomMachineName
(
16
),
'required'
=>
TRUE
,
);
$this
->
writeSettings
(
$settings
);
$this
->
expectedExceptionMessage
=
'[1045] Access denied for user'
;
$this
->
drupalGet
(
''
);
$this
->
assertRaw
(
$this
->
expectedExceptionMessage
);
$this
->
assertExceptionFailure
(
$this
->
expectedExceptionMessage
,
'Ensure that the access denied DB connection exception is thrown.'
);
}
/**
* Asserts that an exception is present in the assertions and removes it.
*
* This ensures that expected failures are passes rather than failures.
*
* @param string $exception_message
* The exception message to search for.
*
* @return bool
* TRUE if the exception message was found.
*/
protected
function
assertExceptionFailure
(
$exception_message
,
$message
)
{
$found_exception
=
FALSE
;
foreach
(
$this
->
assertions
as
&
$assertion
)
{
if
(
strpos
(
$assertion
[
'message'
],
$exception_message
)
!==
FALSE
)
{
$found_exception
=
TRUE
;
$this
->
deleteAssert
(
$assertion
[
'message_id'
]);
unset
(
$assertion
);
}
}
return
$this
->
assertTrue
(
$found_exception
,
$message
);
$this
->
assertRaw
(
'PDOException'
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment