Skip to content
Closed
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"require-dev": {
"phpunit/phpunit": "11.*",
"laravel/pint": "1.*",
"phpstan/phpstan": "1.*"
"phpstan/phpstan": "2.*"
}
}
35 changes: 18 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ parameters:
level: 5
paths:
- src
- src/PHPStan
- tests
services:
-
class: Utopia\PHPStan\DisallowAssertEqualsExtension
tags:
- phpstan.restrictedMethodUsageExtension
30 changes: 30 additions & 0 deletions src/PHPStan/DisallowAssertEqualsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Utopia\PHPStan;

use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Rules\RestrictedUsage\RestrictedMethodUsageExtension;
use PHPStan\Rules\RestrictedUsage\RestrictedUsage;

class DisallowAssertEqualsExtension implements RestrictedMethodUsageExtension
{
public function isRestrictedMethodUsage(
ExtendedMethodReflection $methodReflection,
Scope $scope,
): ?RestrictedUsage {
if ($methodReflection->getName() !== 'assertEquals') {
return null;
}

$declaringClass = $methodReflection->getDeclaringClass();
if ($declaringClass->getName() !== 'PHPUnit\Framework\Assert') {
return null;
}

return RestrictedUsage::create(
errorMessage: 'Use assertSame() instead of assertEquals()',
identifier: 'method.disallowedAssertEquals',
);
}
}
30 changes: 30 additions & 0 deletions src/phpstan/DisallowAssertEqualsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Utopia\PHPStan;

use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Rules\RestrictedUsage\RestrictedMethodUsageExtension;
use PHPStan\Rules\RestrictedUsage\RestrictedUsage;

class DisallowAssertEqualsExtension implements RestrictedMethodUsageExtension
{
public function isRestrictedMethodUsage(
ExtendedMethodReflection $methodReflection,
Scope $scope,
): ?RestrictedUsage {
if ($methodReflection->getName() !== 'assertEquals') {
return null;
}

$declaringClass = $methodReflection->getDeclaringClass();
if ($declaringClass->getName() !== 'PHPUnit\Framework\Assert') {
return null;
}

return RestrictedUsage::create(
errorMessage: 'Use assertSame() instead of assertEquals()',
identifier: 'method.disallowedAssertEquals',
);
}
}
10 changes: 5 additions & 5 deletions tests/Validator/ArrayListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public function testDescription(): void
{
$arrayList = new ArrayList(new Integer());
$this->assertFalse($arrayList->isValid(['text']));
$this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());
$this->assertSame('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());

$arrayList = new ArrayList(new Integer(), 3);
$this->assertFalse($arrayList->isValid(['a', 'b', 'c', 'd']));
$this->assertEquals('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription());
$this->assertSame('Value must a valid array no longer than 3 items and Value must be a valid integer', $arrayList->getDescription());
}

public function testCanValidateTextValues(): void
Expand All @@ -26,7 +26,7 @@ public function testCanValidateTextValues(): void
$this->assertFalse($arrayList->isValid(['string', 'string', 3]));
$this->assertFalse($arrayList->isValid('string'));
$this->assertFalse($arrayList->isValid('string'));
$this->assertEquals(\Utopia\Validator::TYPE_STRING, $arrayList->getType());
$this->assertSame(\Utopia\Validator::TYPE_STRING, $arrayList->getType());
$this->assertInstanceOf(Text::class, $arrayList->getValidator());
}

Expand All @@ -36,7 +36,7 @@ public function testCanValidateNumericValues(): void
$this->assertTrue($arrayList->isValid([1, 2, 3]));
$this->assertFalse($arrayList->isValid(1));
$this->assertFalse($arrayList->isValid('string'));
$this->assertEquals(\Utopia\Validator::TYPE_MIXED, $arrayList->getType());
$this->assertSame(\Utopia\Validator::TYPE_MIXED, $arrayList->getType());
$this->assertInstanceOf(Numeric::class, $arrayList->getValidator());
}

Expand All @@ -46,7 +46,7 @@ public function testCanValidateNumericValuesWithBoundaries(): void
$this->assertTrue($arrayList->isValid([1]));
$this->assertTrue($arrayList->isValid([1, 2]));
$this->assertFalse($arrayList->isValid([1, 2, 3]));
$this->assertEquals($arrayList->getType(), \Utopia\Validator::TYPE_MIXED);
$this->assertSame($arrayList->getType(), \Utopia\Validator::TYPE_MIXED);
$this->assertInstanceOf(Numeric::class, $arrayList->getValidator());
}
}
2 changes: 1 addition & 1 deletion tests/Validator/AssocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testCanValidateAssocArray(): void
$this->assertTrue($this->assoc->isValid([]));
$this->assertTrue($this->assoc->isValid(['value' => str_repeat('-', 62000)]));
$this->assertTrue($this->assoc->isArray());
$this->assertEquals(\Utopia\Validator::TYPE_ARRAY, $this->assoc->getType());
$this->assertSame(\Utopia\Validator::TYPE_ARRAY, $this->assoc->getType());
}

public function testCantValidateSequentialArray(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Validator/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testCanValidateStrictly()
$this->assertFalse($boolean->isValid('string'));
$this->assertFalse($boolean->isValid(1.2));
$this->assertFalse($boolean->isArray());
$this->assertEquals($boolean->getType(), \Utopia\Validator::TYPE_BOOLEAN);
$this->assertSame($boolean->getType(), \Utopia\Validator::TYPE_BOOLEAN);
}

public function testCanValidateLoosely()
Expand All @@ -41,6 +41,6 @@ public function testCanValidateLoosely()
$this->assertFalse($boolean->isValid('string'));
$this->assertFalse($boolean->isValid(1.2));
$this->assertFalse($boolean->isArray());
$this->assertEquals(\Utopia\Validator::TYPE_BOOLEAN, $boolean->getType());
$this->assertSame(\Utopia\Validator::TYPE_BOOLEAN, $boolean->getType());
}
}
Loading