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
9d9965b6
Commit
9d9965b6
authored
Jan 07, 2016
by
Will Banfield
Committed by
Jeremy Mikola
Mar 14, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added corrupt chunk tests
parent
ebf903d6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
GridFsUpload.php
src/GridFS/GridFsUpload.php
+1
-1
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+31
-0
No files found.
src/GridFS/GridFsUpload.php
View file @
9d9965b6
...
@@ -107,7 +107,7 @@ class GridFsUpload
...
@@ -107,7 +107,7 @@ class GridFsUpload
throw
new
UnexpectedTypeException
(
'stream'
,
$source
);
throw
new
UnexpectedTypeException
(
'stream'
,
$source
);
}
else
{
}
else
{
$streamMetadata
=
stream_get_meta_data
(
$source
);
$streamMetadata
=
stream_get_meta_data
(
$source
);
}
while
(
$data
=
$this
->
readChunk
(
$source
))
{
while
(
$data
=
$this
->
readChunk
(
$source
))
{
$this
->
insertChunk
(
$data
);
$this
->
insertChunk
(
$data
);
}
}
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
9d9965b6
...
@@ -93,6 +93,37 @@ class BucketFunctionalTest extends FunctionalTestCase
...
@@ -93,6 +93,37 @@ class BucketFunctionalTest extends FunctionalTestCase
$this
->
assertEquals
(
255
*
1024
,
$raw
->
chunkSize
);
$this
->
assertEquals
(
255
*
1024
,
$raw
->
chunkSize
);
$this
->
assertTrue
(
is_string
(
$raw
->
md5
));
$this
->
assertTrue
(
is_string
(
$raw
->
md5
));
}
}
public
function
testCorruptChunk
()
{
$id
=
$this
->
bucket
->
uploadFromStream
(
"test_filename"
,
$this
->
generateStream
(
"foobar"
));
$this
->
collectionsWrapper
->
getChunksCollection
()
->
updateOne
([
'files_id'
=>
$id
],
[
'$set'
=>
[
'data'
=>
new
\MongoDB\BSON\Binary
(
'foo'
,
\MongoDB\BSON\Binary
::
TYPE_GENERIC
)]]);
$error
=
null
;
try
{
$download
=
$this
->
bucket
->
openDownloadStream
(
$id
);
stream_get_contents
(
$download
);
}
catch
(
\MongoDB\Exception\Exception
$e
)
{
$error
=
$e
;
}
$corruptFileError
=
'\MongoDB\Exception\GridFSCOrruptFileException'
;
$this
->
assertTrue
(
$error
instanceof
$corruptFileError
);
}
public
function
testErrorsOnMissingChunk
()
{
$id
=
$this
->
bucket
->
uploadFromStream
(
"test_filename"
,
$this
->
generateStream
(
"hello world,abcdefghijklmnopqrstuv123456789"
),
[
"chunkSizeBytes"
=>
1
]);
$this
->
collectionsWrapper
->
getChunksCollection
()
->
deleteOne
([
'files_id'
=>
$id
,
'n'
=>
7
]);
$error
=
null
;
try
{
$download
=
$this
->
bucket
->
openDownloadStream
(
$id
);
stream_get_contents
(
$download
);
}
catch
(
\MongoDB\Exception\Exception
$e
)
{
$error
=
$e
;
}
$corruptFileError
=
'\MongoDB\Exception\GridFSCOrruptFileException'
;
$this
->
assertTrue
(
$error
instanceof
$corruptFileError
);
}
public
function
testUploadEnsureIndexes
()
public
function
testUploadEnsureIndexes
()
{
{
$chunks
=
$this
->
bucket
->
getCollectionsWrapper
()
->
getChunksCollection
();
$chunks
=
$this
->
bucket
->
getCollectionsWrapper
()
->
getChunksCollection
();
...
...
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