Skip to content

Commit

Permalink
fix: missing != and !== on new toUseStrictEquality arch expecta…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
nunomaduro committed Sep 23, 2024
1 parent a55da85 commit 432ff22
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private function getExpectationClosure(string $name): Closure
if (self::hasExtend($name)) {
$extend = self::$extends[$name]->bindTo($this, Expectation::class);

if ($extend != false) {
if ($extend != false) { // @pest-arch-ignore-line
return $extend;
}
}
Expand Down Expand Up @@ -522,9 +522,9 @@ public function toUseStrictEquality(): ArchExpectation
{
return Targeted::make(
$this,
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' == '), // @pest-arch-ignore-line
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' == ') && ! str_contains((string) file_get_contents($object->path), ' != '),
'to use strict equality',
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' == ')),
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' == ') || str_contains($line, ' != ')),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Expectations/OppositeExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ public function toUseStrictEquality(): ArchExpectation
{
return Targeted::make(
$this->original,
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' === '),
fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' === ') && ! str_contains((string) file_get_contents($object->path), ' !== '),
'to use strict equality',
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' === ')),
FileLineFinder::where(fn (string $line): bool => str_contains($line, ' === ') || str_contains($line, ' !== ')),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Logging/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getTestSuiteName(TestSuite $testSuite): string
{
if ($testSuite instanceof TestSuiteForTestMethodWithDataProvider) {
$firstTest = $this->getFirstTest($testSuite);
if ($firstTest != null) {
if ($firstTest instanceof \PHPUnit\Event\Code\TestMethod) {
return $this->getTestMethodNameWithoutDatasetSuffix($firstTest);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function bind(?BaseClosure $closure, ?object $newThis, object|stri

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

if ($closure === null) {
if (! $closure instanceof \Closure) {
throw ShouldNotHappen::fromMessage('Could not bind closure.');
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public function test(): void
if ($a == $b) {
echo 'Equal';
}

if ($a != $b) {
echo 'Equal';
}
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/Arch/ToUseStrictEquality/StrictEquality.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public function test(): void
if ($a === $b) {
echo 'Equal';
}

if ($a !== $b) {
echo 'Equal';
}
}
}

0 comments on commit 432ff22

Please sign in to comment.