Skip to content

Commit c12236c

Browse files
committed
tests + rename folder
1 parent d9860ab commit c12236c

21 files changed

Lines changed: 208 additions & 207 deletions

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
level: 5
33
paths:
44
- src
5+
- src/PHPStan
56
- tests
67
services:
78
-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Utopia\PHPStan;
4+
5+
use PHPStan\Analyser\Scope;
6+
use PHPStan\Reflection\ExtendedMethodReflection;
7+
use PHPStan\Rules\RestrictedUsage\RestrictedMethodUsageExtension;
8+
use PHPStan\Rules\RestrictedUsage\RestrictedUsage;
9+
10+
class DisallowAssertEqualsExtension implements RestrictedMethodUsageExtension
11+
{
12+
public function isRestrictedMethodUsage(
13+
ExtendedMethodReflection $methodReflection,
14+
Scope $scope,
15+
): ?RestrictedUsage {
16+
if ($methodReflection->getName() !== 'assertEquals') {
17+
return null;
18+
}
19+
20+
$declaringClass = $methodReflection->getDeclaringClass();
21+
if ($declaringClass->getName() !== 'PHPUnit\Framework\Assert') {
22+
return null;
23+
}
24+
25+
return RestrictedUsage::create(
26+
errorMessage: 'Use assertSame() instead of assertEquals()',
27+
identifier: 'method.disallowedAssertEquals',
28+
);
29+
}
30+
}

src/phpstan/DisallowAssertEqualsExtension.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/Validator/ArrayListTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public function testDescription(): void
1010
{
1111
$arrayList = new ArrayList(new Integer());
1212
$this->assertFalse($arrayList->isValid(['text']));
13-
$this->assertEquals('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());
13+
$this->assertSame('Value must a valid array and Value must be a valid integer', $arrayList->getDescription());
1414

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

2020
public function testCanValidateTextValues(): void
@@ -26,7 +26,7 @@ public function testCanValidateTextValues(): void
2626
$this->assertFalse($arrayList->isValid(['string', 'string', 3]));
2727
$this->assertFalse($arrayList->isValid('string'));
2828
$this->assertFalse($arrayList->isValid('string'));
29-
$this->assertEquals(\Utopia\Validator::TYPE_STRING, $arrayList->getType());
29+
$this->assertSame(\Utopia\Validator::TYPE_STRING, $arrayList->getType());
3030
$this->assertInstanceOf(Text::class, $arrayList->getValidator());
3131
}
3232

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

@@ -46,7 +46,7 @@ public function testCanValidateNumericValuesWithBoundaries(): void
4646
$this->assertTrue($arrayList->isValid([1]));
4747
$this->assertTrue($arrayList->isValid([1, 2]));
4848
$this->assertFalse($arrayList->isValid([1, 2, 3]));
49-
$this->assertEquals($arrayList->getType(), \Utopia\Validator::TYPE_MIXED);
49+
$this->assertSame($arrayList->getType(), \Utopia\Validator::TYPE_MIXED);
5050
$this->assertInstanceOf(Numeric::class, $arrayList->getValidator());
5151
}
5252
}

tests/Validator/AssocTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testCanValidateAssocArray(): void
2525
$this->assertTrue($this->assoc->isValid([]));
2626
$this->assertTrue($this->assoc->isValid(['value' => str_repeat('-', 62000)]));
2727
$this->assertTrue($this->assoc->isArray());
28-
$this->assertEquals(\Utopia\Validator::TYPE_ARRAY, $this->assoc->getType());
28+
$this->assertSame(\Utopia\Validator::TYPE_ARRAY, $this->assoc->getType());
2929
}
3030

3131
public function testCantValidateSequentialArray(): void

tests/Validator/BooleanTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testCanValidateStrictly()
2222
$this->assertFalse($boolean->isValid('string'));
2323
$this->assertFalse($boolean->isValid(1.2));
2424
$this->assertFalse($boolean->isArray());
25-
$this->assertEquals($boolean->getType(), \Utopia\Validator::TYPE_BOOLEAN);
25+
$this->assertSame($boolean->getType(), \Utopia\Validator::TYPE_BOOLEAN);
2626
}
2727

2828
public function testCanValidateLoosely()
@@ -41,6 +41,6 @@ public function testCanValidateLoosely()
4141
$this->assertFalse($boolean->isValid('string'));
4242
$this->assertFalse($boolean->isValid(1.2));
4343
$this->assertFalse($boolean->isArray());
44-
$this->assertEquals(\Utopia\Validator::TYPE_BOOLEAN, $boolean->getType());
44+
$this->assertSame(\Utopia\Validator::TYPE_BOOLEAN, $boolean->getType());
4545
}
4646
}

0 commit comments

Comments
 (0)