Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Use PHPUnit 11 #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"guzzlehttp/guzzle": "^7.5"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3",
"symfony/thanks": "^1.2",
"silverstripe/standards": "^1",
Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/GridFieldRefreshButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ protected function getGridFieldMock()
$gridFieldMock = $this
->getMockBuilder(GridField::class)
->setConstructorArgs(['TestGridField'])
->setMethods(['Link'])
->onlyMethods(['Link'])
->getMock();

$gridFieldMock
->expects($this->any())
->method('Link')
->will($this->returnValue('http://example.com'));
->willReturn('http://example.com');

return $gridFieldMock;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Model/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
use PHPUnit\Framework\Attributes\DataProvider;

class PackageTest extends SapphireTest
{
public function providePackageNamesAndTitles()
public static function providePackageNamesAndTitles()
{
return [
['pretendvendor/silverstripe-prefixedpackage', 'prefixedpackage'],
Expand All @@ -26,10 +27,10 @@ public function providePackageNamesAndTitles()
}

/**
* @dataProvider providePackageNamesAndTitles
*
* Ensure the vendor and 'silverstripe-' is stripped from module names.
*/
#[DataProvider('providePackageNamesAndTitles')]
public function testTitleFormatsNameCorrectly($name, $title)
{
$testPackage = new Package([
Expand Down
6 changes: 3 additions & 3 deletions tests/Tasks/UpdatePackageInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function getModuleVersion(string $module): string
};
Injector::inst()->registerService(new $mockVersionProvider(), VersionProvider::class);
$composerLoader = $this->getMockBuilder(ComposerLoader::class)
->setMethods(['getLock'])->getMock();
$composerLoader->expects($this->any())->method('getLock')->will($this->returnValue(json_decode(<<<LOCK
->onlyMethods(['getLock'])->getMock();
$composerLoader->expects($this->any())->method('getLock')->willReturn(json_decode(<<<LOCK
{
"packages": [
{
Expand All @@ -78,7 +78,7 @@ public function getModuleVersion(string $module): string
"packages-dev": null
}
LOCK
)));
));

$task = UpdatePackageInfoTask::create();
$task->setComposerLoader($composerLoader);
Expand Down
25 changes: 10 additions & 15 deletions tests/Util/ApiLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\Dev\SapphireTest;
use Psr\SimpleCache\CacheInterface;
use ReflectionMethod;
use PHPUnit\Framework\Attributes\DataProvider;

class ApiLoaderTest extends SapphireTest
{
Expand Down Expand Up @@ -40,8 +41,6 @@ private function getFakeJson(): array

/**
* Note: contains some logic from SupportedAddonsLoader for context
*
* @group integration
*/
public function testAddonsAreParsedAndReturnedCorrectly()
{
Expand All @@ -61,18 +60,16 @@ public function testAddonsAreParsedAndReturnedCorrectly()

/**
* Note: contains some logic from SupportedAddonsLoader for context
*
* @group integration
*/
public function testCacheControlSettingsAreRespected()
{
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->once())->method('get')->will($this->returnValue(false));
$cacheMock->expects($this->once())->method('get')->willReturn(false);
$cacheMock->expects($this->once())
->method('set')
->with($this->anything(), '["foo\/bar","bin\/baz"]', 5000)
->will($this->returnValue(true));
->willReturn(true);

$loader = $this->getLoader($cacheMock);
$loader->setGuzzleClient($this->getMockClient(new Response(
Expand All @@ -90,10 +87,10 @@ public function testCachedAddonsAreUsedWhenAvailable()
{
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->once())->method('get')->will($this->returnValue(json_encode($this->getFakeJson())));
$cacheMock->expects($this->once())->method('get')->willReturn(json_encode($this->getFakeJson()));
$loader = $this->getLoader($cacheMock);

$mockClient = $this->getMockBuilder(Client::class)->setMethods(['send'])->getMock();
$mockClient = $this->getMockBuilder(Client::class)->onlyMethods(['send'])->getMock();
$mockClient->expects($this->never())->method('send');
$loader->setGuzzleClient($mockClient);

Expand All @@ -104,9 +101,7 @@ public function testCachedAddonsAreUsedWhenAvailable()
$this->assertSame($this->getFakeJson(), $addons);
}

/**
* @dataProvider provideParseResponseContentsEmpty
*/
#[DataProvider('provideParseResponseContentsEmpty')]
public function testParseResponseContentsEmpty(string $contents)
{
// ApiLoader is an abstract class
Expand All @@ -125,7 +120,7 @@ protected function getCacheKey()
$inst->parseResponseContents($contents, $failureMessage);
}

public function provideParseResponseContentsEmpty(): array
public static function provideParseResponseContentsEmpty(): array
{
return [
[
Expand Down Expand Up @@ -179,15 +174,15 @@ protected function getLoader($cacheMock = false)
if (!$cacheMock) {
$cacheMock = $this->getMockCacheInterface();

$cacheMock->expects($this->any())->method('get')->will($this->returnValue(false));
$cacheMock->expects($this->any())->method('set')->will($this->returnValue(true));
$cacheMock->expects($this->any())->method('get')->willReturn(false);
$cacheMock->expects($this->any())->method('set')->willReturn(true);
}

$loader = $this->getMockBuilder(ApiLoader::class)
->getMockForAbstractClass();

$loader->setCache($cacheMock);
$loader->expects($this->any())->method('getCacheKey')->will($this->returnValue('cacheKey'));
$loader->expects($this->any())->method('getCacheKey')->willReturn('cacheKey');

return $loader;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Util/ModuleHealthLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function setUp(): void
parent::setUp();

$this->loader = $this->getMockBuilder(ModuleHealthLoader::class)
->setMethods(['doRequest'])
->onlyMethods(['doRequest'])
->getMock();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Util/SupportedAddonsLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function setUp(): void
parent::setUp();

$this->loader = $this->getMockBuilder(SupportedAddonsLoader::class)
->setMethods(['doRequest'])
->onlyMethods(['doRequest'])
->getMock();
}

Expand Down
Loading