@@ -96,12 +96,12 @@ final class Generator
96
96
/**
97
97
* Returns a test double for the specified class.
98
98
*
99
- * @throws ClassAlreadyExistsException
100
99
* @throws ClassIsEnumerationException
101
100
* @throws ClassIsFinalException
102
101
* @throws ClassIsReadonlyException
103
102
* @throws DuplicateMethodException
104
103
* @throws InvalidMethodNameException
104
+ * @throws NameAlreadyInUseException
105
105
* @throws OriginalConstructorInvocationRequiredException
106
106
* @throws ReflectionException
107
107
* @throws RuntimeException
@@ -118,7 +118,7 @@ public function testDouble(string $type, bool $mockObject, bool $markAsMockObjec
118
118
}
119
119
120
120
$ this ->ensureValidMethods ($ methods );
121
- $ this ->ensureMockedClassDoesNotAlreadyExist ($ mockClassName );
121
+ $ this ->ensureNameForTestDoubleClassIsAvailable ($ mockClassName );
122
122
123
123
if (!$ callOriginalConstructor && $ callOriginalMethods ) {
124
124
throw new OriginalConstructorInvocationRequiredException ;
@@ -229,13 +229,13 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock
229
229
*
230
230
* Concrete methods to mock can be specified with the $mockedMethods parameter.
231
231
*
232
- * @throws ClassAlreadyExistsException
233
232
* @throws ClassIsEnumerationException
234
233
* @throws ClassIsFinalException
235
234
* @throws ClassIsReadonlyException
236
235
* @throws DuplicateMethodException
237
236
* @throws InvalidArgumentException
238
237
* @throws InvalidMethodNameException
238
+ * @throws NameAlreadyInUseException
239
239
* @throws OriginalConstructorInvocationRequiredException
240
240
* @throws ReflectionException
241
241
* @throws RuntimeException
@@ -290,13 +290,13 @@ interface_exists($originalClassName, $callAutoload)) {
290
290
*
291
291
* @psalm-param trait-string $traitName
292
292
*
293
- * @throws ClassAlreadyExistsException
294
293
* @throws ClassIsEnumerationException
295
294
* @throws ClassIsFinalException
296
295
* @throws ClassIsReadonlyException
297
296
* @throws DuplicateMethodException
298
297
* @throws InvalidArgumentException
299
298
* @throws InvalidMethodNameException
299
+ * @throws NameAlreadyInUseException
300
300
* @throws OriginalConstructorInvocationRequiredException
301
301
* @throws ReflectionException
302
302
* @throws RuntimeException
@@ -960,17 +960,19 @@ private function ensureValidMethods(?array $methods): void
960
960
}
961
961
962
962
/**
963
- * @throws ClassAlreadyExistsException
963
+ * @throws NameAlreadyInUseException
964
964
* @throws ReflectionException
965
965
*/
966
- private function ensureMockedClassDoesNotAlreadyExist (string $ mockClassName ): void
966
+ private function ensureNameForTestDoubleClassIsAvailable (string $ className ): void
967
967
{
968
- if ($ mockClassName !== '' && class_exists ($ mockClassName , false )) {
969
- $ reflector = $ this ->reflectClass ($ mockClassName );
968
+ if ($ className === '' ) {
969
+ return ;
970
+ }
970
971
971
- if (!$ reflector ->implementsInterface (MockObject::class)) {
972
- throw new ClassAlreadyExistsException ($ mockClassName );
973
- }
972
+ if (class_exists ($ className , false ) ||
973
+ interface_exists ($ className , false ) ||
974
+ trait_exists ($ className , false )) {
975
+ throw new NameAlreadyInUseException ($ className );
974
976
}
975
977
}
976
978
0 commit comments