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
dce08e00
Commit
dce08e00
authored
Apr 26, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-75: Unit tests for database, collection, and index models
parent
e90d518d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
252 additions
and
1 deletion
+252
-1
IndexInfo.php
src/Model/IndexInfo.php
+1
-1
CollectionInfoTest.php
tests/Model/CollectionInfoTest.php
+42
-0
DatabaseInfoTest.php
tests/Model/DatabaseInfoTest.php
+30
-0
IndexInfoTest.php
tests/Model/IndexInfoTest.php
+86
-0
IndexInputTest.php
tests/Model/IndexInputTest.php
+93
-0
No files found.
src/Model/IndexInfo.php
View file @
dce08e00
...
...
@@ -133,7 +133,7 @@ class IndexInfo implements ArrayAccess
*/
public
function
offsetGet
(
$key
)
{
return
$this
->
data
[
$key
];
return
$this
->
info
[
$key
];
}
/**
...
...
tests/Model/CollectionInfoTest.php
0 → 100644
View file @
dce08e00
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\CollectionInfo
;
use
MongoDB\Tests\TestCase
;
class
CollectionInfoTest
extends
TestCase
{
public
function
testGetName
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
));
$this
->
assertSame
(
'foo'
,
$info
->
getName
());
}
public
function
testGetOptions
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
));
$this
->
assertSame
(
array
(),
$info
->
getOptions
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
)));
$this
->
assertSame
(
array
(
'capped'
=>
true
,
'size'
=>
1048576
),
$info
->
getOptions
());
}
public
function
testCappedCollectionMethods
()
{
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
));
$this
->
assertFalse
(
$info
->
isCapped
());
$this
->
assertNull
(
$info
->
getCappedMax
());
$this
->
assertNull
(
$info
->
getCappedSize
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
)));
$this
->
assertTrue
(
$info
->
isCapped
());
$this
->
assertNull
(
$info
->
getCappedMax
());
$this
->
assertSame
(
1048576
,
$info
->
getCappedSize
());
$info
=
new
CollectionInfo
(
array
(
'name'
=>
'foo'
,
'options'
=>
array
(
'capped'
=>
true
,
'size'
=>
1048576
,
'max'
=>
100
)));
$this
->
assertTrue
(
$info
->
isCapped
());
$this
->
assertSame
(
100
,
$info
->
getCappedMax
());
$this
->
assertSame
(
1048576
,
$info
->
getCappedSize
());
}
}
tests/Model/DatabaseInfoTest.php
0 → 100644
View file @
dce08e00
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\DatabaseInfo
;
use
MongoDB\Tests\TestCase
;
class
DatabaseInfoTest
extends
TestCase
{
public
function
testGetName
()
{
$info
=
new
DatabaseInfo
(
array
(
'name'
=>
'foo'
));
$this
->
assertSame
(
'foo'
,
$info
->
getName
());
}
public
function
testGetSizeOnDisk
()
{
$info
=
new
DatabaseInfo
(
array
(
'sizeOnDisk'
=>
'1048576'
));
$this
->
assertSame
(
1048576
,
$info
->
getSizeOnDisk
());
}
public
function
testIsEmpty
()
{
$info
=
new
DatabaseInfo
(
array
(
'empty'
=>
false
));
$this
->
assertFalse
(
$info
->
isEmpty
());
$info
=
new
DatabaseInfo
(
array
(
'empty'
=>
true
));
$this
->
assertTrue
(
$info
->
isEmpty
());
}
}
tests/Model/IndexInfoTest.php
0 → 100644
View file @
dce08e00
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Tests\TestCase
;
class
IndexInfoTest
extends
TestCase
{
public
function
testBasicIndex
()
{
$info
=
new
IndexInfo
(
array
(
'v'
=>
1
,
'key'
=>
array
(
'x'
=>
1
),
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
));
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'x'
=>
1
),
$info
->
getKey
());
$this
->
assertSame
(
'x_1'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
public
function
testSparseIndex
()
{
$info
=
new
IndexInfo
(
array
(
'v'
=>
1
,
'key'
=>
array
(
'y'
=>
1
),
'name'
=>
'y_sparse'
,
'ns'
=>
'foo.bar'
,
'sparse'
=>
true
,
));
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'y'
=>
1
),
$info
->
getKey
());
$this
->
assertSame
(
'y_sparse'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertTrue
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
}
public
function
testUniqueIndex
()
{
$info
=
new
IndexInfo
(
array
(
'v'
=>
1
,
'key'
=>
array
(
'z'
=>
1
),
'name'
=>
'z_unique'
,
'ns'
=>
'foo.bar'
,
'unique'
=>
true
,
));
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'z'
=>
1
),
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertFalse
(
$info
->
isTtl
());
$this
->
assertTrue
(
$info
->
isUnique
());
}
public
function
testTtlIndex
()
{
$info
=
new
IndexInfo
(
array
(
'v'
=>
1
,
'key'
=>
array
(
'z'
=>
1
),
'name'
=>
'z_unique'
,
'ns'
=>
'foo.bar'
,
'expireAfterSeconds'
=>
100
,
));
$this
->
assertSame
(
1
,
$info
->
getVersion
());
$this
->
assertSame
(
array
(
'z'
=>
1
),
$info
->
getKey
());
$this
->
assertSame
(
'z_unique'
,
$info
->
getName
());
$this
->
assertSame
(
'foo.bar'
,
$info
->
getNamespace
());
$this
->
assertFalse
(
$info
->
isSparse
());
$this
->
assertTrue
(
$info
->
isTtl
());
$this
->
assertFalse
(
$info
->
isUnique
());
$this
->
assertTrue
(
isset
(
$info
[
'expireAfterSeconds'
]));
$this
->
assertSame
(
100
,
$info
[
'expireAfterSeconds'
]);
}
}
tests/Model/IndexInputTest.php
0 → 100644
View file @
dce08e00
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\IndexInput
;
use
MongoDB\Tests\TestCase
;
class
IndexInputTest
extends
TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testConstructorShouldRequireKey
()
{
new
IndexInput
(
array
());
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
*/
public
function
testConstructorShouldRequireKeyToBeArrayOrObject
()
{
new
IndexInput
(
array
(
'key'
=>
'foo'
));
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
*/
public
function
testConstructorShouldRequireKeyOrderToBeScalar
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
array
())));
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
*/
public
function
testConstructorShouldRequireNamespace
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
)));
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
*/
public
function
testConstructorShouldRequireNamespaceToBeString
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
1
));
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
*/
public
function
testConstructorShouldRequireNameToBeString
()
{
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
'foo.bar'
,
'name'
=>
1
));
}
/**
* @dataProvider provideExpectedNameAndKey
*/
public
function
testNameGeneration
(
$expectedName
,
array
$key
)
{
$this
->
assertSame
(
$expectedName
,
(
string
)
new
IndexInput
(
array
(
'key'
=>
$key
,
'ns'
=>
'foo.bar'
)));
}
public
function
provideExpectedNameAndKey
()
{
return
array
(
array
(
'x_1'
,
array
(
'x'
=>
1
)),
array
(
'x_1_y_-1'
,
array
(
'x'
=>
1
,
'y'
=>
-
1
)),
array
(
'loc_2dsphere'
,
array
(
'loc'
=>
'2dsphere'
)),
array
(
'loc_2dsphere_x_1'
,
array
(
'loc'
=>
'2dsphere'
,
'x'
=>
1
)),
array
(
'doc_text'
,
array
(
'doc'
=>
'text'
)),
);
}
public
function
testBsonSerialization
()
{
$expected
=
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
'foo.bar'
,
'name'
=>
'x_1'
,
);
$indexInput
=
new
IndexInput
(
array
(
'key'
=>
array
(
'x'
=>
1
),
'ns'
=>
'foo.bar'
,
));
$this
->
assertInstanceOf
(
'BSON\Serializable'
,
$indexInput
);
$this
->
assertEquals
(
$expected
,
$indexInput
->
bsonSerialize
());
}
}
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