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
748c14f4
Commit
748c14f4
authored
Sep 12, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more fields to Bucket debug handler and test selectGridFSBucket()
parent
90155d99
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
Bucket.php
src/GridFS/Bucket.php
+12
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+49
-0
No files found.
src/GridFS/Bucket.php
View file @
748c14f4
...
...
@@ -27,8 +27,12 @@ class Bucket
private
$collectionWrapper
;
private
$databaseName
;
private
$manager
;
private
$bucketName
;
private
$chunkSizeBytes
;
private
$readConcern
;
private
$readPreference
;
private
$writeConcern
;
/**
* Constructs a GridFS bucket.
...
...
@@ -79,9 +83,13 @@ class Bucket
throw
InvalidArgumentException
::
invalidType
(
'"writeConcern" option'
,
$options
[
'writeConcern'
],
'MongoDB\Driver\WriteConcern'
);
}
$this
->
manager
=
$manager
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
bucketName
=
$options
[
'bucketName'
];
$this
->
chunkSizeBytes
=
$options
[
'chunkSizeBytes'
];
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
writeConcern
=
isset
(
$options
[
'writeConcern'
])
?
$options
[
'writeConcern'
]
:
$this
->
manager
->
getWriteConcern
();
$collectionOptions
=
array_intersect_key
(
$options
,
[
'readConcern'
=>
1
,
'readPreference'
=>
1
,
'writeConcern'
=>
1
]);
...
...
@@ -100,7 +108,11 @@ class Bucket
return
[
'bucketName'
=>
$this
->
bucketName
,
'databaseName'
=>
$this
->
databaseName
,
'manager'
=>
$this
->
manager
,
'chunkSizeBytes'
=>
$this
->
chunkSizeBytes
,
'readConcern'
=>
$this
->
readConcern
,
'readPreference'
=>
$this
->
readPreference
,
'writeConcern'
=>
$this
->
writeConcern
,
];
}
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
748c14f4
...
...
@@ -190,6 +190,55 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectGridFSBucketInheritsOptions
()
{
$databaseOptions
=
[
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$databaseOptions
);
$bucket
=
$database
->
selectGridFSBucket
();
$debug
=
$bucket
->
__debugInfo
();
$this
->
assertSame
(
$this
->
manager
,
$debug
[
'manager'
]);
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertSame
(
'fs'
,
$debug
[
'bucketName'
]);
$this
->
assertSame
(
261120
,
$debug
[
'chunkSizeBytes'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectGridFSBucketPassesOptions
()
{
$bucketOptions
=
[
'bucketName'
=>
'custom_fs'
,
'chunkSizeBytes'
=>
8192
,
'readConcern'
=>
new
ReadConcern
(
ReadConcern
::
LOCAL
),
'readPreference'
=>
new
ReadPreference
(
ReadPreference
::
RP_SECONDARY_PREFERRED
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$bucket
=
$database
->
selectGridFSBucket
(
$bucketOptions
);
$debug
=
$bucket
->
__debugInfo
();
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertSame
(
'custom_fs'
,
$debug
[
'bucketName'
]);
$this
->
assertSame
(
8192
,
$debug
[
'chunkSizeBytes'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadConcern'
,
$debug
[
'readConcern'
]);
$this
->
assertSame
(
ReadConcern
::
LOCAL
,
$debug
[
'readConcern'
]
->
getLevel
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\ReadPreference'
,
$debug
[
'readPreference'
]);
$this
->
assertSame
(
ReadPreference
::
RP_SECONDARY_PREFERRED
,
$debug
[
'readPreference'
]
->
getMode
());
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testWithOptionsInheritsOptions
()
{
$databaseOptions
=
[
...
...
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