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
9918b971
Commit
9918b971
authored
Apr 27, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9 from jmikola/pedantry
Pedantry tests
parents
97ab718e
869c94a1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
154 additions
and
116 deletions
+154
-116
Client.php
src/Client.php
+12
-12
CollectionInfo.php
src/Model/CollectionInfo.php
+20
-20
CollectionInfoLegacyIterator.php
src/Model/CollectionInfoLegacyIterator.php
+21
-21
DatabaseInfo.php
src/Model/DatabaseInfo.php
+11
-11
IndexInfo.php
src/Model/IndexInfo.php
+11
-11
IndexInput.php
src/Model/IndexInput.php
+9
-9
CollectionTest.php
tests/CollectionTest.php
+0
-32
PedantryTest.php
tests/PedantryTest.php
+70
-0
No files found.
src/Client.php
View file @
9918b971
...
@@ -79,44 +79,44 @@ class Client
...
@@ -79,44 +79,44 @@ class Client
}
}
/**
/**
* Select a
database
.
* Select a
collection
.
*
*
* If a write concern or read preference is not specified, the write concern
* If a write concern or read preference is not specified, the write concern
* or read preference of the Client will be applied, respectively.
* or read preference of the Client will be applied, respectively.
*
*
* @param string $databaseName Name of the database to select
* @param string $databaseName Name of the database containing the collection
* @param string $collectionName Name of the collection to select
* @param WriteConcern $writeConcern Default write concern to apply
* @param WriteConcern $writeConcern Default write concern to apply
* @param ReadPreference $readPreference Default read preference to apply
* @param ReadPreference $readPreference Default read preference to apply
* @return
Database
* @return
Collection
*/
*/
public
function
select
Database
(
$database
Name
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
select
Collection
(
$databaseName
,
$collection
Name
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
$namespace
=
$databaseName
.
'.'
.
$collectionName
;
// TODO: inherit from Manager options once PHPC-196 is implemented
// TODO: inherit from Manager options once PHPC-196 is implemented
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
return
new
Database
(
$this
->
manager
,
$databaseNam
e
,
$writeConcern
,
$readPreference
);
return
new
Collection
(
$this
->
manager
,
$namespac
e
,
$writeConcern
,
$readPreference
);
}
}
/**
/**
* Select a
collection
.
* Select a
database
.
*
*
* If a write concern or read preference is not specified, the write concern
* If a write concern or read preference is not specified, the write concern
* or read preference of the Client will be applied, respectively.
* or read preference of the Client will be applied, respectively.
*
*
* @param string $databaseName Name of the database containing the collection
* @param string $databaseName Name of the database to select
* @param string $collectionName Name of the collection to select
* @param WriteConcern $writeConcern Default write concern to apply
* @param WriteConcern $writeConcern Default write concern to apply
* @param ReadPreference $readPreference Default read preference to apply
* @param ReadPreference $readPreference Default read preference to apply
* @return
Collection
* @return
Database
*/
*/
public
function
select
Collection
(
$databaseName
,
$collection
Name
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
select
Database
(
$database
Name
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
$namespace
=
$databaseName
.
'.'
.
$collectionName
;
// TODO: inherit from Manager options once PHPC-196 is implemented
// TODO: inherit from Manager options once PHPC-196 is implemented
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$writeConcern
=
$writeConcern
?:
$this
->
writeConcern
;
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
$readPreference
=
$readPreference
?:
$this
->
readPreference
;
return
new
Collection
(
$this
->
manager
,
$namespac
e
,
$writeConcern
,
$readPreference
);
return
new
Database
(
$this
->
manager
,
$databaseNam
e
,
$writeConcern
,
$readPreference
);
}
}
}
}
src/Model/CollectionInfo.php
View file @
9918b971
...
@@ -28,53 +28,53 @@ class CollectionInfo
...
@@ -28,53 +28,53 @@ class CollectionInfo
}
}
/**
/**
* Return the
collection name
.
* Return the
maximum number of documents to keep in the capped collection
.
*
*
* @return
string
* @return
integer|null
*/
*/
public
function
get
Name
()
public
function
get
CappedMax
()
{
{
return
(
string
)
$this
->
info
[
'name'
]
;
return
isset
(
$this
->
info
[
'options'
][
'max'
])
?
(
integer
)
$this
->
info
[
'options'
][
'max'
]
:
null
;
}
}
/**
/**
* Return the
collection options
.
* Return the
maximum size (in bytes) of the capped collection
.
*
*
* @return
array
* @return
integer|null
*/
*/
public
function
get
Options
()
public
function
get
CappedSize
()
{
{
return
isset
(
$this
->
info
[
'options'
]
)
?
(
array
)
$this
->
info
[
'options'
]
:
array
()
;
return
isset
(
$this
->
info
[
'options'
]
[
'size'
])
?
(
integer
)
$this
->
info
[
'options'
][
'size'
]
:
null
;
}
}
/**
/**
* Return
whether the collection is a capped collection
.
* Return
the collection name
.
*
*
* @return
boolean
* @return
string
*/
*/
public
function
isCapped
()
public
function
getName
()
{
{
return
!
empty
(
$this
->
info
[
'options'
][
'capped'
])
;
return
(
string
)
$this
->
info
[
'name'
]
;
}
}
/**
/**
* Return the
maximum number of documents to keep in the capped collection
.
* Return the
collection options
.
*
*
* @return
integer|null
* @return
array
*/
*/
public
function
get
CappedMax
()
public
function
get
Options
()
{
{
return
isset
(
$this
->
info
[
'options'
]
[
'max'
])
?
(
integer
)
$this
->
info
[
'options'
][
'max'
]
:
null
;
return
isset
(
$this
->
info
[
'options'
]
)
?
(
array
)
$this
->
info
[
'options'
]
:
array
()
;
}
}
/**
/**
* Return
the maximum size (in bytes) of the
capped collection.
* Return
whether the collection is a
capped collection.
*
*
* @return
integer|null
* @return
boolean
*/
*/
public
function
getCappedSize
()
public
function
isCapped
()
{
{
return
isset
(
$this
->
info
[
'options'
][
'size'
])
?
(
integer
)
$this
->
info
[
'options'
][
'size'
]
:
null
;
return
!
empty
(
$this
->
info
[
'options'
][
'capped'
])
;
}
}
/**
/**
...
...
src/Model/CollectionInfoLegacyIterator.php
View file @
9918b971
...
@@ -40,27 +40,6 @@ class CollectionInfoLegacyIterator extends FilterIterator implements CollectionI
...
@@ -40,27 +40,6 @@ class CollectionInfoLegacyIterator extends FilterIterator implements CollectionI
parent
::
__construct
(
$iterator
);
parent
::
__construct
(
$iterator
);
}
}
/**
* Return the current element as a CollectionInfo instance.
*
* @see CollectionInfoIterator::current()
* @see http://php.net/iterator.current
* @return CollectionInfo
*/
public
function
current
()
{
$info
=
parent
::
current
();
// Trim the database prefix up to and including the first dot
$firstDot
=
strpos
(
$info
[
'name'
],
'.'
);
if
(
$firstDot
!==
false
)
{
$info
[
'name'
]
=
(
string
)
substr
(
$info
[
'name'
],
$firstDot
+
1
);
}
return
new
CollectionInfo
(
$info
);
}
/**
/**
* Filter out internal or invalid collections.
* Filter out internal or invalid collections.
*
*
...
@@ -92,4 +71,25 @@ class CollectionInfoLegacyIterator extends FilterIterator implements CollectionI
...
@@ -92,4 +71,25 @@ class CollectionInfoLegacyIterator extends FilterIterator implements CollectionI
return
true
;
return
true
;
}
}
/**
* Return the current element as a CollectionInfo instance.
*
* @see CollectionInfoIterator::current()
* @see http://php.net/iterator.current
* @return CollectionInfo
*/
public
function
current
()
{
$info
=
parent
::
current
();
// Trim the database prefix up to and including the first dot
$firstDot
=
strpos
(
$info
[
'name'
],
'.'
);
if
(
$firstDot
!==
false
)
{
$info
[
'name'
]
=
(
string
)
substr
(
$info
[
'name'
],
$firstDot
+
1
);
}
return
new
CollectionInfo
(
$info
);
}
}
}
src/Model/DatabaseInfo.php
View file @
9918b971
...
@@ -26,6 +26,17 @@ class DatabaseInfo
...
@@ -26,6 +26,17 @@ class DatabaseInfo
$this
->
info
=
$info
;
$this
->
info
=
$info
;
}
}
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public
function
__debugInfo
()
{
return
$this
->
info
;
}
/**
/**
* Return the database name.
* Return the database name.
*
*
...
@@ -55,15 +66,4 @@ class DatabaseInfo
...
@@ -55,15 +66,4 @@ class DatabaseInfo
{
{
return
(
boolean
)
$this
->
info
[
'empty'
];
return
(
boolean
)
$this
->
info
[
'empty'
];
}
}
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public
function
__debugInfo
()
{
return
$this
->
info
;
}
}
}
src/Model/IndexInfo.php
View file @
9918b971
...
@@ -34,6 +34,17 @@ class IndexInfo implements ArrayAccess
...
@@ -34,6 +34,17 @@ class IndexInfo implements ArrayAccess
$this
->
info
=
$info
;
$this
->
info
=
$info
;
}
}
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public
function
__debugInfo
()
{
return
$this
->
info
;
}
/**
/**
* Return the index key.
* Return the index key.
*
*
...
@@ -157,15 +168,4 @@ class IndexInfo implements ArrayAccess
...
@@ -157,15 +168,4 @@ class IndexInfo implements ArrayAccess
{
{
throw
new
BadMethodCallException
(
'IndexInfo is immutable'
);
throw
new
BadMethodCallException
(
'IndexInfo is immutable'
);
}
}
/**
* Return the collection info as an array.
*
* @see http://php.net/oop5.magic#language.oop5.magic.debuginfo
* @return array
*/
public
function
__debugInfo
()
{
return
$this
->
info
;
}
}
}
src/Model/IndexInput.php
View file @
9918b971
...
@@ -61,24 +61,24 @@ class IndexInput implements Serializable
...
@@ -61,24 +61,24 @@ class IndexInput implements Serializable
}
}
/**
/**
*
Serialize the index information to BSON for index creation
.
*
Return the index name
.
*
*
* @see MongoDB\Collection::createIndexes()
* @param string
* @see http://php.net/bson-serializable.bsonserialize
*/
*/
public
function
bsonSerialize
()
public
function
__toString
()
{
{
return
$this
->
index
;
return
$this
->
index
[
'name'
]
;
}
}
/**
/**
*
Return the index name
.
*
Serialize the index information to BSON for index creation
.
*
*
* @param string
* @see MongoDB\Collection::createIndexes()
* @see http://php.net/bson-serializable.bsonserialize
*/
*/
public
function
__toString
()
public
function
bsonSerialize
()
{
{
return
$this
->
index
[
'name'
]
;
return
$this
->
index
;
}
}
/**
/**
...
...
tests/CollectionTest.php
deleted
100644 → 0
View file @
97ab718e
<?php
namespace
MongoDB\Tests
;
use
ReflectionClass
;
use
ReflectionMethod
;
class
CollectionTest
extends
TestCase
{
public
function
testMethodOrder
()
{
$class
=
new
ReflectionClass
(
'MongoDB\Collection'
);
$filters
=
array
(
'public'
=>
ReflectionMethod
::
IS_PUBLIC
,
'protected'
=>
ReflectionMethod
::
IS_PROTECTED
,
'private'
=>
ReflectionMethod
::
IS_PRIVATE
,
);
foreach
(
$filters
as
$visibility
=>
$filter
)
{
$methods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$class
->
getMethods
(
$filter
)
);
$sortedMethods
=
$methods
;
sort
(
$sortedMethods
);
$this
->
assertEquals
(
$methods
,
$sortedMethods
,
sprintf
(
'%s methods are declared alphabetically'
,
ucfirst
(
$visibility
)));
}
}
}
tests/PedantryTest.php
0 → 100644
View file @
9918b971
<?php
namespace
MongoDB\Tests
;
use
RecursiveDirectoryIterator
;
use
RecursiveIteratorIterator
;
use
ReflectionClass
;
use
ReflectionMethod
;
use
RegexIterator
;
/**
* Pedantic tests that have nothing to do with functional correctness.
*/
class
PedantryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideProjectClassNames
*/
public
function
testMethodsAreOrderedAlphabeticallyByVisibility
(
$className
)
{
$class
=
new
ReflectionClass
(
$className
);
$methods
=
$class
->
getMethods
();
$methods
=
array_filter
(
$methods
,
function
(
ReflectionMethod
$method
)
use
(
$class
)
{
return
$method
->
getDeclaringClass
()
==
$class
;
}
);
$getSortValue
=
function
(
ReflectionMethod
$method
)
{
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PRIVATE
)
{
return
'2'
.
$method
->
getName
();
}
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PROTECTED
)
{
return
'1'
.
$method
->
getName
();
}
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PUBLIC
)
{
return
'0'
.
$method
->
getName
();
}
};
$sortedMethods
=
$methods
;
usort
(
$sortedMethods
,
function
(
ReflectionMethod
$a
,
ReflectionMethod
$b
)
use
(
$getSortValue
)
{
return
strcasecmp
(
$getSortValue
(
$a
),
$getSortValue
(
$b
));
}
);
$methods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$methods
);
$sortedMethods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$sortedMethods
);
$this
->
assertEquals
(
$sortedMethods
,
$methods
);
}
public
function
provideProjectClassNames
()
{
$classNames
=
array
();
$srcDir
=
realpath
(
__DIR__
.
'/../src/'
);
$files
=
new
RegexIterator
(
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$srcDir
)),
'/\.php$/i'
);
foreach
(
$files
as
$file
)
{
$classNames
[][]
=
'MongoDB\\'
.
str_replace
(
DIRECTORY_SEPARATOR
,
'\\'
,
substr
(
$file
->
getRealPath
(),
strlen
(
$srcDir
)
+
1
,
-
4
));
}
return
$classNames
;
}
}
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