diff options
Diffstat (limited to 'tests/lib/Notification/NotificationTest.php')
-rw-r--r-- | tests/lib/Notification/NotificationTest.php | 156 |
1 files changed, 77 insertions, 79 deletions
diff --git a/tests/lib/Notification/NotificationTest.php b/tests/lib/Notification/NotificationTest.php index 957d74233be..cebe9d51021 100644 --- a/tests/lib/Notification/NotificationTest.php +++ b/tests/lib/Notification/NotificationTest.php @@ -30,7 +30,7 @@ class NotificationTest extends TestCase { $this->notification = new Notification($this->validator, $this->richTextFormatter); } - protected function dataValidString($maxLength) { + protected static function dataValidString($maxLength): array { $dataSets = [ ['test1'], ['1564'], @@ -42,7 +42,7 @@ class NotificationTest extends TestCase { return $dataSets; } - protected function dataInvalidString($maxLength) { + protected static function dataInvalidString($maxLength): array { $dataSets = [ [''] ]; @@ -52,29 +52,29 @@ class NotificationTest extends TestCase { return $dataSets; } - public function dataSetApp() { - return $this->dataValidString(32); + public static function dataSetApp(): array { + return self::dataValidString(32); } /** - * @dataProvider dataSetApp * @param string $app */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetApp')] public function testSetApp($app): void { $this->assertSame('', $this->notification->getApp()); $this->assertSame($this->notification, $this->notification->setApp($app)); $this->assertSame($app, $this->notification->getApp()); } - public function dataSetAppInvalid() { - return $this->dataInvalidString(32); + public static function dataSetAppInvalid(): array { + return self::dataInvalidString(32); } /** - * @dataProvider dataSetAppInvalid * @param mixed $app * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetAppInvalid')] public function testSetAppInvalid($app): void { $this->expectException(\InvalidArgumentException::class); @@ -82,36 +82,36 @@ class NotificationTest extends TestCase { } - public function dataSetUser() { - return $this->dataValidString(64); + public static function dataSetUser(): array { + return self::dataValidString(64); } /** - * @dataProvider dataSetUser * @param string $user */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetUser')] public function testSetUser($user): void { $this->assertSame('', $this->notification->getUser()); $this->assertSame($this->notification, $this->notification->setUser($user)); $this->assertSame($user, $this->notification->getUser()); } - public function dataSetUserInvalid() { - return $this->dataInvalidString(64); + public static function dataSetUserInvalid(): array { + return self::dataInvalidString(64); } /** - * @dataProvider dataSetUserInvalid * @param mixed $user * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetUserInvalid')] public function testSetUserInvalid($user): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setUser($user); } - public function dataSetDateTime() { + public static function dataSetDateTime(): array { $past = new \DateTime(); $past->sub(new \DateInterval('P1Y')); $current = new \DateTime(); @@ -126,16 +126,16 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetDateTime * @param \DateTime $dateTime */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetDateTime')] public function testSetDateTime(\DateTime $dateTime): void { $this->assertSame(0, $this->notification->getDateTime()->getTimestamp()); $this->assertSame($this->notification, $this->notification->setDateTime($dateTime)); $this->assertSame($dateTime, $this->notification->getDateTime()); } - public function dataSetDateTimeZero() { + public static function dataSetDateTimeZero(): array { $nineTeenSeventy = new \DateTime(); $nineTeenSeventy->setTimestamp(0); return [ @@ -144,18 +144,17 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetDateTimeZero * @param \DateTime $dateTime - * * @expectedMessage 'The given date time is invalid' */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetDateTimeZero')] public function testSetDateTimeZero($dateTime): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setDateTime($dateTime); } - public function dataSetObject() { + public static function dataSetObject(): array { return [ ['a', '21'], [str_repeat('a', 64), '42'], @@ -163,10 +162,10 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetObject * @param string $type * @param string $id */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetObject')] public function testSetObject($type, $id): void { $this->assertSame('', $this->notification->getObjectType()); $this->assertSame('', $this->notification->getObjectId()); @@ -175,11 +174,11 @@ class NotificationTest extends TestCase { $this->assertSame($id, $this->notification->getObjectId()); } - public function dataSetObjectTypeInvalid() { - return $this->dataInvalidString(64); + public static function dataSetObjectTypeInvalid(): array { + return self::dataInvalidString(64); } - public function dataSetObjectIdInvalid() { + public static function dataSetObjectIdInvalid(): array { return [ [''], [str_repeat('a', 64 + 1)], @@ -187,18 +186,17 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetObjectIdInvalid * @param mixed $id - * * @expectedMessage 'The given object id is invalid' */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetObjectIdInvalid')] public function testSetObjectIdInvalid($id): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setObject('object', $id); } - public function dataSetSubject() { + public static function dataSetSubject(): array { return [ ['a', []], [str_repeat('a', 64), [str_repeat('a', 160)]], @@ -207,10 +205,10 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetSubject * @param string $subject * @param array $parameters */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetSubject')] public function testSetSubject($subject, $parameters): void { $this->assertSame('', $this->notification->getSubject()); $this->assertSame([], $this->notification->getSubjectParameters()); @@ -219,51 +217,51 @@ class NotificationTest extends TestCase { $this->assertSame($parameters, $this->notification->getSubjectParameters()); } - public function dataSetSubjectInvalidSubject() { - return $this->dataInvalidString(64); + public static function dataSetSubjectInvalidSubject(): array { + return self::dataInvalidString(64); } /** - * @dataProvider dataSetSubjectInvalidSubject * @param mixed $subject * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetSubjectInvalidSubject')] public function testSetSubjectInvalidSubject($subject): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setSubject($subject, []); } - public function dataSetParsedSubject() { - return $this->dataValidString(false); + public static function dataSetParsedSubject(): array { + return self::dataValidString(false); } /** - * @dataProvider dataSetParsedSubject * @param string $subject */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetParsedSubject')] public function testSetParsedSubject($subject): void { $this->assertSame('', $this->notification->getParsedSubject()); $this->assertSame($this->notification, $this->notification->setParsedSubject($subject)); $this->assertSame($subject, $this->notification->getParsedSubject()); } - public function dataSetParsedSubjectInvalid() { - return $this->dataInvalidString(false); + public static function dataSetParsedSubjectInvalid(): array { + return self::dataInvalidString(false); } /** - * @dataProvider dataSetParsedSubjectInvalid * @param mixed $subject * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetParsedSubjectInvalid')] public function testSetParsedSubjectInvalid($subject): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setParsedSubject($subject); } - public function dataSetMessage() { + public static function dataSetMessage(): array { return [ ['a', []], [str_repeat('a', 64), [str_repeat('a', 160)]], @@ -272,10 +270,10 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataSetMessage * @param string $message * @param array $parameters */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetMessage')] public function testSetMessage($message, $parameters): void { $this->assertSame('', $this->notification->getMessage()); $this->assertSame([], $this->notification->getMessageParameters()); @@ -284,102 +282,102 @@ class NotificationTest extends TestCase { $this->assertSame($parameters, $this->notification->getMessageParameters()); } - public function dataSetMessageInvalidMessage() { - return $this->dataInvalidString(64); + public static function dataSetMessageInvalidMessage(): array { + return self::dataInvalidString(64); } /** - * @dataProvider dataSetMessageInvalidMessage * @param mixed $message * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetMessageInvalidMessage')] public function testSetMessageInvalidMessage($message): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setMessage($message, []); } - public function dataSetParsedMessage() { - return $this->dataValidString(false); + public static function dataSetParsedMessage(): array { + return self::dataValidString(false); } /** - * @dataProvider dataSetParsedMessage * @param string $message */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetParsedMessage')] public function testSetParsedMessage($message): void { $this->assertSame('', $this->notification->getParsedMessage()); $this->assertSame($this->notification, $this->notification->setParsedMessage($message)); $this->assertSame($message, $this->notification->getParsedMessage()); } - public function dataSetParsedMessageInvalid() { - return $this->dataInvalidString(false); + public static function dataSetParsedMessageInvalid(): array { + return self::dataInvalidString(false); } /** - * @dataProvider dataSetParsedMessageInvalid * @param mixed $message * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetParsedMessageInvalid')] public function testSetParsedMessageInvalid($message): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setParsedMessage($message); } - public function dataSetLink() { - return $this->dataValidString(4000); + public static function dataSetLink(): array { + return self::dataValidString(4000); } /** - * @dataProvider dataSetLink * @param string $link */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetLink')] public function testSetLink($link): void { $this->assertSame('', $this->notification->getLink()); $this->assertSame($this->notification, $this->notification->setLink($link)); $this->assertSame($link, $this->notification->getLink()); } - public function dataSetLinkInvalid() { - return $this->dataInvalidString(4000); + public static function dataSetLinkInvalid(): array { + return self::dataInvalidString(4000); } /** - * @dataProvider dataSetLinkInvalid * @param mixed $link * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetLinkInvalid')] public function testSetLinkInvalid($link): void { $this->expectException(\InvalidArgumentException::class); $this->notification->setLink($link); } - public function dataSetIcon() { - return $this->dataValidString(4000); + public static function dataSetIcon(): array { + return self::dataValidString(4000); } /** - * @dataProvider dataSetIcon * @param string $icon */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetIcon')] public function testSetIcon($icon): void { $this->assertSame('', $this->notification->getIcon()); $this->assertSame($this->notification, $this->notification->setIcon($icon)); $this->assertSame($icon, $this->notification->getIcon()); } - public function dataSetIconInvalid() { - return $this->dataInvalidString(4000); + public static function dataSetIconInvalid(): array { + return self::dataInvalidString(4000); } /** - * @dataProvider dataSetIconInvalid * @param mixed $icon * */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetIconInvalid')] public function testSetIconInvalid($icon): void { $this->expectException(\InvalidArgumentException::class); @@ -392,7 +390,7 @@ class NotificationTest extends TestCase { } public function testAddAction(): void { - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->once()) ->method('isValid') @@ -410,7 +408,7 @@ class NotificationTest extends TestCase { public function testAddActionInvalid(): void { $this->expectException(\InvalidArgumentException::class); - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->once()) ->method('isValid') @@ -422,7 +420,7 @@ class NotificationTest extends TestCase { } public function testAddActionSecondPrimary(): void { - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->exactly(2)) ->method('isValid') @@ -438,7 +436,7 @@ class NotificationTest extends TestCase { } public function testAddParsedAction(): void { - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->once()) ->method('isValidParsed') @@ -456,7 +454,7 @@ class NotificationTest extends TestCase { public function testAddParsedActionInvalid(): void { $this->expectException(\InvalidArgumentException::class); - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->once()) ->method('isValidParsed') @@ -468,7 +466,7 @@ class NotificationTest extends TestCase { } public function testAddActionSecondParsedPrimary(): void { - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action = $this->createMock(IAction::class); $action->expects($this->exactly(2)) ->method('isValidParsed') @@ -484,7 +482,7 @@ class NotificationTest extends TestCase { } public function testAddActionParsedPrimaryEnd(): void { - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action1 = $this->createMock(IAction::class); $action1->expects($this->exactly(2)) ->method('isValidParsed') @@ -492,7 +490,7 @@ class NotificationTest extends TestCase { $action1->expects($this->exactly(2)) ->method('isPrimary') ->willReturn(false); - /** @var \OCP\Notification\IAction|\PHPUnit\Framework\MockObject\MockObject $action */ + /** @var IAction|\PHPUnit\Framework\MockObject\MockObject $action */ $action2 = $this->createMock(IAction::class); $action2->expects($this->once()) ->method('isValidParsed') @@ -508,7 +506,7 @@ class NotificationTest extends TestCase { $this->assertEquals([$action2, $action1, $action1], $this->notification->getParsedActions()); } - public function dataIsValid() { + public static function dataIsValid(): array { return [ [false, '', false], [true, '', false], @@ -518,16 +516,16 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataIsValid * * @param bool $isValidCommon * @param string $subject * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsValid')] public function testIsValid($isValidCommon, $subject, $expected): void { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ $notification = $this->getMockBuilder(Notification::class) - ->setMethods([ + ->onlyMethods([ 'isValidCommon', 'getSubject', 'getParsedSubject', @@ -551,16 +549,16 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataIsValid * * @param bool $isValidCommon * @param string $subject * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsValid')] public function testIsParsedValid($isValidCommon, $subject, $expected): void { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ $notification = $this->getMockBuilder(Notification::class) - ->setMethods([ + ->onlyMethods([ 'isValidCommon', 'getParsedSubject', 'getSubject', @@ -583,7 +581,7 @@ class NotificationTest extends TestCase { $this->assertEquals($expected, $notification->isValidParsed()); } - public function dataIsValidCommon() { + public static function dataIsValidCommon(): array { return [ ['', '', 0, '', '', false], ['app', '', 0, '', '', false], @@ -595,7 +593,6 @@ class NotificationTest extends TestCase { } /** - * @dataProvider dataIsValidCommon * * @param string $app * @param string $user @@ -604,10 +601,11 @@ class NotificationTest extends TestCase { * @param string $objectId * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsValidCommon')] public function testIsValidCommon($app, $user, $timestamp, $objectType, $objectId, $expected): void { - /** @var \OCP\Notification\INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ + /** @var INotification|\PHPUnit\Framework\MockObject\MockObject $notification */ $notification = $this->getMockBuilder(Notification::class) - ->setMethods([ + ->onlyMethods([ 'getApp', 'getUser', 'getDateTime', |