Skip to content

Commit

Permalink
DEP Use PHPUnit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 10, 2024
1 parent 7c53d75 commit 3a05872
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 92 deletions.
43 changes: 15 additions & 28 deletions tests/php/Controllers/LinkFieldControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\LinkField\Tests\Models\LinkTest\LinkOwner;
use SilverStripe\Versioned\Versioned;
use SilverStripe\LinkField\Models\Link;
use PHPUnit\Framework\Attributes\DataProvider;

class LinkFieldControllerTest extends FunctionalTest
{
Expand Down Expand Up @@ -61,9 +62,7 @@ protected function tearDown(): void
LinkOwner::add_extension(Versioned::class);
}

/**
* @dataProvider provideLinkFormGetSchema
*/
#[DataProvider('provideLinkFormGetSchema')]
public function testLinkFormGetSchema(
string $idType,
string $typeKey,
Expand Down Expand Up @@ -115,7 +114,7 @@ public function testLinkFormGetSchema(
}
}

public function provideLinkFormGetSchema(): array
public static function provideLinkFormGetSchema(): array
{
return [
'Valid existing record' => [
Expand Down Expand Up @@ -170,9 +169,7 @@ public function provideLinkFormGetSchema(): array
];
}

/**
* @dataProvider provideExcludeLinkTextField
*/
#[DataProvider('provideExcludeLinkTextField')]
public function testExcludeLinkTextField(bool $excludeLinkTextField): void
{
$owner = $this->getFixtureLinkOwner();
Expand Down Expand Up @@ -202,7 +199,7 @@ public function testExcludeLinkTextField(bool $excludeLinkTextField): void
}
}

public function provideExcludeLinkTextField(): array
public static function provideExcludeLinkTextField(): array
{
return [
'exclude field' => [
Expand All @@ -214,9 +211,7 @@ public function provideExcludeLinkTextField(): array
];
}

/**
* @dataProvider provideLinkFormPost
*/
#[DataProvider('provideLinkFormPost')]
public function testLinkFormPost(
string $idType,
string $typeKey,
Expand Down Expand Up @@ -311,7 +306,7 @@ public function testLinkFormPost(
}
}

public function provideLinkFormPost(): array
public static function provideLinkFormPost(): array
{
// note: not duplicating code paths already tested with provideLinkFormGetSchema()
// e.g. Reject Invalid ID
Expand Down Expand Up @@ -423,9 +418,7 @@ public function provideLinkFormPost(): array
];
}

