Skip to content

Commit

Permalink
Merge pull request #6081 from getkirby/refactor/phpunit-static-providers
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative authored Dec 23, 2023
2 parents 5ea1dbe + f5cbb1e commit aad45f8
Show file tree
Hide file tree
Showing 85 changed files with 245 additions and 277 deletions.
2 changes: 1 addition & 1 deletion tests/Cms/App/AppLanguagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testLanguageCode()
$this->assertNull($app->languageCode('fr'));
}

public function detectedLanguageProvider(): array
public static function detectedLanguageProvider(): array
{
return [
['en', 'en'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/App/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ function ($event) use ($self, &$count) {
$this->assertSame(143, $count);
}

public function urlProvider()
public static function urlProvider(): array
{
return [
['http://getkirby.com', 'http://getkirby.com'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Facades/VTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUp(): void
]);
}

public function messageInput()
public static function messageInput(): array
{
return [
['accepted', ['test'], 'Please confirm'],
Expand Down
4 changes: 2 additions & 2 deletions tests/Cms/Files/FileModificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function testBw()
$file->bw();
}

public function cropOptions()
public static function cropOptionsProvider(): array
{
$field = new Field(null, 'crop', 'top left');

Expand Down Expand Up @@ -275,7 +275,7 @@ public function cropOptions()
}

/**
* @dataProvider cropOptions
* @dataProvider cropOptionsProvider
*/
public function testCrop($args, $expected)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Files/FilePermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function setUp(): void
]);
}

public function actionProvider()
public static function actionProvider(): array
{
return [
['changeName'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Cms/Files/FileRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function testUpdateWithoutPermissions()
FileRules::update($file, []);
}

public function extensionProvider()
public static function extensionProvider(): array
{
return [
['jpg', true],
Expand Down Expand Up @@ -512,7 +512,7 @@ public function testValidExtension($extension, $expected, $message = null)
$this->assertTrue($result);
}

public function fileProvider()
public static function fileProvider(): array
{
return [
// valid examples
Expand Down Expand Up @@ -595,7 +595,7 @@ public function testValidFileSkipMime()
$this->assertTrue(FileRules::validFile($file));
}

public function filenameProvider()
public static function filenameProvider(): array
{
return [
['test.jpg', true],
Expand Down Expand Up @@ -625,7 +625,7 @@ public function testValidFilename($filename, $expected, $message = null)
$this->assertTrue($result);
}

public function mimeProvider()
public static function mimeProvider(): array
{
return [
['image/jpeg', true],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Files/FileSiblingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class FileSiblingsTest extends TestCase
{
protected function collection()
protected function collection(): array
{
return [
['filename' => 'cover.jpg', 'template' => 'cover'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Files/HasFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function tearDown(): void
Dir::remove($this->tmp);
}

public function fileProvider()
public static function fileProvider(): array
{
return [
['test.mp3', 'audio', true],
Expand Down
12 changes: 6 additions & 6 deletions tests/Cms/Ingredients/RootsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class RootsTest extends TestCase
{
protected function rootProvider(string $index): array
protected static function rootProvider(string $index): array
{
$kirby = realpath(__DIR__ . '/../../..');

Expand Down Expand Up @@ -37,9 +37,9 @@ protected function rootProvider(string $index): array
];
}

public function defaultRootProvider(): array
public static function defaultRootProvider(): array
{
return $this->rootProvider(realpath(__DIR__ . '/../../../../'));
return static::rootProvider(realpath(__DIR__ . '/../../../../'));
}

/**
Expand All @@ -52,9 +52,9 @@ public function testDefaultRoot($root, $method)
$this->assertSame($root, $roots->$method());
}

public function customIndexRootProvider(): array
public static function customIndexRootProvider(): array
{
return $this->rootProvider('/var/www/getkirby.com');
return static::rootProvider('/var/www/getkirby.com');
}

/**
Expand All @@ -73,7 +73,7 @@ public function testCustomIndexRoot($root, $method)
$this->assertSame($root, $roots->$method());
}

public function customRootProvider(): array
public static function customRootProvider(): array
{
$base = '/var/www/getkirby.com';
$public = $base . '/public';
Expand Down
6 changes: 3 additions & 3 deletions tests/Cms/Ingredients/UrlsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class UrlsTest extends TestCase
{
public function defaultUrlProvider(): array
public static function defaultUrlProvider(): array
{
return [
['/', 'index'],
Expand All @@ -29,7 +29,7 @@ public function testDefaulUrl($url, $method)
$this->assertSame($url, $urls->$method());
}

public function customBaseUrlProvider(): array
public static function customBaseUrlProvider(): array
{
return [
['https://getkirby.com', 'index'],
Expand All @@ -55,7 +55,7 @@ public function testWithCustomBaseUrl($url, $method)
$this->assertSame($url, $urls->$method());
}

public function customUrlProvider(): array
public static function customUrlProvider(): array
{
return [
['https://getkirby.com', 'index'],
Expand Down
6 changes: 3 additions & 3 deletions tests/Cms/Languages/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testConstructNoCode()
new Language([]);
}

public function baseUrlProvider()
public static function baseUrlProvider(): array
{
return [
['https://getkirby.com', null, 'https://getkirby.com'],
Expand Down Expand Up @@ -404,7 +404,7 @@ public function testName()
$this->assertSame('en', $language->name());
}

public function pathProvider()
public static function pathProvider(): array
{
return [
[null, 'en'],
Expand Down Expand Up @@ -432,7 +432,7 @@ public function testPath($input, $expected)
$this->assertSame($expected, $language->path());
}

public function patternProvider()
public static function patternProvider(): array
{
return [
[null, 'en/(:all?)'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Models/ModelWithContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function blueprint(): Blueprint

class ModelWithContentTest extends TestCase
{
public function modelsProvider(): array
public static function modelsProvider(): array
{
$app = new App([
'site' => [
Expand Down
4 changes: 2 additions & 2 deletions tests/Cms/Pages/PageActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function site()
return $this->app->site();
}

public function slugProvider()
public static function slugProvider(): array
{
return [
['test', 'test', true],
Expand Down Expand Up @@ -594,7 +594,7 @@ public function testUpdateHooks()
$this->assertSame(2, $calls);
}

public function languageProvider()
public static function languageProvider(): array
{
return [
[null],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PageBlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testExtendedOptions()
$this->assertEquals($expected, $blueprint->options()); // cannot use strict assertion (array order)
}

public function numProvider()
public static function numProvider(): array
{
return [
['default', 'default'],
Expand Down
4 changes: 2 additions & 2 deletions tests/Cms/Pages/PageCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function tearDown(): void
);
}

public function requestMethodProvider()
public static function requestMethodProvider(): array
{
return [
['GET', true],
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testRenderCacheDisabled()
$this->assertNotSame($html1, $html2);
}

public function dynamicProvider(): array
public static function dynamicProvider(): array
{
return [
['dynamic-auth', ['auth']],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PagePermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp(): void
]);
}

public function actionProvider()
public static function actionProvider(): array
{
return [
['changeSlug'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PageRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testChangeSlugReservedPath()
PageRules::changeSlug($app->page('a'), 'api');
}

public function statusActionProvider()
public static function statusActionProvider(): array
{
return [
['draft'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PageSiblingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function site($children = null)
return $this->app->site();
}

protected function collection()
protected function collection(): array
{
return [
['slug' => 'project-a'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PageSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function testPublishAlreadyPublished()
$this->assertSame('unlisted', $page->publish()->status());
}

public function sortProvider()
public static function sortProvider(): array
{
return [
['a', 2, 'b,a,c,d'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Pages/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public function testPreviewUrl()
$this->assertSame('/test', $page->previewUrl());
}

public function previewUrlProvider()
public static function previewUrlProvider(): array
{
return [
[null, '/test', false],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Permissions/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function tearDown(): void
Permissions::$extendedActions = [];
}

public function actionsProvider()
public static function actionsProvider(): array
{
return [
['files', 'changeName'],
Expand Down
6 changes: 3 additions & 3 deletions tests/Cms/Routes/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function testDisabledPanel()
$this->assertNull($app->call('panel/something'));
}

public function customRouteProvider()
public static function customRouteProvider(): array
{
return [
// home
Expand Down Expand Up @@ -439,7 +439,7 @@ public function testMultiLangHomeRouteWithoutLanguageCode()
$this->assertSame('en', I18n::locale());
}

public function multiDomainProvider()
public static function multiDomainProvider(): array
{
return [
['https://getkirby.fr', 'fr'],
Expand Down Expand Up @@ -533,7 +533,7 @@ public function testMultiLangHomeWithDifferentDomainsAndPath($domain, $language)
$this->assertSame($language, I18n::locale());
}

public function acceptedLanguageProvider()
public static function acceptedLanguageProvider(): array
{
return [
['fr,en;q=0.8', '/fr'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Sections/FieldsSectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUp(): void
]);
}

public function modelProvider()
public static function modelProvider(): array
{
return [
[
Expand Down
6 changes: 3 additions & 3 deletions tests/Cms/Sections/PagesSectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testParentWithInvalidOption()
]);
}

public function statusProvider()
public static function statusProvider(): array
{
return [
[null, 'all'],
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testStatus($input, $expected)
$this->assertSame($expected, $section->status());
}

public function addableStatusProvider()
public static function addableStatusProvider(): array
{
return [
['all', true],
Expand Down Expand Up @@ -353,7 +353,7 @@ public function testFlip()
$this->assertSame('C', $section->data()[2]['text']);
}

public function sortableStatusProvider()
public static function sortableStatusProvider(): array
{
return [
['all', true],
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Sections/StatsSectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function report()
return $this->reports()[0];
}

public function reports()
public function reports(): array
{
return [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/Cms/Site/SitePermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SitePermissionsTest extends TestCase
{
public function actionProvider()
public static function actionProvider(): array
{
return [
['changeTitle'],
Expand Down
Loading

0 comments on commit aad45f8

Please sign in to comment.