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
0b923b08
Unverified
Commit
0b923b08
authored
Jan 27, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-510: Improve handling of NULL and Int64 values in DocumentsMatchConstraint
parent
e0dd83cb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
DocumentsMatchConstraint.php
tests/SpecTests/DocumentsMatchConstraint.php
+13
-3
DocumentsMatchConstraintTest.php
tests/SpecTests/DocumentsMatchConstraintTest.php
+1
-1
No files found.
tests/SpecTests/DocumentsMatchConstraint.php
View file @
0b923b08
...
@@ -33,6 +33,7 @@ use stdClass;
...
@@ -33,6 +33,7 @@ use stdClass;
use
Symfony\Bridge\PhpUnit\ConstraintTrait
;
use
Symfony\Bridge\PhpUnit\ConstraintTrait
;
use
function
array_values
;
use
function
array_values
;
use
function
get_class
;
use
function
get_class
;
use
function
gettype
;
use
function
in_array
;
use
function
in_array
;
use
function
is_array
;
use
function
is_array
;
use
function
is_object
;
use
function
is_object
;
...
@@ -313,8 +314,11 @@ class DocumentsMatchConstraint extends Constraint
...
@@ -313,8 +314,11 @@ class DocumentsMatchConstraint extends Constraint
continue
;
continue
;
}
}
$expectedType
=
is_object
(
$expectedValue
)
?
get_class
(
$expectedValue
)
:
gettype
(
$expectedValue
);
$actualType
=
is_object
(
$expectedValue
)
?
get_class
(
$actualValue
)
:
gettype
(
$actualValue
);
// Workaround for ObjectComparator printing the whole actual object
// Workaround for ObjectComparator printing the whole actual object
if
(
get_class
(
$expectedValue
)
!==
get_class
(
$actualValue
)
)
{
if
(
$expectedType
!==
$actualType
)
{
throw
new
ComparisonFailure
(
throw
new
ComparisonFailure
(
$expectedValue
,
$expectedValue
,
$actualValue
,
$actualValue
,
...
@@ -322,10 +326,10 @@ class DocumentsMatchConstraint extends Constraint
...
@@ -322,10 +326,10 @@ class DocumentsMatchConstraint extends Constraint
''
,
''
,
false
,
false
,
sprintf
(
sprintf
(
'Field path "%s": %s is not instance of expected
class
"%s".'
,
'Field path "%s": %s is not instance of expected
type
"%s".'
,
$keyPrefix
.
$key
,
$keyPrefix
.
$key
,
$this
->
exporter
()
->
shortenedExport
(
$actualValue
),
$this
->
exporter
()
->
shortenedExport
(
$actualValue
),
get_class
(
$expectedValue
)
$expectedType
)
)
);
);
}
}
...
@@ -441,6 +445,12 @@ class DocumentsMatchConstraint extends Constraint
...
@@ -441,6 +445,12 @@ class DocumentsMatchConstraint extends Constraint
$bson
[
$key
]
=
$this
->
prepareBSON
(
$value
,
false
,
$sortKeys
);
$bson
[
$key
]
=
$this
->
prepareBSON
(
$value
,
false
,
$sortKeys
);
continue
;
continue
;
}
}
/* Convert Int64 objects to integers on 64-bit platforms for
* compatibility reasons. */
if
(
$value
instanceof
Int64
&&
PHP_INT_SIZE
!=
4
)
{
$bson
[
$key
]
=
(
int
)
((
string
)
$value
);
}
}
}
return
$bson
;
return
$bson
;
...
...
tests/SpecTests/DocumentsMatchConstraintTest.php
View file @
0b923b08
...
@@ -154,7 +154,7 @@ class DocumentsMatchConstraintTest extends TestCase
...
@@ -154,7 +154,7 @@ class DocumentsMatchConstraintTest extends TestCase
[
'foo'
=>
'42'
],
[
'foo'
=>
'42'
],
],
],
'Type mismatch'
=>
[
'Type mismatch'
=>
[
'Field path "foo": MongoDB\Model\BSONDocument Object (...) is not instance of expected
class
"MongoDB\Model\BSONArray".'
,
'Field path "foo": MongoDB\Model\BSONDocument Object (...) is not instance of expected
type
"MongoDB\Model\BSONArray".'
,
new
DocumentsMatchConstraint
([
'foo'
=>
[
'bar'
]]),
new
DocumentsMatchConstraint
([
'foo'
=>
[
'bar'
]]),
[
'foo'
=>
(
object
)
[
'bar'
]],
[
'foo'
=>
(
object
)
[
'bar'
]],
],
],
...
...
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