@@ -69,22 +69,18 @@ public function testCreateNamedStringScalarClass(StringScalar $stringScalar): vo
6969 */
7070 public function testSerializeThrowsIfUnserializableValueIsGiven (StringScalar $ stringScalar ): void
7171 {
72- $ this -> expectException (InvariantViolation:: class) ;
72+ $ object = new class () {} ;
7373
74- $ stringScalar ->serialize (
75- new class () {
76- }
77- );
74+ $ this ->expectException (InvariantViolation::class);
75+ $ stringScalar ->serialize ($ object );
7876 }
7977
8078 /**
8179 * @dataProvider stringClassProvider
8280 */
8381 public function testSerializeThrowsIfStringScalarIsNotValid (StringScalar $ stringScalar ): void
8482 {
85- $ this ->expectException (InvariantViolation::class);
86- $ this ->expectExceptionMessage ('The given string "bar" is not a valid MyStringScalar. ' );
87-
83+ $ this ->expectExceptionObject (new InvariantViolation ('The given string "bar" is not a valid MyStringScalar. ' ));
8884 $ stringScalar ->serialize ('bar ' );
8985 }
9086
@@ -120,11 +116,11 @@ public function __toString(): string
120116 */
121117 public function testParseValueThrowsIfValueCantBeString (StringScalar $ stringScalar ): void
122118 {
119+ $ object = new class () {};
120+
123121 $ this ->expectException (Error::class);
124122 $ this ->expectExceptionMessageMatches (/** @lang RegExp */ '/can not be coerced to a string/ ' );
125-
126- $ stringScalar ->parseValue (new class () {
127- });
123+ $ stringScalar ->parseValue ($ object );
128124 }
129125
130126 /**
@@ -154,21 +150,22 @@ public function testParseValuePassesOnMatch(StringScalar $stringScalar): void
154150 */
155151 public function testParseLiteralThrowsIfNotString (StringScalar $ stringScalar ): void
156152 {
153+ $ intValueNode = new IntValueNode ([]);
154+
157155 $ this ->expectException (Error::class);
158156 $ this ->expectExceptionMessageMatches (/** @lang RegExp */ '/ ' . NodeKind::INT . '/ ' );
159-
160- $ stringScalar ->parseLiteral (new IntValueNode ([]));
157+ $ stringScalar ->parseLiteral ($ intValueNode );
161158 }
162159
163160 /**
164161 * @dataProvider stringClassProvider
165162 */
166163 public function testParseLiteralThrowsIfValueDoesNotMatch (StringScalar $ stringScalar ): void
167164 {
168- $ this ->expectException (Error::class);
169- $ this ->expectExceptionMessage ('The given string "bar" is not a valid MyStringScalar. ' );
165+ $ stringValueNode = new StringValueNode (['value ' => 'bar ' ]);
170166
171- $ stringScalar ->parseLiteral (new StringValueNode (['value ' => 'bar ' ]));
167+ $ this ->expectExceptionObject (new Error ('The given string "bar" is not a valid MyStringScalar. ' ));
168+ $ stringScalar ->parseLiteral ($ stringValueNode );
172169 }
173170
174171 /**
0 commit comments