/**
* @dataProvider provideLinkFormReadOnly
*/
#[DataProvider('provideLinkFormReadOnly')]
public function testLinkFormReadonly(string $idType, string $fail, bool $expected): void
{
TestPhoneLink::$fail = $fail;
Expand All @@ -444,7 +437,7 @@ public function testLinkFormReadonly(string $idType, string $fail, bool $expecte
$this->assertSame($expected, $actual);
}

public function provideLinkFormReadOnly(): array
public static function provideLinkFormReadOnly(): array
{
return [
[
Expand All @@ -470,9 +463,7 @@ public function provideLinkFormReadOnly(): array
];
}

/**
* @dataProvider provideLinkData
*/
#[DataProvider('provideLinkData')]
public function testLinkData(
string $idType,
int $expectedCode,
Expand All @@ -495,7 +486,7 @@ public function testLinkData(
}
}

public function provideLinkData(): array
public static function provideLinkData(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -529,9 +520,7 @@ public function provideLinkData(): array
];
}

/**
* @dataProvider provideLinkArchive
*/
#[DataProvider('provideLinkArchive')]
public function testLinkArchive(
string $idType,
string $fail,
Expand Down Expand Up @@ -567,7 +556,7 @@ public function testLinkArchive(
}
}

public function provideLinkArchive(): array
public static function provideLinkArchive(): array
{
return [
'Valid' => [
Expand Down Expand Up @@ -633,9 +622,7 @@ public function testLinkDeleteVersions(): void
$this->assertNull($liveLink);
}

/**
* @dataProvider provideLinkSort
*/
#[DataProvider('provideLinkSort')]
public function testLinkSort(
array $newLinkTextOrder,
string $fail,
Expand Down Expand Up @@ -669,7 +656,7 @@ public function testLinkSort(
);
}

public function provideLinkSort(): array
public static function provideLinkSort(): array
{
return [
'Success' => [
Expand Down
7 changes: 3 additions & 4 deletions tests/php/Form/MultiLinkFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\LinkField\Form\MultiLinkField;
use SilverStripe\ORM\ArrayList;
use PHPUnit\Framework\Attributes\DataProvider;

class MultiLinkFieldTest extends SapphireTest
{
public function provideConvertValueToArray(): array
public static function provideConvertValueToArray(): array
{
return [
'empty string' => [
Expand Down Expand Up @@ -56,9 +57,7 @@ public function provideConvertValueToArray(): array
];
}

/**
* @dataProvider provideConvertValueToArray
*/
#[DataProvider('provideConvertValueToArray')]
public function testConvertValueToArray(mixed $value, array $expected): void
{
$field = new MultiLinkField('');
Expand Down
32 changes: 13 additions & 19 deletions tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\LinkField\Tests\Controllers\LinkFieldControllerTest\TestPhoneLink;
use SilverStripe\LinkField\Tests\Models\SiteTreeLinkTest\TestSiteTreeCanView;
use PHPUnit\Framework\Attributes\DataProvider;

class LinkTest extends SapphireTest
{
Expand Down Expand Up @@ -106,8 +107,8 @@ public function testSiteTreeLinkTitleFallback(): void
* @param string $class
* @param bool $expected
* @throws ReflectionException
* @dataProvider linkTypeProvider
*/
#[DataProvider('linkTypeProvider')]
public function testLinkType(string $class, bool $expected): void
{
/** @var Link $model */
Expand All @@ -119,7 +120,7 @@ public function testLinkType(string $class, bool $expected): void
: $this->assertNull($linkTypeField, 'We do not expect to a find link type field');
}

public function linkTypeProvider(): array
public static function linkTypeProvider(): array
{
return [
[EmailLink::class, false],
Expand Down Expand Up @@ -152,7 +153,7 @@ public function testGetVersionedState(): void
$this->assertEquals('unversioned', $link->getVersionedState());
}

public function provideGetUrl(): array
public static function provideGetUrl(): array
{
return [
'internal link / page only' => [
Expand Down Expand Up @@ -233,16 +234,16 @@ public function provideGetUrl(): array
* @param string $class
* @param string $expected
* @return void
* @dataProvider provideGetUrl
*/
#[DataProvider('provideGetUrl')]
public function testGetUrl(string $identifier, string $class, string $expected): void
{
/** @var Link $link */
$link = $this->objFromFixture($class, $identifier);
$this->assertSame($expected, $link->getURL(), 'We expect specific URL value');
}

function provideDefaultLinkTitle(): array
static function provideDefaultLinkTitle(): array
{
return [
'page link' => [
Expand Down Expand Up @@ -303,9 +304,7 @@ function provideDefaultLinkTitle(): array
];
}

/**
* @dataProvider provideDefaultLinkTitle
*/
#[DataProvider('provideDefaultLinkTitle')]
public function testDefaultLinkTitle(string $identifier, string $class, string $expected): void
{
/** @var Link $link */
Expand All @@ -314,7 +313,7 @@ public function testDefaultLinkTitle(string $identifier, string $class, string $
$this->assertEquals($expected, $link->getTitle());
}

public function provideOwner()
public static function provideOwner()
{
return [
'null because there is no owner' => [
Expand Down Expand Up @@ -344,9 +343,8 @@ public function provideOwner()
* Test the functionality of the overridden Owner method.
* Note this is NOT explicitly testing multi-relational has_many relations pointing at the has_one since that's
* a framework functionality, not a linkfield one.
*
* @dataProvider provideOwner
*/
#[DataProvider('provideOwner')]
public function testOwner(string $class, string $fixture, ?array $expected)
{
$link = $this->objFromFixture($class, $fixture);
Expand Down Expand Up @@ -401,9 +399,7 @@ public function testOwnerHasOne()
$this->assertSame($owner->ID, $link->Owner()?->ID);
}

/**
* @dataProvider provideCanPermissions
*/
#[DataProvider('provideCanPermissions')]
public function testCanPermissions(string $linkPermission, string $ownerPermission)
{
$link = $this->objFromFixture(SiteTreeLink::class, 'page-link-page-only');
Expand All @@ -421,7 +417,7 @@ public function testCanPermissions(string $linkPermission, string $ownerPermissi
$this->assertFalse($link->can($permissionName));
}

public function provideCanPermissions()
public static function provideCanPermissions()
{
return [
'canView' => [
Expand All @@ -447,7 +443,7 @@ public function testCanCreate()
$this->assertTrue($link->can('Create'));
}

public function provideLinkType(): array
public static function provideLinkType(): array
{
return [
'email_link_type' => [
Expand Down Expand Up @@ -477,9 +473,7 @@ public function provideLinkType(): array
];
}

/**
* @dataProvider provideLinkType
*/
#[DataProvider('provideLinkType')]
public function testGetShortCode(string $class, string $expected): void
{
$linkClass = Injector::inst()->get($class);
Expand Down
11 changes: 4 additions & 7 deletions tests/php/Services/LinkTypeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\LinkField\Models\PhoneLink;
use SilverStripe\LinkField\Models\SiteTreeLink;
use SilverStripe\LinkField\Tests\Controllers\LinkFieldControllerTest\TestPhoneLink;
use PHPUnit\Framework\Attributes\DataProvider;

class LinkTypeServiceTest extends SapphireTest
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testGenerateAllLinkTypes()
$this->assertSame($expected, $types);
}

public function keyClassDataProvider(): array
public static function keyClassDataProvider(): array
{
return [
'sitetree_key' => [
Expand Down Expand Up @@ -81,9 +82,7 @@ public function keyClassDataProvider(): array
];
}

/**
* @dataProvider keyClassDataProvider
*/
#[DataProvider('keyClassDataProvider')]
public function testByKey($key, $class)
{
$service = new LinkTypeService();
Expand All @@ -93,9 +92,7 @@ public function testByKey($key, $class)
$this->assertEquals($linkClass, $keyType);
}

/**
* @dataProvider keyClassDataProvider
*/
#[DataProvider('keyClassDataProvider')]
public function testKeyByClassName($key, $class)
{
$service = new LinkTypeService();
Expand Down
Loading

0 comments on commit 3a05872

Please sign in to comment.