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 17, 2024
1 parent 98850c6 commit c6a524e
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Assets\Tests\Conversion\FileConverterManagerTest\TestTxtToImageConverter;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use PHPUnit\Framework\Attributes\DataProvider;

class FileConverterManagerTest extends SapphireTest
{
Expand Down Expand Up @@ -41,35 +42,33 @@ protected function setUp(): void
}
}

public function provideConvert(): array
public static function provideConvert(): array
{
return [
'supported by image converter' => [
'fromFormat' => 'jpg',
'toFormat' => 'png',
'fromExtension' => 'jpg',
'toExtension' => 'png',
'expectSuccess' => true,
],
'supported by txt converter' => [
'fromFormat' => 'txt',
'toFormat' => 'png',
'fromExtension' => 'txt',
'toExtension' => 'png',
'expectSuccess' => true,
],
'unsupported 1' => [
'fromFormat' => 'jpg',
'toFormat' => 'txt',
'fromExtension' => 'jpg',
'toExtension' => 'txt',
'expectSuccess' => false,
],
'unsupported 2' => [
'fromFormat' => 'txt',
'toFormat' => 'doc',
'fromExtension' => 'txt',
'toExtension' => 'doc',
'expectSuccess' => false,
],
];
}

/**
* @dataProvider provideConvert
*/
#[DataProvider('provideConvert')]
public function testConvert(string $fromExtension, string $toExtension, bool $expectSuccess): void
{
$manager = new FileConverterManager();
Expand Down
19 changes: 7 additions & 12 deletions tests/php/Conversion/InterventionImageFileConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Dev\SapphireTest;
use PHPUnit\Framework\Attributes\DataProvider;

class InterventionImageFileConverterTest extends SapphireTest
{
Expand All @@ -34,7 +35,7 @@ protected function setUp(): void
}
}

public function provideSupportsConversion(): array
public static function provideSupportsConversion(): array
{
// We don't need to check every possible file type here.
// We're just validating that the logic overall holds true.
Expand Down Expand Up @@ -90,16 +91,14 @@ public function provideSupportsConversion(): array
];
}

/**
* @dataProvider provideSupportsConversion
*/
#[DataProvider('provideSupportsConversion')]
public function testSupportsConversion(string $from, string $to, array $options, bool $expected): void
{
$converter = new InterventionImageFileConverter();
$this->assertSame($expected, $converter->supportsConversion($from, $to, $options));
}

public function provideConvert(): array
public static function provideConvert(): array
{
return [
'no options' => [
Expand All @@ -111,9 +110,7 @@ public function provideConvert(): array
];
}

/**
* @dataProvider provideConvert
*/
#[DataProvider('provideConvert')]
public function testConvert(array $options): void
{
$origFile = $this->objFromFixture(Image::class, 'jpg-image');
Expand All @@ -133,7 +130,7 @@ public function testConvert(array $options): void
}
}

public function provideConvertUnsupported(): array
public static function provideConvertUnsupported(): array
{
return [
'nothing to convert from' => [
Expand Down Expand Up @@ -181,9 +178,7 @@ public function provideConvertUnsupported(): array
];
}

/**
* @dataProvider provideConvertUnsupported
*/
#[DataProvider('provideConvertUnsupported')]
public function testConvertUnsupported(string $fixtureClass, string $fromFixture, string $to, array $options, string $exceptionMessage): void
{
$file = $this->objFromFixture($fixtureClass, $fromFixture);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/FileFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class FileFinderTest extends SapphireTest

protected $base;

public function __construct()
public function __construct(string $name)
{
$this->base = __DIR__ . '/FileFinderTest';
parent::__construct();
parent::__construct($name);
}

public function testBasicOperation()
Expand Down
7 changes: 3 additions & 4 deletions tests/php/FileNameFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Assets\FileNameFilter;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\Transliterator;
use PHPUnit\Framework\Attributes\DataProvider;

class FileNameFilterTest extends SapphireTest
{
Expand Down Expand Up @@ -59,9 +60,7 @@ public function testFilterWithCustomRules()
);
}

/**
* @dataProvider providerFilterWithEmptyString
*/
#[DataProvider('providerFilterWithEmptyString')]
public function testFilterWithEmptyString($name)
{
$filter = new FileNameFilter();
Expand All @@ -80,7 +79,7 @@ public function testFilterWithEmptyString($name)
);
}

