11<?php
22
3- include __DIR__ . '/Foo.php ' ;
4- include __DIR__ . '/FooMatcher.php ' ;
3+ namespace FriendsOfPhpSpec \PhpSpec \Tests ;
54
65use PhpSpec \Exception \Exception as PhpSpecException ;
76use PhpSpec \Matcher \MatchersProvider ;
87use PHPUnit \Framework \TestCase ;
98
109class ExpectTest extends TestCase implements MatchersProvider
1110{
12- private $ addInvalidMatcher ;
11+ private bool $ addInvalidMatcher = false ;
1312
14- function setUp (): void
13+ protected function setUp (): void
1514 {
1615 $ this ->addInvalidMatcher = false ;
1716 }
1817
1918 /**
20- * @test
2119 * @dataProvider correctExpectations
2220 */
23- function it_does_not_throw_when_expectation_is_met ($ expectation )
21+ public function testItDoesNotThrowWhenExpectationIsMet ($ expectation ): void
2422 {
2523 $ expectation ();
2624 $ this ->addToAssertionCount (1 ); // No exception thrown
2725 }
2826
2927 /**
30- * @test
3128 * @dataProvider incorrectExpectations
3229 */
33- function it_throws_when_expectation_is_not_met ($ expectation )
30+ public function testItThrowsWhenExpectationIsNotMet ($ expectation ): void
3431 {
3532 $ this ->expectException (PhpSpecException::class);
3633 $ expectation ();
3734 }
3835
39- /**
40- * @test
41- */
42- function it_throws_when_custom_matcher_does_not_implement_correct_interface ()
36+ public function testItThrowsWhenCustomMatcherDoesNotImplementCorrectInterface (): void
4337 {
44- $ this ->expectException (RuntimeException::class);
38+ $ this ->expectException (\ RuntimeException::class);
4539 $ this ->addInvalidMatcher = true ;
4640 expect (1 )->toBe (1 );
4741 }
4842
49- /**
50- * @test
51- */
52- function it_can_be_deactivated ()
43+ public function testItCanBeDeactivated (): void
5344 {
5445 // Active by default
5546 $ this ->assertTrue (e710d4e7_friends_of_phpspec_use_expect ());
@@ -67,13 +58,13 @@ function it_can_be_deactivated()
6758 /**
6859 * Cases that should evaluate without an exception
6960 */
70- function correctExpectations ()
61+ public function correctExpectations (): array
7162 {
7263 return [
7364 [ function () { expect (5 )->toBe (5 ); } ],
7465 [ function () { expect (5 )->notToBe (1 ); } ],
7566 [ function () { expect (5 )->toBeLike ('5 ' ); } ],
76- [ function () { expect ((new Foo ()))->toHaveType (' Foo ' ); } ],
67+ [ function () { expect ((new Foo ()))->toHaveType (Foo::class ); } ],
7768 [ function () { expect ((new Foo ()))->toHaveCount (1 ); } ],
7869 [ function () { expect ((new Foo ()))->toBeFoo (); } ],
7970 [ function () { expect ((new Foo ())->getArray ())->toBeArray (); } ],
@@ -98,7 +89,7 @@ function correctExpectations()
9889 /**
9990 * Cases that should throw an exception when evaluated
10091 */
101- function incorrectExpectations ()
92+ public function incorrectExpectations (): array
10293 {
10394 return [
10495 [ function () { expect (6 )->toBe (5 ); } ],
@@ -132,7 +123,7 @@ public function getMatchers(): array
132123 return [
133124 'haveKey ' => function ($ subject , $ key ) { return array_key_exists ($ key , $ subject ); },
134125 'haveFoo ' => new FooMatcher (),
135- 'haveBar ' => $ this ->addInvalidMatcher ? new stdClass () : new FooMatcher (),
126+ 'haveBar ' => $ this ->addInvalidMatcher ? new \ stdClass () : new FooMatcher (),
136127 ];
137128 }
138129}
0 commit comments