Skip to content

Commit

Permalink
Merge pull request #446 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 2b8ecdf + 44a56a2 commit f6b85de
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"asyncphp/doorman": "^4"
},
"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
17 changes: 0 additions & 17 deletions tests/AbstractTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/CleanupJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @author Andrew Aitken-Fincham <[email protected]>
*/
class CleanupJobTest extends AbstractTest
class CleanupJobTest extends SapphireTest
{
/**
* {@inheritDoc}
Expand Down
9 changes: 5 additions & 4 deletions tests/Jobs/DoormanQueuedJobTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Jobs\DoormanQueuedJobTask;
use Symbiote\QueuedJobs\Services\QueuedJob;
use PHPUnit\Framework\Attributes\DataProvider;

class DoormanQueuedJobTaskTest extends SapphireTest
{
protected static $fixture_file = 'DoormanQueuedJobTaskTest.yml';

/**
* @dataProvider canRunTaskProvider
* @param string $status
* @param bool $expected
*/
#[DataProvider('canRunTaskProvider')]
public function testCanRunTask($status, $expected)
{
/** @var QueuedJobDescriptor $descriptor */
Expand All @@ -30,7 +31,7 @@ public function testCanRunTask($status, $expected)
/**
* @return array[]
*/
public function canRunTaskProvider()
public static function canRunTaskProvider()
{
return [
[QueuedJob::STATUS_NEW, true],
Expand All @@ -41,10 +42,10 @@ public function canRunTaskProvider()
}

/**
* @dataProvider isCancelledProvider
* @param string $status
* @param bool $expected
*/
#[DataProvider('isCancelledProvider')]
public function testIsCancelled($status, $expected)
{
/** @var QueuedJobDescriptor $descriptor */
Expand All @@ -59,7 +60,7 @@ public function testIsCancelled($status, $expected)
/**
* @return array[]
*/
public function isCancelledProvider()
public static function isCancelledProvider()
{
return [
[QueuedJob::STATUS_CANCELLED, true],
Expand Down
18 changes: 13 additions & 5 deletions tests/MaintenanceLockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use PHPUnit\Framework\Attributes\DataProvider;
use SilverStripe\Dev\SapphireTest;

/**
* Class MaintenanceLockTest
*
* @package Symbiote\QueuedJobs\Tests
*/
class MaintenanceLockTest extends AbstractTest
class MaintenanceLockTest extends SapphireTest
{
protected function setUp(): void
{
parent::setUp();

// The shutdown handler doesn't play nicely with SapphireTest's database handling
QueuedJobService::config()->set('use_shutdown_function', false);
}

/**
* @param $lockFileEnabled
* @param $fileExists
* @param $lockActive
* @dataProvider maintenanceCaseProvider
*/
#[DataProvider('maintenanceCaseProvider')]
public function testEnableMaintenanceIfActive($lockFileEnabled, $fileExists, $lockActive)
{
$fileName = 'test-lock.txt';
Expand All @@ -41,7 +49,7 @@ public function testEnableMaintenanceIfActive($lockFileEnabled, $fileExists, $lo
/**
* @return array
*/
public function maintenanceCaseProvider()
public static function maintenanceCaseProvider()
{
return [
[
Expand Down
5 changes: 3 additions & 2 deletions tests/QueuedJobRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

use SilverStripe\Dev\SapphireTest;
use Symbiote\QueuedJobs\DataObjects\QueuedJobRule;
use PHPUnit\Framework\Attributes\DataProvider;

class QueuedJobRuleTest extends SapphireTest
{
/**
* @param string $property
* @param mixed $value
* @param mixed $expected
* @dataProvider ruleGetterProvider
*/
#[DataProvider('ruleGetterProvider')]
public function testQueueRuleGetters($property, $value, $expected)
{
$rule = QueuedJobRule::create();
Expand All @@ -21,7 +22,7 @@ public function testQueueRuleGetters($property, $value, $expected)
$this->assertSame($expected, $rule->{$property});
}

public function ruleGetterProvider(): array
public static function ruleGetterProvider(): array
{
return [
['Processes', null, 1],
Expand Down
6 changes: 0 additions & 6 deletions tests/QueuedJobsAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/**
* Tests for the QueuedJobsAdmin ModelAdmin clas
*
* @coversDefaultClass \Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin
* @package queuedjobs
* @author Robbie Averill <[email protected]>
*/
Expand Down Expand Up @@ -73,8 +72,6 @@ public function testConstructorParamsShouldBeATextarea()
/**
* Ensure that when a multi-line value is entered for JobParams, it is split by new line and each value
* passed to the constructor of the JobType that is created by the reflection in createjob()
*
* @covers ::createjob
*/
public function testCreateJobWithConstructorParams()
{
Expand All @@ -95,9 +92,6 @@ public function testCreateJobWithConstructorParams()
$this->admin->createjob($form->getData(), $form);
}

/**
* @covers ::createjob
*/
public function testCreateJobWithStartAfterOption()
{
$startTimeAfter = DBDatetime::now();
Expand Down
18 changes: 9 additions & 9 deletions tests/QueuedJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
use Symbiote\QueuedJobs\Tests\QueuedJobsTest\TestExceptingJob;
use Symbiote\QueuedJobs\Tests\QueuedJobsTest\TestQJService;
use Symbiote\QueuedJobs\Tests\QueuedJobsTest\TestQueuedJob;
use PHPUnit\Framework\Attributes\DataProvider;
use SilverStripe\Dev\SapphireTest;

/**
* @author Marcus Nyeholt <[email protected]>
*/
class QueuedJobsTest extends AbstractTest
class QueuedJobsTest extends SapphireTest
{
/**
* We need the DB for this test
Expand Down Expand Up @@ -746,8 +748,8 @@ public function testGrabMutex(): void
* @param array $jobs
* @param int $expected
* @throws ValidationException
* @dataProvider jobsProvider
*/
#[DataProvider('jobsProvider')]
public function testBrokenJobNotification(array $jobs, int $expected): void
{
/** @var QueuedJobDescriptor $descriptor */
Expand Down Expand Up @@ -776,8 +778,8 @@ public function testBrokenJobNotification(array $jobs, int $expected): void
* @param int $expected
* @throws ValidationException
* @throws Exception
* @dataProvider healthCheckProvider
*/
#[DataProvider('healthCheckProvider')]
public function testExcludeTasksFromHealthCheck(string $jobClass, int $expected): void
{
$service = $this->getService();
Expand All @@ -802,7 +804,7 @@ public function testExcludeTasksFromHealthCheck(string $jobClass, int $expected)
);
}

public function jobsProvider(): array
public static function jobsProvider(): array
{
return [
[
Expand All @@ -824,15 +826,15 @@ public function jobsProvider(): array
];
}

public function healthCheckProvider(): array
public static function healthCheckProvider(): array
{
return [
[TestExceptingJob::class, 1],
[RunBuildTaskJob::class, 0],
];
}

public function provideGetQueue(): array
public static function provideGetQueue(): array
{
return [
'immediate const' => [
Expand Down Expand Up @@ -878,9 +880,7 @@ public function provideGetQueue(): array
];
}

/**
* @dataProvider provideGetQueue
*/
#[DataProvider('provideGetQueue')]
public function testGetQueue(int|string $queue, ?string $expected): void
{
$this->assertSame($expected, AbstractQueuedJob::getQueue($queue));
Expand Down
5 changes: 4 additions & 1 deletion tests/ScheduledExecutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
use Symbiote\QueuedJobs\Tests\ScheduledExecutionTest\TestScheduledDataObject;
use Symbiote\QueuedJobs\Services\QueuedJobService;

/**
* @author [email protected]
* @license BSD License http://silverstripe.org/bsd-license/
*/
class ScheduledExecutionTest extends AbstractTest
class ScheduledExecutionTest extends SapphireTest
{
/**
* We need the DB for this test
Expand All @@ -34,6 +35,8 @@ protected function setUp(): void
parent::setUp();

DBDatetime::set_mock_now('2018-05-28 13:15:00');
// The shutdown handler doesn't play nicely with SapphireTest's database handling
QueuedJobService::config()->set('use_shutdown_function', false);
}

public function testScheduledExecutionTimes()
Expand Down

0 comments on commit f6b85de

Please sign in to comment.