public function providerFilterWithEmptyString()
public static function providerFilterWithEmptyString()
{
return [['ö ö ö.jpg'], ['新しいファイル.jpg']];
}
Expand Down
35 changes: 17 additions & 18 deletions tests/php/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\PermissionChecker;
use SilverStripe\Versioned\Versioned;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Tests for the File class
Expand Down Expand Up @@ -185,7 +186,7 @@ public function testInvalidImageManipulations()
$this->assertNull($broken->Pad(100, 100));
}

public function appCategoryDataProvider()
public static function appCategoryDataProvider()
{
return [
['image', 'jpg'],
Expand All @@ -200,9 +201,7 @@ public function appCategoryDataProvider()
];
}

/**
* @dataProvider appCategoryDataProvider
*/
#[DataProvider('appCategoryDataProvider')]
public function testAppCategory($category, $extension)
{
// Test various categories
Expand Down Expand Up @@ -833,10 +832,10 @@ public function testRename()
}

/**
* @dataProvider allowedExtensionsProvider
* @param array $allowedExtensions
* @param array $expected
*/
#[DataProvider('allowedExtensionsProvider')]
public function testGetAllowedExtensions($allowedExtensions, $expected)
{
Config::modify()->set(File::class, 'allowed_extensions', $allowedExtensions);
Expand All @@ -846,7 +845,7 @@ public function testGetAllowedExtensions($allowedExtensions, $expected)
/**
* @return array[]
*/
public function allowedExtensionsProvider()
public static function allowedExtensionsProvider()
{
return [
'unkeyed array' => [
Expand Down Expand Up @@ -875,7 +874,7 @@ public function allowedExtensionsProvider()
public function testCanViewReturnsExtendedResult()
{
/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(true);
$this->assertTrue($file->canView());
}
Expand All @@ -885,7 +884,7 @@ public function testCanViewDelegatesToParentWhenInheritingPermissions()
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

/** @var PermissionChecker&MockObject $permissionChecker */
Expand Down Expand Up @@ -938,7 +937,7 @@ public function testCanViewReturnsFalseForAnonymousUsersWithCanViewTypeLoggedInU
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

$file->CanViewType = 'LoggedInUsers';
Expand All @@ -950,7 +949,7 @@ public function testCanViewReturnsFalseForAnonymousUsersWithCanViewTypeOnlyThese
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

$file->CanViewType = 'OnlyTheseUsers';
Expand All @@ -960,7 +959,7 @@ public function testCanViewReturnsFalseForAnonymousUsersWithCanViewTypeOnlyThese
public function testCanViewReturnsTrueForUserInGroupWithCanViewTypeOnlyTheseUsers()
{
/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

/** @var Member&MockObject $member */
Expand All @@ -976,7 +975,7 @@ public function testCanViewFallsBackToCheckingDefaultFilePermissions()
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

/** @var PermissionChecker&MockObject $permissionChecker */
Expand All @@ -992,7 +991,7 @@ public function testCanViewFallsBackToCheckingDefaultFilePermissions()
public function testCanEditReturnsExtendedResult()
{
/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(true);
$this->assertTrue($file->canEdit());
}
Expand All @@ -1002,7 +1001,7 @@ public function testCanEditReturnsTrueForUserWithEditAllPermissions()
$this->logInWithPermission();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);
$this->assertTrue($file->canEdit());
}
Expand All @@ -1012,7 +1011,7 @@ public function testCanEditDelegatesToParentWhenInheritingPermissions()
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

/** @var PermissionChecker&MockObject $permissionChecker */
Expand All @@ -1030,7 +1029,7 @@ public function testCanEditFallsBackToCheckingDefaultFilePermissions()
$this->logOut();

/** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)->setMethods(['extendedCan'])->getMock();
$file = $this->getMockBuilder(File::class)->onlyMethods(['extendedCan'])->getMock();
$file->expects($this->once())->method('extendedCan')->willReturn(null);

/** @var PermissionChecker&MockObject $permissionChecker */
Expand All @@ -1047,7 +1046,7 @@ public function testCanEditFallsBackToCheckingDefaultFilePermissions()
* @return Generator
* @see testHasRestrictedAccess
*/
public function restrictedAccessDataProvider()
public static function restrictedAccessDataProvider()
{
yield ['restricted-test-r', false];
yield ['restricted-test-r1', false];
Expand All @@ -1063,11 +1062,11 @@ public function restrictedAccessDataProvider()
}

/**
* @dataProvider restrictedAccessDataProvider
*
* @param string $fixtureName
* @param bool $expected
*/
#[DataProvider('restrictedAccessDataProvider')]
public function testHasRestrictedAccess(string $fixtureName, bool $expected)
{
/** @var Folder $folder */
Expand Down
Loading

0 comments on commit c6a524e

Please sign in to comment.