Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
c9b14ee3
Unverified
Commit
c9b14ee3
authored
Jan 31, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-510: Extract generic error expectation construction
parent
0b923b08
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
35 deletions
+43
-35
ErrorExpectation.php
tests/SpecTests/ErrorExpectation.php
+43
-35
No files found.
tests/SpecTests/ErrorExpectation.php
View file @
c9b14ee3
...
...
@@ -113,41 +113,7 @@ final class ErrorExpectation
*/
public
static
function
fromTransactions
(
stdClass
$operation
)
{
$o
=
new
self
();
if
(
isset
(
$operation
->
error
))
{
$o
->
isExpected
=
$operation
->
error
;
}
$result
=
isset
(
$operation
->
result
)
?
$operation
->
result
:
null
;
if
(
isset
(
$result
->
errorContains
))
{
$o
->
messageContains
=
$result
->
errorContains
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorCodeName
))
{
$o
->
codeName
=
$result
->
errorCodeName
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorLabelsContain
))
{
if
(
!
self
::
isArrayOfStrings
(
$result
->
errorLabelsContain
))
{
throw
InvalidArgumentException
::
invalidType
(
'errorLabelsContain'
,
$result
->
errorLabelsContain
,
'string[]'
);
}
$o
->
includedLabels
=
$result
->
errorLabelsContain
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorLabelsOmit
))
{
if
(
!
self
::
isArrayOfStrings
(
$result
->
errorLabelsOmit
))
{
throw
InvalidArgumentException
::
invalidType
(
'errorLabelsOmit'
,
$result
->
errorLabelsOmit
,
'string[]'
);
}
$o
->
excludedLabels
=
$result
->
errorLabelsOmit
;
$o
->
isExpected
=
true
;
}
return
$o
;
return
self
::
fromGenericOperation
(
$operation
);
}
public
static
function
noError
()
...
...
@@ -232,6 +198,48 @@ final class ErrorExpectation
$test
->
assertSame
(
$this
->
codeName
,
$result
->
codeName
);
}
/**
* @throws InvalidArgumentException
*/
private
static
function
fromGenericOperation
(
stdClass
$operation
)
{
$o
=
new
self
();
if
(
isset
(
$operation
->
error
))
{
$o
->
isExpected
=
$operation
->
error
;
}
$result
=
isset
(
$operation
->
result
)
?
$operation
->
result
:
null
;
if
(
isset
(
$result
->
errorContains
))
{
$o
->
messageContains
=
$result
->
errorContains
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorCodeName
))
{
$o
->
codeName
=
$result
->
errorCodeName
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorLabelsContain
))
{
if
(
!
self
::
isArrayOfStrings
(
$result
->
errorLabelsContain
))
{
throw
InvalidArgumentException
::
invalidType
(
'errorLabelsContain'
,
$result
->
errorLabelsContain
,
'string[]'
);
}
$o
->
includedLabels
=
$result
->
errorLabelsContain
;
$o
->
isExpected
=
true
;
}
if
(
isset
(
$result
->
errorLabelsOmit
))
{
if
(
!
self
::
isArrayOfStrings
(
$result
->
errorLabelsOmit
))
{
throw
InvalidArgumentException
::
invalidType
(
'errorLabelsOmit'
,
$result
->
errorLabelsOmit
,
'string[]'
);
}
$o
->
excludedLabels
=
$result
->
errorLabelsOmit
;
$o
->
isExpected
=
true
;
}
return
$o
;
}
private
static
function
isArrayOfStrings
(
$array
)
{
if
(
!
is_array
(
$array
))
{
...
...
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