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 #3000

Merged
merged 1 commit into from
Sep 18, 2024
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 @@ -30,7 +30,7 @@
"silverstripe/vendor-plugin": "^2"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Controllers/CMSMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,14 @@ public function testSiteTreeHintsCache()
Security::setCurrentUser($user);
$pageClass = array_values(SiteTree::page_type_classes())[0];
$mockPageMissesCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate'])
->onlyMethods(['canCreate'])
->getMock();
$mockPageMissesCache
->expects($this->exactly(3))
->method('canCreate');

$mockPageHitsCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate'])
->onlyMethods(['canCreate'])
->getMock();
$mockPageHitsCache
->expects($this->never())
Expand Down
1 change: 0 additions & 1 deletion tests/php/Controllers/ContentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public function testLinkShortcodes()
/**
* Tests that {@link ContentController::getViewer()} chooses the correct templates.
*
* @covers \SilverStripe\CMS\Controllers\ContentController::getViewer()
**/
public function testGetViewer()
{
Expand Down
3 changes: 0 additions & 3 deletions tests/php/Controllers/ModelAsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ public function testDoesntRedirectToNestedChildrenOutsideOfOwnHierarchy()
/**
*
* NOTE: This test requires nested_urls
*
*/
public function testRedirectsNestedRenamedPagesWithGetParameters()
{
Expand All @@ -225,7 +224,6 @@ public function testRedirectsNestedRenamedPagesWithGetParameters()
/**
*
* NOTE: This test requires nested_urls
*
*/
public function testDoesntRedirectToNestedRenamedPageWhenNewExists()
{
Expand Down Expand Up @@ -255,7 +253,6 @@ public function testDoesntRedirectToNestedRenamedPageWhenNewExists()
/**
*
* NOTE: This test requires nested_urls
*
*/
public function testFindOldPage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Dev\TestOnly;

class SiteTreeTest_NamespaceMapTestController extends ContentController implements TestOnly
class SiteTreeTest_NamespaceMapTestNodeController extends ContentController implements TestOnly
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was renamed to match the corresponding SiteTreeTest_NamespaceMapTestNode which was also renamed

{

}
13 changes: 5 additions & 8 deletions tests/php/Model/RedirectorPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
use PHPUnit\Framework\Attributes\DataProvider;

class RedirectorPageTest extends FunctionalTest
{
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testGoodRedirectors()
);
}

public function provideEmptyRedirectors()
public static function provideEmptyRedirectors()
{
return [
'use 200' => [
Expand All @@ -73,9 +74,7 @@ public function provideEmptyRedirectors()
];
}

/**
* @dataProvider provideEmptyRedirectors
*/
#[DataProvider('provideEmptyRedirectors')]
public function testEmptyRedirectors(bool $use404)
{
Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404);
Expand Down Expand Up @@ -181,7 +180,7 @@ public function testFileRedirector()
$this->assertStringContainsString("FileTest.txt", $page->Link());
}

public function provideUnpublishedTarget()
public static function provideUnpublishedTarget()
{
return [
'use 200 with sitetree' => [
Expand All @@ -203,9 +202,7 @@ public function provideUnpublishedTarget()
];
}

/**
* @dataProvider provideUnpublishedTarget
*/
#[DataProvider('provideUnpublishedTarget')]
public function testUnpublishedTarget(bool $use404, bool $isFile)
{
Config::modify()->set(RedirectorPageController::class, 'missing_redirect_is_404', $use404);
Expand Down
5 changes: 3 additions & 2 deletions tests/php/Model/SiteTreePermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Versioned\Versioned;
use PHPUnit\Framework\Attributes\DataProvider;

class SiteTreePermissionsTest extends FunctionalTest
{
Expand Down Expand Up @@ -524,8 +525,8 @@ public function testInheritCanEditFromSiteConfig()

/**
* Test permissions on duplicate page
* @dataProvider groupWithPermissions
*/
#[DataProvider('groupWithPermissions')]
public function testDuplicatePageWithGroupPermissions(string $userName, string $method, bool $expected)
{
$originalPage = $this->objFromFixture(SiteTree::class, 'originalpage');
Expand All @@ -538,7 +539,7 @@ public function testDuplicatePageWithGroupPermissions(string $userName, string $
$this->assertSame($dupe->{$method}($user), $expected);
}

public function groupWithPermissions(): array
public static function groupWithPermissions(): array
{
return [
'Subadmin can view page duplicate.' => [
Expand Down
40 changes: 15 additions & 25 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use SilverStripe\CMS\Model\RedirectorPage;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestController;
use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestNodeController;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage;
use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild;
use SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject;
use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTest;
use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTestNode;
use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
Expand Down Expand Up @@ -42,6 +42,7 @@
use PageController;

use const RESOURCES_DIR;
use PHPUnit\Framework\Attributes\DataProvider;

class SiteTreeTest extends SapphireTest
{
Expand Down Expand Up @@ -71,7 +72,7 @@ class SiteTreeTest extends SapphireTest
NotPageObject::class,
];

public function reservedSegmentsProvider()
public static function reservedSegmentsProvider()
{
return [
// segments reserved by rules
Expand Down Expand Up @@ -142,8 +143,8 @@ public function testURLGeneration()

/**
* Check if reserved URL's are properly appended with a number at top level
* @dataProvider reservedSegmentsProvider
*/
#[DataProvider('reservedSegmentsProvider')]
public function testDisallowedURLGeneration($title, $urlSegment)
{
$page = new SiteTree(['Title' => $title]);
Expand All @@ -155,8 +156,8 @@ public function testDisallowedURLGeneration($title, $urlSegment)
/**
* Check if reserved URL's are not appended with a number on a child page
* It's okay to have a URL like domain.com/my-page/admin as it won't interfere with domain.com/admin
* @dataProvider reservedSegmentsProvider
*/
#[DataProvider('reservedSegmentsProvider')]
public function testDisallowedChildURLGeneration($title, $urlSegment)
{
// Using the same dataprovider, strip out the -2 from the admin and dev segment
Expand Down Expand Up @@ -1092,9 +1093,6 @@ public function testURLSegmentAutoUpdateLocalized()
i18n::set_locale($oldLocale);
}

/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentURLSegmentConflicts()
{
$sitetree = new SiteTree();
Expand Down Expand Up @@ -1124,9 +1122,6 @@ public function testValidURLSegmentURLSegmentConflicts()
$this->assertTrue($sitetree->validURLSegment());
}

/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentClassNameConflicts()
{
$sitetree = new SiteTree();
Expand All @@ -1135,9 +1130,6 @@ public function testValidURLSegmentClassNameConflicts()
$this->assertTrue($sitetree->validURLSegment(), 'Class names are no longer conflicts');
}

/**
* @covers \SilverStripe\CMS\Model\SiteTree::validURLSegment
*/
public function testValidURLSegmentControllerConflicts()
{
Config::modify()->set(SiteTree::class, 'nested_urls', true);
Expand Down Expand Up @@ -1273,11 +1265,11 @@ public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass()

/**
* Tests that various types of SiteTree classes will or will not be returned from the allowedChildren method
* @dataProvider allowedChildrenProvider
* @param string $className
* @param array $expected
* @param string $assertionMessage
*/
#[DataProvider('allowedChildrenProvider')]
public function testAllowedChildren($className, $expected, $assertionMessage)
{
$class = new $className;
Expand All @@ -1287,7 +1279,7 @@ public function testAllowedChildren($className, $expected, $assertionMessage)
/**
* @return array
*/
public function allowedChildrenProvider()
public static function allowedChildrenProvider()
{
return [
[
Expand Down Expand Up @@ -1525,7 +1517,7 @@ public function testMetaComponents()
$charset = Config::inst()->get(ContentNegotiator::class, 'encoding');

$mockVersionProvider = $this->getMockBuilder(VersionProvider::class)
->setMethods(['getModuleVersion'])
->onlyMethods(['getModuleVersion'])
->getMock();
$mockVersionProvider->method('getModuleVersion')->willReturn('4.50.99');
$page->setVersionProvider($mockVersionProvider);
Expand Down Expand Up @@ -1752,8 +1744,8 @@ public function testGetControllerNameFromNamespaceMappingConfig()
'SilverStripe\\CMS\\Tests\\Page' => 'SilverStripe\\CMS\\Tests\\Controllers',
]);

$namespacedSiteTree = new SiteTreeTest_NamespaceMapTest();
$this->assertSame(SiteTreeTest_NamespaceMapTestController::class, $namespacedSiteTree->getControllerName());
$namespacedSiteTree = new SiteTreeTest_NamespaceMapTestNode();
$this->assertSame(SiteTreeTest_NamespaceMapTestNodeController::class, $namespacedSiteTree->getControllerName());
}

public function testTreeTitleCache()
Expand All @@ -1764,14 +1756,14 @@ public function testTreeTitleCache()
$pageClass = array_values(SiteTree::page_type_classes())[0];

$mockPageMissesCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate'])
->onlyMethods(['canCreate'])
->getMock();
$mockPageMissesCache
->expects($this->exactly(3))
->method('canCreate');

$mockPageHitsCache = $this->getMockBuilder($pageClass)
->setMethods(['canCreate'])
->onlyMethods(['canCreate'])
->getMock();
$mockPageHitsCache
->expects($this->never())
Expand Down Expand Up @@ -2092,9 +2084,7 @@ public function testCMSEditLink()
);
}

/**
* @dataProvider provideSanitiseExtraMeta
*/
#[DataProvider('provideSanitiseExtraMeta')]
public function testSanitiseExtraMeta(string $extraMeta, string $expected, string $message): void
{
$siteTree = new SiteTree();
Expand All @@ -2103,7 +2093,7 @@ public function testSanitiseExtraMeta(string $extraMeta, string $expected, strin
$this->assertSame($expected, $siteTree->ExtraMeta, $message);
}

public function provideSanitiseExtraMeta(): array
public static function provideSanitiseExtraMeta(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly;

class SiteTreeTest_NamespaceMapTest extends SiteTree implements TestOnly
class SiteTreeTest_NamespaceMapTestNode extends SiteTree implements TestOnly
Copy link
Member Author

@emteknetnz emteknetnz Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this file ends in "Test" - phpunit though it was a test class and complained that it had no test cases. So I simply renamed it to match its $table_name

{
private static $table_name = 'SiteTreeTest_NamespaceMapTestNode';
}
3 changes: 0 additions & 3 deletions tests/php/Search/ZZZSearchFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ public function testPagesRestrictedToSpecificGroupNotIncluded()
Security::setCurrentUser(null);
}

/**
*
*/
public function testInheritedRestrictedPagesNotIncluded()
{
$request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']);
Expand Down
Loading