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
4f7349e9
Commit
4f7349e9
authored
Jan 07, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-141: Static method for immutable BadMethodCallException
parent
c02f1272
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
4 deletions
+47
-4
BadMethodCallException.php
src/Exception/BadMethodCallException.php
+11
-0
IndexInfo.php
src/Model/IndexInfo.php
+4
-4
IndexInfoTest.php
tests/Model/IndexInfoTest.php
+32
-0
No files found.
src/Exception/BadMethodCallException.php
View file @
4f7349e9
...
...
@@ -4,6 +4,17 @@ namespace MongoDB\Exception;
class
BadMethodCallException
extends
\BadMethodCallException
implements
Exception
{
/**
* Thrown when a mutable method is invoked on an immutable object.
*
* @param string $class Class name
* @return self
*/
public
static
function
classIsImmutable
(
$class
)
{
return
new
static
(
sprintf
(
'%s is immutable'
,
$class
));
}
/**
* Thrown when accessing a result field on an unacknowledged write result.
*
...
...
src/Model/IndexInfo.php
View file @
4f7349e9
...
...
@@ -151,21 +151,21 @@ class IndexInfo implements ArrayAccess
* Not supported.
*
* @see http://php.net/arrayaccess.offsetset
* @throws BadMethodCallException
IndexInfo is immutable
* @throws BadMethodCallException
*/
public
function
offsetSet
(
$key
,
$value
)
{
throw
new
BadMethodCallException
(
'IndexInfo is immutable'
);
throw
BadMethodCallException
::
classIsImmutable
(
__CLASS__
);
}
/**
* Not supported.
*
* @see http://php.net/arrayaccess.offsetunset
* @throws BadMethodCallException
IndexInfo is immutable
* @throws BadMethodCallException
*/
public
function
offsetUnset
(
$key
)
{
throw
new
BadMethodCallException
(
'IndexInfo is immutable'
);
throw
BadMethodCallException
::
classIsImmutable
(
__CLASS__
);
}
}
tests/Model/IndexInfoTest.php
View file @
4f7349e9
...
...
@@ -96,4 +96,36 @@ class IndexInfoTest extends TestCase
$info
=
new
IndexInfo
(
$expectedInfo
);
$this
->
assertSame
(
$expectedInfo
,
$info
->
__debugInfo
());
}
/**
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
*/
public
function
testOffsetSetCannotBeCalled
()
{
$info
=
new
IndexInfo
([
'v'
=>
1
,
'key'
=>
[
'x'
=>
1
],
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
]);
$info
[
'v'
]
=
2
;
}
/**
* @expectedException MongoDB\Exception\BadMethodCallException
* @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
*/
public
function
testOffsetUnsetCannotBeCalled
()
{
$info
=
new
IndexInfo
([
'v'
=>
1
,
'key'
=>
[
'x'
=>
1
],
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
]);
unset
(
$info
[
'v'
]);
}
}
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