Skip to content

Commit

Permalink
Prefer PHPUnit self calls instead of $this
Browse files Browse the repository at this point in the history
Done using PreferPHPUnitSelfCallRector.

Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Nov 21, 2024
1 parent 8f54159 commit 5878e38
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 358 deletions.
97 changes: 1 addition & 96 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -115,46 +115,11 @@ parameters:
count: 1
path: src/Translator.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#"
count: 1
path: tests/Cache/ApcuCacheFactoryTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)\\.$#"
count: 1
path: tests/Cache/ApcuCacheFactoryTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 2
path: tests/Cache/ApcuCacheFactoryTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
count: 1
path: tests/Cache/ApcuCacheFactoryTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 2
path: tests/Cache/ApcuCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#"
count: 4
path: tests/Cache/ApcuCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 11
path: tests/Cache/ApcuCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#"
count: 1
path: tests/Cache/ApcuCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
count: 1
Expand All @@ -166,33 +131,8 @@ parameters:
path: tests/Cache/ApcuDisabledTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 1
path: tests/Cache/InMemoryCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#"
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with array\\<array\\> and array\\<string\\> will always evaluate to false\\.$#"
count: 1
path: tests/Cache/InMemoryCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 4
path: tests/Cache/InMemoryCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#"
count: 1
path: tests/Cache/InMemoryCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 9
path: tests/FunctionsTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 13
path: tests/LoaderTest.php

-
Expand Down Expand Up @@ -225,11 +165,6 @@ parameters:
count: 1
path: tests/LoaderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 16
path: tests/MoFilesTest.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\MoFilesTest\\:\\:getFiles\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -250,11 +185,6 @@ parameters:
count: 1
path: tests/MoFilesTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 3
path: tests/PluralFormulaTest.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralFormulaTest\\:\\:pluralCounts\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -270,11 +200,6 @@ parameters:
count: 1
path: tests/PluralFormulaTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 3
path: tests/PluralTest.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralTest\\:\\:dataProviderPluralForms\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -285,23 +210,3 @@ parameters:
count: 1
path: tests/PluralTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#"
count: 2
path: tests/StringReaderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 2
path: tests/StringReaderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 6
path: tests/TranslatorTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 6
path: tests/TranslatorTest.php

8 changes: 4 additions & 4 deletions tests/Cache/ApcuCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testGetInstanceReturnApcuCache(): void
{
$factory = new ApcuCacheFactory();
$instance = $factory->getInstance(new MoParser(null), 'foo', 'bar');
$this->assertInstanceOf(ApcuCache::class, $instance);
self::assertInstanceOf(ApcuCache::class, $instance);
}

public function testConstructorSetsTtl(): void
Expand All @@ -59,7 +59,7 @@ public function testConstructorSetsTtl(): void
sleep($ttl * 2);

apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success);
$this->assertFalse($success);
self::assertFalse($success);
}

public function testConstructorSetsReloadOnMiss(): void
Expand All @@ -76,7 +76,7 @@ public function testConstructorSetsReloadOnMiss(): void

apcu_delete('mo_' . $locale . '.' . $domain . '.' . $msgid);
$actual = $instance->get($msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testConstructorSetsPrefix(): void
Expand All @@ -93,6 +93,6 @@ public function testConstructorSetsPrefix(): void
$factory->getInstance($parser, $locale, $domain);

$actual = apcu_fetch($prefix . $locale . '.' . $domain . '.' . $msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}
}
36 changes: 18 additions & 18 deletions tests/Cache/ApcuCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testConstructorLoadsCache(): void
new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain);

$actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testConstructorSetsTtl(): void
Expand All @@ -67,9 +67,9 @@ public function testConstructorSetsTtl(): void
sleep($ttl * 2);

apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success);
$this->assertFalse($success);
self::assertFalse($success);
apcu_fetch('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY, $success);
$this->assertFalse($success);
self::assertFalse($success);
}

public function testConstructorSetsReloadOnMiss(): void
Expand All @@ -91,7 +91,7 @@ public function testConstructorSetsReloadOnMiss(): void

apcu_delete($prefix . $locale . '.' . $domain . '.' . $msgid);
$actual = $cache->get($msgid);
$this->assertEquals($expected, $actual);
self::assertSame($expected, $actual);
}

public function testConstructorSetsPrefix(): void
Expand All @@ -105,7 +105,7 @@ public function testConstructorSetsPrefix(): void
new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain, 0, true, $prefix);

$actual = apcu_fetch($prefix . $locale . '.' . $domain . '.' . $msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testEnsureTranslationsLoadedSetsLoadedKey(): void
Expand All @@ -117,7 +117,7 @@ public function testEnsureTranslationsLoadedSetsLoadedKey(): void
new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain);

$actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testEnsureTranslationsLoadedHonorsLock(): void
Expand All @@ -136,9 +136,9 @@ public function testEnsureTranslationsLoadedHonorsLock(): void
new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain);

$actual = apcu_fetch($lock);
$this->assertSame(1, $actual);
self::assertSame(1, $actual);
apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success);
$this->assertFalse($success);
self::assertFalse($success);
}

public function testGetReturnsMsgstr(): void
Expand All @@ -149,7 +149,7 @@ public function testGetReturnsMsgstr(): void
$cache = new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), 'foo', 'bar');

$actual = $cache->get($msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testGetReturnsMsgidForCacheMiss(): void
Expand All @@ -159,7 +159,7 @@ public function testGetReturnsMsgidForCacheMiss(): void
$cache = new ApcuCache(new MoParser(null), 'foo', 'bar');

$actual = $cache->get($expected);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testStoresMsgidOnCacheMiss(): void
Expand All @@ -172,7 +172,7 @@ public function testStoresMsgidOnCacheMiss(): void
$cache->get($expected);

$actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $expected);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testGetReloadsOnCacheMiss(): void
Expand All @@ -186,7 +186,7 @@ public function testGetReloadsOnCacheMiss(): void

apcu_delete('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY);
$actual = $cache->get($msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testReloadOnMissHonorsLock(): void
Expand All @@ -209,7 +209,7 @@ public function testReloadOnMissHonorsLock(): void
});
$actual = $method->invoke($cache, $msgid);

$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testSetSetsMsgstr(): void
Expand All @@ -221,21 +221,21 @@ public function testSetSetsMsgstr(): void
$cache->set($msgid, $expected);

$actual = $cache->get($msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testHasReturnsFalse(): void
{
$cache = new ApcuCache(new MoParser(null), 'foo', 'bar');
$actual = $cache->has('Column');
$this->assertFalse($actual);
self::assertFalse($actual);
}

public function testHasReturnsTrue(): void
{
$cache = new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), 'foo', 'bar');
$actual = $cache->has('Column');
$this->assertTrue($actual);
self::assertTrue($actual);
}

public function testSetAllSetsTranslations(): void
Expand All @@ -250,7 +250,7 @@ public function testSetAllSetsTranslations(): void

foreach ($translations as $msgid => $expected) {
$actual = $cache->get($msgid);
$this->assertEquals($expected, $actual);
self::assertSame($expected, $actual);
}
}

Expand All @@ -265,6 +265,6 @@ public function testCacheStoresPluralForms(): void

$msgstr = $cache->get($msgid);
$actual = explode(chr(0), $msgstr);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}
}
14 changes: 7 additions & 7 deletions tests/Cache/InMemoryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function testConstructorParsesCache(): void
$parser = new MoParser(__DIR__ . '/../data/little.mo');
$cache = new InMemoryCache($parser);
$actual = $cache->get('Column');
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testGetReturnsMsgidForCacheMiss(): void
{
$expected = 'Column';
$cache = new InMemoryCache(new MoParser(null));
$actual = $cache->get($expected);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testSetSetsMsgstr(): void
Expand All @@ -37,21 +37,21 @@ public function testSetSetsMsgstr(): void
$cache = new InMemoryCache(new MoParser(null));
$cache->set($msgid, $expected);
$actual = $cache->get($msgid);
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}

public function testHasReturnsFalse(): void
{
$cache = new InMemoryCache(new MoParser(null));
$actual = $cache->has('Column');
$this->assertFalse($actual);
self::assertFalse($actual);
}

public function testHasReturnsTrue(): void
{
$cache = new InMemoryCache(new MoParser(__DIR__ . '/../data/little.mo'));
$actual = $cache->has('Column');
$this->assertTrue($actual);
self::assertTrue($actual);
}

public function testSetAllSetsTranslations(): void
Expand All @@ -64,7 +64,7 @@ public function testSetAllSetsTranslations(): void
$cache->setAll($translations);
foreach ($translations as $msgid => $expected) {
$actual = $cache->get($msgid);
$this->assertEquals($expected, $actual);
self::assertSame($expected, $actual);
}
}

Expand All @@ -77,6 +77,6 @@ public function testGetAllReturnsTranslations(): void
$cache = new InMemoryCache(new MoParser(null));
$cache->setAll($expected);
$actual = $cache->getAll();
$this->assertSame($expected, $actual);
self::assertSame($expected, $actual);
}
}
Loading

0 comments on commit 5878e38

Please sign in to comment.