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
dd7058c9
Commit
dd7058c9
authored
Jul 27, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #219
parents
7a6bb13d
a36b0799
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
StreamWrapper.php
src/GridFS/StreamWrapper.php
+27
-7
WritableStream.php
src/GridFS/WritableStream.php
+0
-5
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+3
-3
SpecFunctionalTest.php
tests/GridFS/SpecFunctionalTest.php
+6
-3
No files found.
src/GridFS/StreamWrapper.php
View file @
dd7058c9
...
...
@@ -2,6 +2,8 @@
namespace
MongoDB\GridFS
;
use
Exception
;
/**
* Stream wrapper for reading and writing a GridFS file.
*
...
...
@@ -57,6 +59,10 @@ class StreamWrapper
*/
public
function
stream_eof
()
{
if
(
!
$this
->
stream
instanceof
ReadableStream
)
{
return
false
;
}
return
$this
->
stream
->
isEOF
();
}
...
...
@@ -93,12 +99,20 @@ class StreamWrapper
*
* @see http://php.net/manual/en/streamwrapper.stream-read.php
* @param integer $count Number of bytes to read
* @return string
* @return string
*/
public
function
stream_read
(
$count
)
{
// TODO: Ensure that $this->stream is a ReadableStream
return
$this
->
stream
->
downloadNumBytes
(
$count
);
if
(
!
$this
->
stream
instanceof
ReadableStream
)
{
return
''
;
}
try
{
return
$this
->
stream
->
downloadNumBytes
(
$count
);
}
catch
(
Exception
$e
)
{
trigger_error
(
sprintf
(
'%s: %s'
,
get_class
(
$e
),
$e
->
getMessage
()),
\E_USER_WARNING
);
return
false
;
}
}
/**
...
...
@@ -122,14 +136,20 @@ class StreamWrapper
*
* @see http://php.net/manual/en/streamwrapper.stream-write.php
* @param string $data Data to write
* @return integer The number of bytes
successfully stored
* @return integer The number of bytes
written
*/
public
function
stream_write
(
$data
)
{
// TODO: Ensure that $this->stream is a WritableStream
$this
->
stream
->
insertChunks
(
$data
);
if
(
!
$this
->
stream
instanceof
WritableStream
)
{
return
0
;
}
return
strlen
(
$data
);
try
{
return
$this
->
stream
->
insertChunks
(
$data
);
}
catch
(
Exception
$e
)
{
trigger_error
(
sprintf
(
'%s: %s'
,
get_class
(
$e
),
$e
->
getMessage
()),
\E_USER_WARNING
);
return
false
;
}
}
/**
...
...
src/GridFS/WritableStream.php
View file @
dd7058c9
...
...
@@ -184,11 +184,6 @@ class WritableStream
return
$readBytes
;
}
public
function
isEOF
()
{
return
$this
->
isClosed
;
}
private
function
abort
()
{
$this
->
collectionWrapper
->
deleteChunksByFilesId
(
$this
->
file
[
'_id'
]);
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
dd7058c9
...
...
@@ -125,7 +125,7 @@ class BucketFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException
MongoDB\GridFS\Exception\CorruptFileException
* @expectedException
PHPUnit_Framework_Error_Warning
*/
public
function
testDownloadingFileWithMissingChunk
()
{
...
...
@@ -137,7 +137,7 @@ class BucketFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException
MongoDB\GridFS\Exception\CorruptFileException
* @expectedException
PHPUnit_Framework_Error_Warning
*/
public
function
testDownloadingFileWithUnexpectedChunkIndex
()
{
...
...
@@ -152,7 +152,7 @@ class BucketFunctionalTest extends FunctionalTestCase
}
/**
* @expectedException
MongoDB\GridFS\Exception\CorruptFileException
* @expectedException
PHPUnit_Framework_Error_Warning
*/
public
function
testDownloadingFileWithUnexpectedChunkSize
()
{
...
...
tests/GridFS/SpecFunctionalTest.php
View file @
dd7058c9
...
...
@@ -6,9 +6,9 @@ use MongoDB\Collection;
use
MongoDB\BSON\Binary
;
use
MongoDB\BSON\ObjectId
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\Exception\RuntimeException
;
use
MongoDB\Operation\BulkWrite
;
use
DateTime
;
use
Exception
;
use
IteratorIterator
;
use
LogicException
;
use
MultipleIterator
;
...
...
@@ -50,7 +50,7 @@ class SpecFunctionalTest extends FunctionalTestCase
try
{
$result
=
$this
->
executeAct
(
$test
[
'act'
]);
}
catch
(
Runtime
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
$result
=
$e
;
}
...
...
@@ -333,7 +333,10 @@ class SpecFunctionalTest extends FunctionalTestCase
case
'ChunkIsMissing'
:
case
'ChunkIsWrongSize'
:
return
'MongoDB\GridFS\Exception\CorruptFileException'
;
/* Although ReadableStream throws a CorruptFileException, the
* stream wrapper will convert it to a PHP error of type
* E_USER_WARNING. */
return
'PHPUnit_Framework_Error_Warning'
;
default
:
throw
new
LogicException
(
'Unsupported error: '
.
$error
);
...
...
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