Skip to content

Commit

Permalink
release: v3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Sep 23, 2024
1 parent f291cd1 commit a55da85
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/ArchPresets/Strict.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function execute(): void
fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toHaveProtectedMethods(),
fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toBeAbstract(),
fn (Expectation $namespace): ArchExpectation => $namespace->toUseStrictTypes(),
fn (Expectation $namespace): ArchExpectation => $namespace->toUseStrictEquality(),
fn (Expectation $namespace): ArchExpectation => $namespace->classes()->toBeFinal(),
);

Expand Down
15 changes: 14 additions & 1 deletion src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function sequence(mixed ...$callbacks): self
throw new BadMethodCallException('Expectation value is not iterable.');
}

if (count($callbacks) == 0) {
if ($callbacks === []) {
throw new InvalidArgumentException('No sequence expectations defined.');
}

Expand Down Expand Up @@ -515,6 +515,19 @@ public function toUseStrictTypes(): ArchExpectation
);
}

/**
* Asserts that the given expectation target uses strict equality.
*/
public function toUseStrictEquality(): ArchExpectation
{
return Targeted::make(
$this,
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' == '), // @pest-arch-ignore-line
'to use strict equality',
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' == ')),
);
}

/**
* Asserts that the given expectation target is final.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Expectations/OppositeExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ public function toUseStrictTypes(): ArchExpectation
);
}

/**
* Asserts that the given expectation target does not use the strict equality operator.
*/
public function toUseStrictEquality(): ArchExpectation
{
return Targeted::make(
$this->original,
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' === '),
'to use strict equality',
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' === ')),
);
}

/**
* Asserts that the given expectation target is not final.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function getTrimmedTestClassName(TestMethod $test): string
public function getTestSuiteLocation(TestSuite $testSuite): ?string
{
$firstTest = $this->getFirstTest($testSuite);
if ($firstTest == null) {
if (! $firstTest instanceof \PHPUnit\Event\Code\TestMethod) {
return null;
}
$path = $firstTest->testDox()->prettifiedClassName();
Expand Down
2 changes: 1 addition & 1 deletion src/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

function version(): string
{
return '3.1.0';
return '3.2.0';
}

function testDirectory(string $file = ''): string
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ final class Closure
*/
public static function bind(?BaseClosure $closure, ?object $newThis, object|string|null $newScope = 'static'): BaseClosure
{
if ($closure == null) {
if (! $closure instanceof \Closure) {
throw ShouldNotHappen::fromMessage('Could not bind null closure.');
}

$closure = BaseClosure::bind($closure, $newThis, $newScope);

if ($closure == false) {
if ($closure === null) {
throw ShouldNotHappen::fromMessage('Could not bind closure.');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Pest Testing Framework 3.1.0.
Pest Testing Framework 3.2.0.

USAGE: pest <file> [options]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

Pest Testing Framework 3.1.0.
Pest Testing Framework 3.2.0.

8 changes: 7 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,12 @@
✓ it can handle a non-defined exception
✓ it can handle a class not found Error

PASS Tests\Features\Expect\toUseStrictEquality
✓ missing strict equality
✓ has strict equality
✓ opposite missing strict equality
✓ opposite has strict equality

PASS Tests\Features\Expect\toUseTrait
✓ pass
✓ failures
Expand Down Expand Up @@ -1574,4 +1580,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1089 passed (2637 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1093 passed (2644 assertions)
21 changes: 21 additions & 0 deletions tests/Features/Expect/toUseStrictEquality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Pest\Arch\Exceptions\ArchExpectationFailedException;

test('missing strict equality')
->throws(ArchExpectationFailedException::class)
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality')
->toUseStrictEquality();

test('has strict equality')
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality')
->toUseStrictEquality();

test('opposite missing strict equality')
->throws(ArchExpectationFailedException::class)
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality')
->not->toUseStrictEquality();

test('opposite has strict equality')
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality')
->not->toUseStrictEquality();
18 changes: 18 additions & 0 deletions tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\ToUseStrictEquality;

class NotStrictEquality
{
public function test(): void
{
$a = 1;
$b = '1';

if ($a == $b) {
echo 'Equal';
}
}
}
18 changes: 18 additions & 0 deletions tests/Fixtures/Arch/ToUseStrictEquality/StrictEquality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\ToUseStrictEquality;

class StrictEquality
{
public function test(): void
{
$a = 1;
$b = '1';

if ($a === $b) {
echo 'Equal';
}
}
}
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1079 passed (2613 assertions)')
->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1083 passed (2620 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();

Expand Down

0 comments on commit a55da85

Please sign in to comment.