Skip to content

Commit

Permalink
Mutate remaining data providers to static ones
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Sep 20, 2024
1 parent 03e87f2 commit e4171a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Tests/LocalesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class LocalesTest extends ResourceBundleTestCase
{
public function testGetLocales()
{
$this->assertSame($this->getLocales(), Locales::getLocales());
$this->assertSame(static::getLocales(), Locales::getLocales());
}

public function testGetAliases()
{
$this->assertSame($this->getLocaleAliases(), Locales::getAliases());
$this->assertSame(static::getLocaleAliases(), Locales::getAliases());
}

/**
Expand All @@ -41,7 +41,7 @@ public function testGetNames($displayLocale)
// We can't assert on exact list of locale, as there's too many variations.
// The best we can do is to make sure getNames() returns a subset of what getLocales() returns.
$this->assertNotEmpty($locales);
$this->assertEmpty(array_diff($locales, $this->getLocales()));
$this->assertEmpty(array_diff($locales, static::getLocales()));
}

public function testGetNamesDefaultLocale()
Expand Down
26 changes: 9 additions & 17 deletions Tests/ResourceBundleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,45 +758,37 @@ protected function tearDown(): void
\Locale::setDefault($this->defaultLocale);
}

public function provideLocales()
public static function provideLocales()
{
return array_map(
function ($locale) { return [$locale]; },
$this->getLocales()
static::getLocales()
);
}

public function provideLocaleAliases()
public static function provideLocaleAliases()
{
return array_map(
function ($alias, $ofLocale) { return [$alias, $ofLocale]; },
array_keys($this->getLocaleAliases()),
$this->getLocaleAliases()
array_keys(static::getLocaleAliases()),
static::getLocaleAliases()
);
}

public function provideRootLocales()
{
return array_map(
function ($locale) { return [$locale]; },
$this->getRootLocales()
);
}

protected function getLocales()
protected static function getLocales()
{
return self::LOCALES;
}

protected function getLocaleAliases()
protected static function getLocaleAliases()
{
return self::LOCALE_ALIASES;
}

protected function getRootLocales()
protected static function getRootLocales()
{
if (null === self::$rootLocales) {
self::$rootLocales = array_filter($this->getLocales(), function ($locale) {
self::$rootLocales = array_filter(static::getLocales(), function ($locale) {
// no locales for which fallback is possible (e.g "en_GB")
return !str_contains($locale, '_');
});
Expand Down

0 comments on commit e4171a0

Please sign in to comment.