@@ -92,12 +92,12 @@ final class Generator
92
92
/**
93
93
* Returns a test double for the specified class.
94
94
*
95
- * @throws ClassAlreadyExistsException
96
95
* @throws ClassIsEnumerationException
97
96
* @throws ClassIsFinalException
98
97
* @throws ClassIsReadonlyException
99
98
* @throws DuplicateMethodException
100
99
* @throws InvalidMethodNameException
100
+ * @throws NameAlreadyInUseException
101
101
* @throws OriginalConstructorInvocationRequiredException
102
102
* @throws ReflectionException
103
103
* @throws RuntimeException
@@ -114,7 +114,7 @@ public function testDouble(string $type, bool $mockObject, ?array $methods = [],
114
114
}
115
115
116
116
$ this ->ensureValidMethods ($ methods );
117
- $ this ->ensureMockedClassDoesNotAlreadyExist ($ mockClassName );
117
+ $ this ->ensureNameForTestDoubleClassIsAvailable ($ mockClassName );
118
118
119
119
if (!$ callOriginalConstructor && $ callOriginalMethods ) {
120
120
throw new OriginalConstructorInvocationRequiredException ;
@@ -219,13 +219,13 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock
219
219
*
220
220
* Concrete methods to mock can be specified with the $mockedMethods parameter.
221
221
*
222
- * @throws ClassAlreadyExistsException
223
222
* @throws ClassIsEnumerationException
224
223
* @throws ClassIsFinalException
225
224
* @throws ClassIsReadonlyException
226
225
* @throws DuplicateMethodException
227
226
* @throws InvalidArgumentException
228
227
* @throws InvalidMethodNameException
228
+ * @throws NameAlreadyInUseException
229
229
* @throws OriginalConstructorInvocationRequiredException
230
230
* @throws ReflectionException
231
231
* @throws RuntimeException
@@ -279,13 +279,13 @@ interface_exists($originalClassName, $callAutoload)) {
279
279
*
280
280
* @psalm-param trait-string $traitName
281
281
*
282
- * @throws ClassAlreadyExistsException
283
282
* @throws ClassIsEnumerationException
284
283
* @throws ClassIsFinalException
285
284
* @throws ClassIsReadonlyException
286
285
* @throws DuplicateMethodException
287
286
* @throws InvalidArgumentException
288
287
* @throws InvalidMethodNameException
288
+ * @throws NameAlreadyInUseException
289
289
* @throws OriginalConstructorInvocationRequiredException
290
290
* @throws ReflectionException
291
291
* @throws RuntimeException
@@ -922,17 +922,19 @@ private function ensureValidMethods(?array $methods): void
922
922
}
923
923
924
924
/**
925
- * @throws ClassAlreadyExistsException
925
+ * @throws NameAlreadyInUseException
926
926
* @throws ReflectionException
927
927
*/
928
- private function ensureMockedClassDoesNotAlreadyExist (string $ mockClassName ): void
928
+ private function ensureNameForTestDoubleClassIsAvailable (string $ className ): void
929
929
{
930
- if ($ mockClassName !== '' && class_exists ($ mockClassName , false )) {
931
- $ reflector = $ this ->reflectClass ($ mockClassName );
930
+ if ($ className === '' ) {
931
+ return ;
932
+ }
932
933
933
- if (!$ reflector ->implementsInterface (MockObject::class)) {
934
- throw new ClassAlreadyExistsException ($ mockClassName );
935
- }
934
+ if (class_exists ($ className , false ) ||
935
+ interface_exists ($ className , false ) ||
936
+ trait_exists ($ className , false )) {
937
+ throw new NameAlreadyInUseException ($ className );
936
938
}
937
939
}
938
940
0 commit comments