Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
fail-fast: false
matrix:
operating-system: ['ubuntu-latest']
php-version: ['7.4', '8.0', '8.1', '8.2']
php-version: ['8.1', '8.2', '8.3', '8.4']
composer-version: ['composer:v2']

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
}
},
"require": {
"php": ">=7.4",
"phpspec/phpspec": "^6.0 || ^7.0"
"php": ">=8.1",
"phpspec/phpspec": "^6.0 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^10.0",
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
"squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Subject extends BaseSubject
{
public function __call(string $method, array $arguments = [])
public function __call(string $method, array $arguments = []): mixed
{
if (preg_match('/^(to|notTo)(.+)$/', $method, $matches)) {
$method = 'should' . $matches[2];
Expand Down
22 changes: 10 additions & 12 deletions tests/ExpectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ protected function setUp(): void
$this->addInvalidMatcher = false;
}

/**
* @dataProvider correctExpectations
*/
#[\PHPUnit\Framework\Attributes\DataProvider('correctExpectations')]
public function testItDoesNotThrowWhenExpectationIsMet($expectation): void
{
$expectation();
$this->addToAssertionCount(1); // No exception thrown
}

/**
* @dataProvider incorrectExpectations
*/
public function testItDoesNotThrowWhenExpectationIsMetAndACustomMatcherIsUsed(): void
{
expect(1)->toHaveFoo(1);
$this->addToAssertionCount(1); // No exception thrown
}

#[\PHPUnit\Framework\Attributes\DataProvider('incorrectExpectations')]
public function testItThrowsWhenExpectationIsNotMet($expectation): void
{
$this->expectException(PhpSpecException::class);
Expand Down Expand Up @@ -58,7 +60,7 @@ public function testItCanBeDeactivated(): void
/**
* Cases that should evaluate without an exception
*/
public function correctExpectations(): array
public static function correctExpectations(): array
{
return [
[ function () { expect(5)->toBe(5); } ],
Expand All @@ -80,16 +82,13 @@ public function correctExpectations(): array
[ function () { expect((new Foo()))->toTrigger(E_USER_DEPRECATED)->duringTriggerError(); } ],
[ function () { expect(1.444447777)->toBeApproximately(1.444447777, 1.0e-9); } ],
[ function () { expect((new Foo())->getIterator())->toIterateAs(new \ArrayIterator(['Foo', 'Bar'])); } ],
// Custom matchers
[ function () { expect(['foo' => 'bar'])->toHaveKey('foo'); } ],
[ function () { expect(1)->toHaveFoo(1); } ],
];
}

/**
* Cases that should throw an exception when evaluated
*/
public function incorrectExpectations(): array
public static function incorrectExpectations(): array
{
return [
[ function () { expect(6)->toBe(5); } ],
Expand Down Expand Up @@ -121,7 +120,6 @@ public function incorrectExpectations(): array
public function getMatchers(): array
{
return [
'haveKey' => function ($subject, $key) { return array_key_exists($key, $subject); },
'haveFoo' => new FooMatcher(),
'haveBar' => $this->addInvalidMatcher ? new \stdClass() : new FooMatcher(),
];
Expand Down
2 changes: 1 addition & 1 deletion tests/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function isFoo()
{
return true;
}
public function count()
public function count(): int
{
return 1;
}
Expand Down