Skip to content

Commit 9561796

Browse files
committed
Bump minimum PHP requirement to 7.4
Also improved tests.
1 parent 0d275a7 commit 9561796

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
"FriendsOfPhpSpec\\PhpSpec\\Expect\\": "src/"
1818
}
1919
},
20+
"autoload-dev": {
21+
"psr-4": {
22+
"FriendsOfPhpSpec\\PhpSpec\\Tests\\": "tests/"
23+
}
24+
},
2025
"require": {
21-
"php": ">=7.3",
26+
"php": ">=7.4",
2227
"phpspec/phpspec": "^6.0 || ^7.0"
2328
},
2429
"require-dev": {
25-
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
30+
"phpunit/phpunit": "^9.0 || ^10.0",
2631
"squizlabs/php_codesniffer": "^3.5"
2732
},
2833
"scripts": {

src/Subject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Subject extends BaseSubject
88
{
9-
public function __call(string $method, array $arguments = array())
9+
public function __call(string $method, array $arguments = [])
1010
{
1111
if (preg_match('/^(to|notTo)(.+)$/', $method, $matches)) {
1212
$method = 'should' . $matches[2];

src/Wrapper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
class Wrapper extends BaseWrapper
1919
{
20-
private $matchers;
21-
private $presenter;
22-
private $dispatcher;
23-
private $example;
24-
private $accessInspector;
20+
private MatcherManager $matchers;
21+
private Presenter $presenter;
22+
private EventDispatcherInterface $dispatcher;
23+
private ExampleNode $example;
24+
private AccessInspector $accessInspector;
2525

2626
public function __construct(
2727
MatcherManager $matchers,

tests/ExpectTest.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,46 @@
11
<?php
22

3-
include __DIR__ . '/Foo.php';
4-
include __DIR__ . '/FooMatcher.php';
3+
namespace FriendsOfPhpSpec\PhpSpec\Tests;
54

65
use PhpSpec\Exception\Exception as PhpSpecException;
76
use PhpSpec\Matcher\MatchersProvider;
87
use PHPUnit\Framework\TestCase;
98

109
class 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
}

tests/Foo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3+
namespace FriendsOfPhpSpec\PhpSpec\Tests;
4+
35
/**
46
* Test fixture used in ExpectTest
57
*/
6-
class Foo implements Countable
8+
class Foo implements \Countable
79
{
810
function isFoo()
911
{
@@ -23,7 +25,7 @@ public function getArray()
2325
}
2426
public function throwException()
2527
{
26-
throw new InvalidArgumentException;
28+
throw new \InvalidArgumentException;
2729
}
2830
public function triggerError()
2931
{

tests/FooMatcher.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace FriendsOfPhpSpec\PhpSpec\Tests;
4+
35
use PhpSpec\Exception\Example\FailureException;
46
use PhpSpec\Matcher\BasicMatcher;
57

0 commit comments

Comments
 (0)