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
554e73f7
Commit
554e73f7
authored
Oct 25, 2018
by
Derick Rethans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-352: Only send bypassDocumentValidation if it's true
parent
f24bfcd7
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
366 additions
and
8 deletions
+366
-8
Aggregate.php
src/Operation/Aggregate.php
+4
-1
BulkWrite.php
src/Operation/BulkWrite.php
+4
-1
FindAndModify.php
src/Operation/FindAndModify.php
+4
-1
InsertMany.php
src/Operation/InsertMany.php
+4
-1
InsertOne.php
src/Operation/InsertOne.php
+4
-1
MapReduce.php
src/Operation/MapReduce.php
+4
-1
Update.php
src/Operation/Update.php
+8
-2
AggregateFunctionalTest.php
tests/Operation/AggregateFunctionalTest.php
+39
-0
BulkWriteFunctionalTest.php
tests/Operation/BulkWriteFunctionalTest.php
+39
-0
ExplainFunctionalTest.php
tests/Operation/ExplainFunctionalTest.php
+53
-0
FindAndModifyFunctionalTest.php
tests/Operation/FindAndModifyFunctionalTest.php
+37
-0
InsertManyFunctionalTest.php
tests/Operation/InsertManyFunctionalTest.php
+39
-0
InsertOneFunctionalTest.php
tests/Operation/InsertOneFunctionalTest.php
+39
-0
MapReduceFunctionalTest.php
tests/Operation/MapReduceFunctionalTest.php
+47
-0
UpdateFunctionalTest.php
tests/Operation/UpdateFunctionalTest.php
+41
-0
No files found.
src/Operation/Aggregate.php
View file @
554e73f7
...
...
@@ -299,7 +299,10 @@ class Aggregate implements Executable
$cmd
[
'allowDiskUse'
]
=
$this
->
options
[
'allowDiskUse'
];
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/BulkWrite.php
View file @
554e73f7
...
...
@@ -324,7 +324,10 @@ class BulkWrite implements Executable
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$options
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/FindAndModify.php
View file @
554e73f7
...
...
@@ -264,7 +264,10 @@ class FindAndModify implements Executable, Explainable
$cmd
[
'maxTimeMS'
]
=
$this
->
options
[
'maxTimeMS'
];
}
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/InsertMany.php
View file @
554e73f7
...
...
@@ -128,7 +128,10 @@ class InsertMany implements Executable
{
$options
=
[
'ordered'
=>
$this
->
options
[
'ordered'
]];
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$options
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/InsertOne.php
View file @
554e73f7
...
...
@@ -104,7 +104,10 @@ class InsertOne implements Executable
{
$options
=
[];
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$options
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/MapReduce.php
View file @
554e73f7
...
...
@@ -291,7 +291,10 @@ class MapReduce implements Executable
}
}
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
src/Operation/Update.php
View file @
554e73f7
...
...
@@ -169,7 +169,10 @@ class Update implements Executable, Explainable
$bulkOptions
=
[];
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$bulkOptions
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
@@ -189,7 +192,10 @@ class Update implements Executable, Explainable
$cmd
[
'writeConcern'
]
=
$this
->
options
[
'writeConcern'
];
}
if
(
isset
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
))
{
if
(
!
empty
(
$this
->
options
[
'bypassDocumentValidation'
])
&&
\MongoDB\server_supports_feature
(
$server
,
self
::
$wireVersionForDocumentLevelValidation
)
)
{
$cmd
[
'bypassDocumentValidation'
]
=
$this
->
options
[
'bypassDocumentValidation'
];
}
...
...
tests/Operation/AggregateFunctionalTest.php
View file @
554e73f7
...
...
@@ -193,6 +193,45 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
assertCollectionCount
(
$this
->
getCollectionName
()
.
'.output'
,
0
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$match'
=>
[
'x'
=>
1
]]],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$match'
=>
[
'x'
=>
1
]]],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
public
function
provideTypeMapOptionsAndExpectedDocuments
()
{
return
[
...
...
tests/Operation/BulkWriteFunctionalTest.php
View file @
554e73f7
...
...
@@ -305,6 +305,45 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'insertOne'
=>
[[
'_id'
=>
1
]]]],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
BulkWrite
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'insertOne'
=>
[[
'_id'
=>
1
]]]],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
/**
* Create data fixtures.
*
...
...
tests/Operation/ExplainFunctionalTest.php
View file @
554e73f7
...
...
@@ -292,6 +292,59 @@ class ExplainFunctionalTest extends FunctionalTestCase
$this
->
assertExplainResult
(
$result
,
$executionStatsExpected
,
$allPlansExecutionExpected
);
}
public
function
testUpdateBypassDocumentValidationSetWhenTrue
()
{
$this
->
createFixtures
(
3
);
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
[
'$gt'
=>
1
]],
[
'$inc'
=>
[
'x'
=>
1
]],
[
'bypassDocumentValidation'
=>
true
]
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
()
->
explain
);
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
explain
->
bypassDocumentValidation
);
}
);
}
public
function
testUpdateBypassDocumentValidationUnsetWhenFalse
()
{
$this
->
createFixtures
(
3
);
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
[
'$gt'
=>
1
]],
[
'$inc'
=>
[
'x'
=>
1
]],
[
'bypassDocumentValidation'
=>
false
]
);
$explainOperation
=
new
Explain
(
$this
->
getDatabaseName
(),
$operation
);
$result
=
$explainOperation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
()
->
explain
);
}
);
}
/**
* @dataProvider provideVerbosityInformation
*/
...
...
tests/Operation/FindAndModifyFunctionalTest.php
View file @
554e73f7
...
...
@@ -76,6 +76,43 @@ class FindAndModifyFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
,
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
FindAndModify
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'remove'
=>
true
,
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocument
*/
...
...
tests/Operation/InsertManyFunctionalTest.php
View file @
554e73f7
...
...
@@ -76,6 +76,45 @@ class InsertManyFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'_id'
=>
1
],
[
'_id'
=>
2
]],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
InsertMany
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'_id'
=>
1
],
[
'_id'
=>
2
]],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
public
function
testUnacknowledgedWriteConcern
()
{
$documents
=
[[
'x'
=>
11
]];
...
...
tests/Operation/InsertOneFunctionalTest.php
View file @
554e73f7
...
...
@@ -91,6 +91,45 @@ class InsertOneFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
1
],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
InsertOne
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
1
],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
public
function
testUnacknowledgedWriteConcern
()
{
$document
=
[
'x'
=>
11
];
...
...
tests/Operation/MapReduceFunctionalTest.php
View file @
554e73f7
...
...
@@ -156,6 +156,53 @@ class MapReduceFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
$this
->
createFixtures
(
1
);
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
MapReduce
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
new
Javascript
(
'function() { emit(this.x, this.y); }'
),
new
Javascript
(
'function(key, values) { return Array.sum(values); }'
),
[
'inline'
=>
1
],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
$this
->
createFixtures
(
1
);
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
MapReduce
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
new
Javascript
(
'function() { emit(this.x, this.y); }'
),
new
Javascript
(
'function(key, values) { return Array.sum(values); }'
),
[
'inline'
=>
1
],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
...
...
tests/Operation/UpdateFunctionalTest.php
View file @
554e73f7
...
...
@@ -46,6 +46,47 @@ class UpdateFunctionalTest extends FunctionalTestCase
);
}
public
function
testBypassDocumentValidationSetWhenTrue
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
1
],
[
'$inc'
=>
[
'x'
=>
1
]],
[
'bypassDocumentValidation'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
$this
->
assertEquals
(
true
,
$event
[
'started'
]
->
getCommand
()
->
bypassDocumentValidation
);
}
);
}
public
function
testBypassDocumentValidationUnsetWhenFalse
()
{
(
new
CommandObserver
)
->
observe
(
function
()
{
$operation
=
new
Update
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[
'_id'
=>
1
],
[
'$inc'
=>
[
'x'
=>
1
]],
[
'bypassDocumentValidation'
=>
false
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'bypassDocumentValidation'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
public
function
testUpdateOne
()
{
$this
->
createFixtures
(
3
);
...
...
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