File tree Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 4
4
5
5
class BadMethodCallException extends \BadMethodCallException implements Exception
6
6
{
7
+ /**
8
+ * Thrown when a mutable method is invoked on an immutable object.
9
+ *
10
+ * @param string $class Class name
11
+ * @return self
12
+ */
13
+ public static function classIsImmutable ($ class )
14
+ {
15
+ return new static (sprintf ('%s is immutable ' , $ class ));
16
+ }
17
+
7
18
/**
8
19
* Thrown when accessing a result field on an unacknowledged write result.
9
20
*
Original file line number Diff line number Diff line change @@ -151,21 +151,21 @@ public function offsetGet($key)
151
151
* Not supported.
152
152
*
153
153
* @see http://php.net/arrayaccess.offsetset
154
- * @throws BadMethodCallException IndexInfo is immutable
154
+ * @throws BadMethodCallException
155
155
*/
156
156
public function offsetSet ($ key , $ value )
157
157
{
158
- throw new BadMethodCallException ( ' IndexInfo is immutable ' );
158
+ throw BadMethodCallException:: classIsImmutable ( __CLASS__ );
159
159
}
160
160
161
161
/**
162
162
* Not supported.
163
163
*
164
164
* @see http://php.net/arrayaccess.offsetunset
165
- * @throws BadMethodCallException IndexInfo is immutable
165
+ * @throws BadMethodCallException
166
166
*/
167
167
public function offsetUnset ($ key )
168
168
{
169
- throw new BadMethodCallException ( ' IndexInfo is immutable ' );
169
+ throw BadMethodCallException:: classIsImmutable ( __CLASS__ );
170
170
}
171
171
}
Original file line number Diff line number Diff line change @@ -96,4 +96,36 @@ public function testDebugInfo()
96
96
$ info = new IndexInfo ($ expectedInfo );
97
97
$ this ->assertSame ($ expectedInfo , $ info ->__debugInfo ());
98
98
}
99
+
100
+ /**
101
+ * @expectedException MongoDB\Exception\BadMethodCallException
102
+ * @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
103
+ */
104
+ public function testOffsetSetCannotBeCalled ()
105
+ {
106
+ $ info = new IndexInfo ([
107
+ 'v ' => 1 ,
108
+ 'key ' => ['x ' => 1 ],
109
+ 'name ' => 'x_1 ' ,
110
+ 'ns ' => 'foo.bar ' ,
111
+ ]);
112
+
113
+ $ info ['v ' ] = 2 ;
114
+ }
115
+
116
+ /**
117
+ * @expectedException MongoDB\Exception\BadMethodCallException
118
+ * @expectedExceptionMessage MongoDB\Model\IndexInfo is immutable
119
+ */
120
+ public function testOffsetUnsetCannotBeCalled ()
121
+ {
122
+ $ info = new IndexInfo ([
123
+ 'v ' => 1 ,
124
+ 'key ' => ['x ' => 1 ],
125
+ 'name ' => 'x_1 ' ,
126
+ 'ns ' => 'foo.bar ' ,
127
+ ]);
128
+
129
+ unset($ info ['v ' ]);
130
+ }
99
131
}
You can’t perform that action at this time.
0 commit comments