Skip to content

Commit

Permalink
ci: Update to PHPUnit 10
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Oct 2, 2024
1 parent ebfd9cf commit 06a7b8b
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 498 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nbproject
/tests/Unit/coverage*
/tests/Unit/clover.xml
/tests/Unit/js/node_modules
/tests/Unit/.phpunit.cache
/tests/Unit/.phpunit.result.cache
/.php-cs-fixer.cache

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Controller/APIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function setUp(): void {
);
}

public function dataGenerateNotification(): array {
public static function dataGenerateNotification(): array {
return [
['user', '', '', false, null, false, null, 123, null, Http::STATUS_NOT_FOUND],
['user', '', '', false, null, false, 'user', 123, null, Http::STATUS_BAD_REQUEST],
Expand Down
126 changes: 41 additions & 85 deletions tests/Unit/Controller/EndpointControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ protected function getController(array $methods = [], $username = 'username') {
$this->clientService,
$this->push,
])
->setMethods($methods)
->onlyMethods($methods)
->getMock();
}

public function dataListNotifications(): array {
public static function dataListNotifications(): array {
return [
[
'v2',
Expand All @@ -109,19 +109,16 @@ public function dataListNotifications(): array {
[
'v2',
[
1 => $this->getMockBuilder(INotification::class)
->getMock(),
3 => $this->getMockBuilder(INotification::class)
->getMock(),
1,
3,
],
'"' . md5(json_encode([1, 3])) . '"',
[['$notification'], ['$notification']],
],
[
'v2',
[
42 => $this->getMockBuilder(INotification::class)
->getMock(),
42,
],
'"' . md5(json_encode([42])) . '"',
[['$notification']],
Expand All @@ -131,12 +128,10 @@ public function dataListNotifications(): array {

/**
* @dataProvider dataListNotifications
* @param string $apiVersion
* @param array $notifications
* @param string $expectedETag
* @param array $expectedData
*/
public function testListNotifications(string $apiVersion, array $notifications, string $expectedETag, array $expectedData): void {
$notifications = array_fill_keys($notifications, $this->createMock(INotification::class));

$controller = $this->getController([
'notificationToArray',
]);
Expand Down Expand Up @@ -180,15 +175,13 @@ public function testListNotifications(string $apiVersion, array $notifications,
$this->assertSame($expectedData, $response->getData());
}

public function dataListNotificationsThrows() {
public static function dataListNotificationsThrows(): array {
return [
[
'v2',
[
1 => $this->getMockBuilder(INotification::class)
->getMock(),
3 => $this->getMockBuilder(INotification::class)
->getMock(),
1,
3,
],
'"' . md5(json_encode([3])) . '"',
[['$notification']],
Expand All @@ -198,12 +191,10 @@ public function dataListNotificationsThrows() {

/**
* @dataProvider dataListNotificationsThrows
* @param string $apiVersion
* @param array $notifications
* @param string $expectedETag
* @param array $expectedData
*/
public function testListNotificationsThrows($apiVersion, array $notifications, $expectedETag, array $expectedData) {
public function testListNotificationsThrows(string $apiVersion, array $notifications, string $expectedETag, array $expectedData): void {
$notifications = array_fill_keys($notifications, $this->createMock(INotification::class));

$controller = $this->getController([
'notificationToArray',
]);
Expand Down Expand Up @@ -260,7 +251,7 @@ public function testListNotificationsThrows($apiVersion, array $notifications, $
$this->assertSame($expectedData, $response->getData());
}

public function dataListNotificationsNoNotifiers() {
public static function dataListNotificationsNoNotifiers(): array {
return [
['v1'],
['v2'],
Expand All @@ -271,7 +262,7 @@ public function dataListNotificationsNoNotifiers() {
* @dataProvider dataListNotificationsNoNotifiers
* @param string $apiVersion
*/
public function testListNotificationsNoNotifiers($apiVersion) {
public function testListNotificationsNoNotifiers(string $apiVersion): void {
$controller = $this->getController();
$this->manager->expects($this->once())
->method('hasNotifiers')
Expand All @@ -282,7 +273,7 @@ public function testListNotificationsNoNotifiers($apiVersion) {
$this->assertSame(Http::STATUS_NO_CONTENT, $response->getStatus());
}

public function dataGetNotification() {
public static function dataGetNotification(): array {
return [
['v1', 42, 'username1', [['$notification']]],
['v2', 21, 'username2', [['$notification']]],
Expand All @@ -291,11 +282,8 @@ public function dataGetNotification() {

/**
* @dataProvider dataGetNotification
* @param string $apiVersion
* @param int $id
* @param string $username
*/
public function testGetNotification($apiVersion, $id, $username) {
public function testGetNotification(string $apiVersion, int $id, string $username): void {
$controller = $this->getController([
'notificationToArray',
], $username);
Expand Down Expand Up @@ -331,22 +319,22 @@ public function testGetNotification($apiVersion, $id, $username) {
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}

public function dataGetNotificationNoId(): array {
$notification = $this->getMockBuilder(INotification::class)
->getMock();

public static function dataGetNotificationNoId(): array {
return [
['v1', false, 42, false, new NotificationNotFoundException()], // No notifiers
['v1', true, 42, true, new NotificationNotFoundException()], // Not found in database
['v1', true, 42, true, $notification], // Not handled on prepare
['v2', true, 42, true, $notification], // Not handled on prepare
['v1', true, 42, true, null], // Not handled on prepare
['v2', true, 42, true, null], // Not handled on prepare
];
}

/**
* @dataProvider dataGetNotificationNoId
*/
public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, int $id, bool $called, NotificationNotFoundException|INotification $notification): void {
public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers, int $id, bool $called, ?NotificationNotFoundException $notification): void {
if ($notification === null) {
$notification = $this->createMock(INotification::class);
}
$controller = $this->getController();

$this->manager->expects($this->once())
Expand Down Expand Up @@ -381,7 +369,7 @@ public function testGetNotificationNoId(string $apiVersion, bool $hasNotifiers,
$this->assertSame(Http::STATUS_NOT_FOUND, $response->getStatus());
}

public function dataDeleteNotification() {
public static function dataDeleteNotification(): array {
return [
[42, 'username1'],
[21, 'username2'],
Expand All @@ -390,10 +378,8 @@ public function dataDeleteNotification() {

/**
* @dataProvider dataDeleteNotification
* @param int $id
* @param string $username
*/
public function testDeleteNotification($id, $username) {
public function testDeleteNotification(int $id, string $username): void {
$controller = $this->getController([], $username);

$this->handler->expects($this->once())
Expand All @@ -405,7 +391,7 @@ public function testDeleteNotification($id, $username) {
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}

public function testDeleteNotificationNoId() {
public function testDeleteNotificationNoId(): void {
$controller = $this->getController();

$this->handler->expects($this->never())
Expand All @@ -418,10 +404,8 @@ public function testDeleteNotificationNoId() {

/**
* @dataProvider dataDeleteNotification
* @param int $_
* @param string $username
*/
public function testDeleteAllNotifications($_, $username) {
public function testDeleteAllNotifications(int $_, string $username): void {
$controller = $this->getController([], $username);

$this->handler->expects($this->once())
Expand All @@ -438,47 +422,24 @@ public function testDeleteAllNotifications($_, $username) {
$this->assertSame(Http::STATUS_OK, $response->getStatus());
}

public function dataNotificationToArray() {
public static function dataNotificationToArray(): array {
return [
['v1', 42, 'app1', 'user1', 1234, 'type1', '42', 'subject1', '', [], 'message1', 'richMessage 1', ['richMessage param'], 'link1', 'icon1', [], []],
['v1', 1337, 'app2', 'user2', 1337, 'type2', '21', 'subject2', 'richSubject 2', ['richSubject param'], 'message2', '', [], 'link2', 'icon2', [
$this->getMockBuilder(IAction::class)
->getMock(),
$this->getMockBuilder(IAction::class)
->getMock(),
], [['action'], ['action']]],
['v2', 42, 'app1', 'user1', 1234, 'type1', '42', 'subject1', '', [], 'message1', 'richMessage 1', ['richMessage param'], 'link1', 'icon1', [], []],
['v2', 1337, 'app2', 'user2', 1337, 'type2', '21', 'subject2', 'richSubject 2', ['richSubject param'], 'message2', '', [], 'link2', 'icon2', [
$this->getMockBuilder(IAction::class)
->getMock(),
$this->getMockBuilder(IAction::class)
->getMock(),
], [['action'], ['action']]],
['v1', 42, 'app1', 'user1', 1234, 'type1', '42', 'subject1', '', [], 'message1', 'richMessage 1', ['richMessage param'], 'link1', 'icon1', 0, []],
['v1', 1337, 'app2', 'user2', 1337, 'type2', '21', 'subject2', 'richSubject 2', ['richSubject param'], 'message2', '', [], 'link2', 'icon2', 2, [['action'], ['action']]],
['v2', 42, 'app1', 'user1', 1234, 'type1', '42', 'subject1', '', [], 'message1', 'richMessage 1', ['richMessage param'], 'link1', 'icon1', 0, []],
['v2', 1337, 'app2', 'user2', 1337, 'type2', '21', 'subject2', 'richSubject 2', ['richSubject param'], 'message2', '', [], 'link2', 'icon2', 2, [['action'], ['action']]],
];
}

/**
* @dataProvider dataNotificationToArray
*
* @param string $apiVersion
* @param int $id
* @param string $app
* @param string $user
* @param int $timestamp
* @param string $objectType
* @param int $objectId
* @param string $subject
* @param string $subjectRich
* @param array $subjectRichParameters
* @param string $message
* @param string $messageRich
* @param array $messageRichParameters
* @param string $link
* @param string $icon
* @param array $actions
* @param array $actionsExpected
*/
public function testNotificationToArray($apiVersion, $id, $app, $user, $timestamp, $objectType, $objectId, $subject, $subjectRich, $subjectRichParameters, $message, $messageRich, $messageRichParameters, $link, $icon, array $actions, array $actionsExpected) {
public function testNotificationToArray(string $apiVersion, int $id, string $app, string $user, int $timestamp, string $objectType, string $objectId, string $subject, string$subjectRich, array $subjectRichParameters, string $message, string $messageRich, array $messageRichParameters, string $link, string $icon, int $actionsCount, array $actionsExpected): void {
$actions = [];
for ($i = 0; $i < $actionsCount; $i++) {
$actions[] = $this->createMock(IAction::class);
}

$notification = $this->getMockBuilder(INotification::class)
->getMock();

Expand Down Expand Up @@ -575,7 +536,7 @@ public function testNotificationToArray($apiVersion, $id, $app, $user, $timestam
);
}

public function dataActionToArray() {
public static function dataActionToArray(): array {
return [
['label1', 'link1', 'GET', false],
['label2', 'link2', 'POST', true],
Expand All @@ -584,13 +545,8 @@ public function dataActionToArray() {

/**
* @dataProvider dataActionToArray
*
* @param string $label
* @param string $link
* @param string $requestType
* @param bool $isPrimary
*/
public function testActionToArray($label, $link, $requestType, $isPrimary) {
public function testActionToArray(string $label, string $link, string $requestType, bool $isPrimary): void {
$action = $this->getMockBuilder(IAction::class)
->getMock();

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Controller/PushControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function getController(array $methods = []): PushController|MockObject
$this->tokenProvider,
$this->identityProof,
])
->setMethods($methods)
->onlyMethods($methods)
->getMock();
}

Expand Down
47 changes: 7 additions & 40 deletions tests/Unit/PushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function getPush(array $methods = []): Push|MockObject {
$this->timeFactory,
$this->logger,
])
->setMethods($methods)
->onlyMethods($methods)
->getMock();
}

Expand All @@ -109,7 +109,8 @@ protected function getPush(array $methods = []): Push|MockObject {
$this->cacheFactory,
$this->userStatusManager,
$this->l10nFactory,
$this->logger
$this->timeFactory,
$this->logger,
);
}

Expand Down Expand Up @@ -598,45 +599,11 @@ public function testPushToDeviceSending(bool $isDebug): void {
$exception0 = new \Exception();
$client->expects($this->exactly(5))
->method('post')
->withConsecutive(
[
'proxyserver1/notifications',
[
'body' => [
'notifications' => ['["Payload"]', '["Payload"]'],
]
]
],
[
'badrequest/notifications',
[
'body' => [
'notifications' => ['["Payload"]'],
]
]
],
[
'unavailable/notifications',
[
'body' => [
'notifications' => ['["Payload"]'],
]
],
],
[
'ok/notifications',
[
'body' => [
'notifications' => ['["Payload"]'],
]
],
]
)
->willReturnOnConsecutiveCalls(
$this->throwException($exception0),
$this->throwException($exception1),
$this->throwException($exception2),
$response3,
$this->throwException($exception0), // proxyserver1/notifications
$this->throwException($exception1), // badrequest/notifications
$this->throwException($exception2), // unavailable/notifications
$response3, // ok/notifications
$this->throwException($exception4),
);

Expand Down
Loading

0 comments on commit 06a7b8b

Please sign in to comment.