Skip to content

Commit 8dcc13f

Browse files
mhujerondrejmirtes
authored andcommitted
improve AssertSameDifferentTypesRule test coverage
1 parent 6501e8e commit 8dcc13f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

tests/Rules/PHPUnit/AssertSameDifferentTypesRuleTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@ public function testRule()
3535
'Call to assertSame() with different types array<int, string> and array<int, int> will always result in test failure.',
3636
14,
3737
],
38+
[
39+
'Call to assertSame() with different types string and int will always result in test failure.',
40+
16,
41+
],
42+
[
43+
'Call to assertSame() with different types string and int will always result in test failure.',
44+
17,
45+
],
46+
[
47+
'Call to assertSame() with different types string and int will always result in test failure.',
48+
18,
49+
],
3850
[
3951
'Call to assertSame() with different types array<string> and array<int> will always result in test failure.',
40-
35,
52+
39,
4153
],
4254
]);
4355
}

tests/Rules/PHPUnit/data/Foo.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Dummy;
4+
5+
class Foo
6+
{
7+
8+
public function assertSame(): string
9+
{
10+
return 'Hello World!';
11+
}
12+
13+
}

tests/Rules/PHPUnit/data/assert-same.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public function testObviouslyNotSameAssertSame()
1212
$this->assertSame(1, $this->returnsString());
1313
$this->assertSame('1', self::returnsInt());
1414
$this->assertSame(['a', 'b'], [1, 2]);
15+
16+
self::assertSame('1', 2); // test self
17+
static::assertSame('1', 2); // test static
18+
parent::assertSame('1', 2); // test parent
1519
}
1620

1721
private function returnsString(): string
@@ -46,6 +50,19 @@ public function testLogicallyCorrectAssertSame()
4650
$this->assertSame(1, self::returnsInt());
4751
$this->assertSame(['a'], ['a', 1]);
4852
$this->assertSame(['a', 2, 3.0], ['a', 1]);
53+
self::assertSame(1, 2); // test self
54+
static::assertSame(1, 2); // test static
55+
parent::assertSame(1, 2); // test parent
56+
}
57+
58+
public function testOther()
59+
{
60+
// assertEquals is not checked
61+
$this->assertEquals('1', 1);
62+
63+
// only calls on \PHPUnit\Framework\TestCase are analyzed
64+
$foo = new \Dummy\Foo();
65+
$foo->assertSame();
4966
}
5067

5168
}

0 commit comments

Comments
 (0)