Skip to content

Commit

Permalink
Merge pull request #194 from creative-commoners/pulls/6/phpunit11
Browse files Browse the repository at this point in the history
DEP Use PHPUnit 11
  • Loading branch information
GuySartorelli authored Sep 18, 2024
2 parents 1eea4a2 + 2b67bd9 commit fd5f043
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
7 changes: 3 additions & 4 deletions tests/ReportAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Reports\Tests\ReportAdminTest\CannotViewReport;
use SilverStripe\Reports\Tests\ReportAdminTest\FakeReport;
use SilverStripe\Reports\Tests\ReportAdminTest\FakeReport2;
use PHPUnit\Framework\Attributes\DataProvider;

class ReportAdminTest extends FunctionalTest
{
Expand Down Expand Up @@ -46,7 +47,7 @@ public function testBreadcrumbsAreGenerated()
$this->assertSame('Fake report two', $map['Title']);
}

public function provideShowReport(): array
public static function provideShowReport(): array
{
return [
'cannot view' => [
Expand All @@ -60,9 +61,7 @@ public function provideShowReport(): array
];
}

/**
* @dataProvider provideShowReport
*/
#[DataProvider('provideShowReport')]
public function testShowReport(string $reportClass, int $expected): void
{
$this->logInWithPermission('ADMIN');
Expand Down
32 changes: 16 additions & 16 deletions tests/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\Reports\Tests\ReportTest\FakeObject;
use SilverStripe\Reports\Tests\ReportTest\FakeTest;
use SilverStripe\Reports\Tests\ReportTest\FakeTest2;
use SilverStripe\Reports\Tests\ReportTest\FakeReport;
use SilverStripe\Reports\Tests\ReportTest\FakeReport2;
use SilverStripe\Reports\Report;

class ReportTest extends SapphireTest
Expand All @@ -34,31 +34,31 @@ public function testExcludeReport()
foreach ($reports as $report) {
$reportNames[] = get_class($report);
}
$this->assertContains(FakeTest::class, $reportNames, 'ReportTest_FakeTest is in reports list');
$this->assertContains(FakeReport::class, $reportNames, 'ReportTest_FakeReport is in reports list');

// Exclude one report
Config::modify()->merge(Report::class, 'excluded_reports', [FakeTest::class]);
Config::modify()->merge(Report::class, 'excluded_reports', [FakeReport::class]);

$reports = Report::get_reports();
$reportNames = array();
foreach ($reports as $report) {
$reportNames[] = get_class($report);
}
$this->assertNotContains(FakeTest::class, $reportNames, 'ReportTest_FakeTest is NOT in reports list');
$this->assertNotContains(FakeReport::class, $reportNames, 'ReportTest_FakeReport is NOT in reports list');

// Exclude two reports
Config::modify()->merge(Report::class, 'excluded_reports', [
FakeTest::class,
FakeTest2::class
FakeReport::class,
FakeReport2::class
]);

$reports = Report::get_reports();
$reportNames = [];
foreach ($reports as $report) {
$reportNames[] = get_class($report);
}
$this->assertNotContains(FakeTest::class, $reportNames, 'ReportTest_FakeTest is NOT in reports list');
$this->assertNotContains(FakeTest2::class, $reportNames, 'ReportTest_FakeTest2 is NOT in reports list');
$this->assertNotContains(FakeReport::class, $reportNames, 'ReportTest_FakeReport is NOT in reports list');
$this->assertNotContains(FakeReport2::class, $reportNames, 'ReportTest_FakeReport2 is NOT in reports list');
}

public function testAbstractClassesAreExcluded()
Expand All @@ -69,15 +69,15 @@ public function testAbstractClassesAreExcluded()
$reportNames[] = get_class($report);
}
$this->assertNotContains(
'ReportTest_FakeTest_Abstract',
'ReportTest_FakeReport_Abstract',
$reportNames,
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract'
'ReportTest_FakeReport_Abstract is NOT in reports list as it is abstract'
);
}

public function testPermissions()
{
$report = new ReportTest\FakeTest2();
$report = new ReportTest\FakeReport2();

// Visitor cannot view
$this->logOut();
Expand All @@ -98,7 +98,7 @@ public function testPermissions()

public function testColumnLink()
{
$report = new ReportTest\FakeTest();
$report = new ReportTest\FakeReport();
/** @var GridField $gridField */
$gridField = $report->getReportField();
/** @var GridFieldDataColumns $columns */
Expand All @@ -117,17 +117,17 @@ public function testColumnLink()

public function testCountForOverview()
{
$report = new ReportTest\FakeTest3();
$report = new ReportTest\FakeReport3();

// Count is limited to 10000 by default
$this->assertEquals('10000+', $report->getCountForOverview());

// Count is limited as per configuration
Config::modify()->set(ReportTest\FakeTest3::class, 'limit_count_in_overview', 15);
Config::modify()->set(ReportTest\FakeReport3::class, 'limit_count_in_overview', 15);
$this->assertEquals('15+', $report->getCountForOverview());

// A null limit displays the full count
Config::modify()->set(ReportTest\FakeTest3::class, 'limit_count_in_overview', null);
Config::modify()->set(ReportTest\FakeReport3::class, 'limit_count_in_overview', null);
$this->assertEquals('15000', $report->getCountForOverview());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;

class FakeTest extends Report implements TestOnly
class FakeReport extends Report implements TestOnly
{
public function title()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;

class FakeTest2 extends Report implements TestOnly
class FakeReport2 extends Report implements TestOnly
{
public function title()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;

class FakeTest3 extends Report implements TestOnly
class FakeReport3 extends Report implements TestOnly
{
public function sourceRecords($params, $sort, $limit)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ReportTest/FakeTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;

abstract class FakeTestAbstract extends Report implements TestOnly
abstract class FakeReportAbstract extends Report implements TestOnly
{
public function title()
{
Expand Down

0 comments on commit fd5f043

Please sign in to comment.