@@ -15,18 +15,20 @@ protected function setUp(): void
1515 $ this ->addInvalidMatcher = false ;
1616 }
1717
18- /**
19- * @dataProvider correctExpectations
20- */
18+ #[\PHPUnit \Framework \Attributes \DataProvider('correctExpectations ' )]
2119 public function testItDoesNotThrowWhenExpectationIsMet ($ expectation ): void
2220 {
2321 $ expectation ();
2422 $ this ->addToAssertionCount (1 ); // No exception thrown
2523 }
2624
27- /**
28- * @dataProvider incorrectExpectations
29- */
25+ public function testItDoesNotThrowWhenExpectationIsMetAndACustomMatcherIsUsed (): void
26+ {
27+ expect (1 )->toHaveFoo (1 );
28+ $ this ->addToAssertionCount (1 ); // No exception thrown
29+ }
30+
31+ #[\PHPUnit \Framework \Attributes \DataProvider('incorrectExpectations ' )]
3032 public function testItThrowsWhenExpectationIsNotMet ($ expectation ): void
3133 {
3234 $ this ->expectException (PhpSpecException::class);
@@ -58,7 +60,7 @@ public function testItCanBeDeactivated(): void
5860 /**
5961 * Cases that should evaluate without an exception
6062 */
61- public function correctExpectations (): array
63+ public static function correctExpectations (): array
6264 {
6365 return [
6466 [ function () { expect (5 )->toBe (5 ); } ],
@@ -80,16 +82,13 @@ public function correctExpectations(): array
8082 [ function () { expect ((new Foo ()))->toTrigger (E_USER_DEPRECATED )->duringTriggerError (); } ],
8183 [ function () { expect (1.444447777 )->toBeApproximately (1.444447777 , 1.0e-9 ); } ],
8284 [ function () { expect ((new Foo ())->getIterator ())->toIterateAs (new \ArrayIterator (['Foo ' , 'Bar ' ])); } ],
83- // Custom matchers
84- [ function () { expect (['foo ' => 'bar ' ])->toHaveKey ('foo ' ); } ],
85- [ function () { expect (1 )->toHaveFoo (1 ); } ],
8685 ];
8786 }
8887
8988 /**
9089 * Cases that should throw an exception when evaluated
9190 */
92- public function incorrectExpectations (): array
91+ public static function incorrectExpectations (): array
9392 {
9493 return [
9594 [ function () { expect (6 )->toBe (5 ); } ],
@@ -121,7 +120,6 @@ public function incorrectExpectations(): array
121120 public function getMatchers (): array
122121 {
123122 return [
124- 'haveKey ' => function ($ subject , $ key ) { return array_key_exists ($ key , $ subject ); },
125123 'haveFoo ' => new FooMatcher (),
126124 'haveBar ' => $ this ->addInvalidMatcher ? new \stdClass () : new FooMatcher (),
127125 ];
0 commit comments