Add strict type on Notifications tests (#15935)
Add strict type on Notifications tests
This commit is contained in:
commit
bf18f1ee93
|
@ -125,6 +125,7 @@ class NotificationsTest extends TestCase {
|
|||
|
||||
$file = $this->createMock(Node::class);
|
||||
$folder = $this->createMock(Folder::class);
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$this->rootFolder->expects($this->once())
|
||||
->method('getUserFolder')
|
||||
|
@ -136,7 +137,11 @@ class NotificationsTest extends TestCase {
|
|||
|
||||
$this->session->expects($this->once())
|
||||
->method('getUser')
|
||||
->willReturn($this->createMock(IUser::class));
|
||||
->willReturn($user);
|
||||
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('user');
|
||||
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->any())
|
||||
|
@ -163,9 +168,15 @@ class NotificationsTest extends TestCase {
|
|||
$this->rootFolder->expects($this->never())
|
||||
->method('getUserFolder');
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$this->session->expects($this->once())
|
||||
->method('getUser')
|
||||
->willReturn($this->createMock(IUser::class));
|
||||
->willReturn($user);
|
||||
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('user');
|
||||
|
||||
$this->notificationManager->expects($this->never())
|
||||
->method('createNotification');
|
||||
|
@ -197,9 +208,15 @@ class NotificationsTest extends TestCase {
|
|||
->method('getById')
|
||||
->willReturn([]);
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
$this->session->expects($this->once())
|
||||
->method('getUser')
|
||||
->willReturn($this->createMock(IUser::class));
|
||||
->willReturn($user);
|
||||
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('user');
|
||||
|
||||
$notification = $this->createMock(INotification::class);
|
||||
$notification->expects($this->any())
|
||||
|
|
|
@ -135,7 +135,7 @@ class Notification implements INotification {
|
|||
* @since 8.2.0
|
||||
*/
|
||||
public function setApp(string $app) {
|
||||
if (!is_string($app) || $app === '' || isset($app[32])) {
|
||||
if (trim($app) === '' || isset($app[32])) {
|
||||
throw new \InvalidArgumentException('The given app name is invalid');
|
||||
}
|
||||
$this->app = $app;
|
||||
|
@ -157,7 +157,7 @@ class Notification implements INotification {
|
|||
* @since 8.2.0
|
||||
*/
|
||||
public function setUser(string $user) {
|
||||
if (!is_string($user) || $user === '' || isset($user[64])) {
|
||||
if (trim($user) === '' || isset($user[64])) {
|
||||
throw new \InvalidArgumentException('The given user id is invalid');
|
||||
}
|
||||
$this->user = $user;
|
||||
|
@ -201,8 +201,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the object type or id is invalid
|
||||
* @since 8.2.0 - 9.0.0: Type of $id changed to string
|
||||
*/
|
||||
public function setObject($type, $id) {
|
||||
if (!is_string($type) || $type === '' || isset($type[64])) {
|
||||
public function setObject(string $type, $id) {
|
||||
if (trim($type) === '' || isset($type[64])) {
|
||||
throw new \InvalidArgumentException('The given object type is invalid');
|
||||
}
|
||||
$this->objectType = $type;
|
||||
|
@ -237,8 +237,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the subject or parameters are invalid
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setSubject($subject, array $parameters = []) {
|
||||
if (!is_string($subject) || $subject === '' || isset($subject[64])) {
|
||||
public function setSubject(string $subject, array $parameters = []) {
|
||||
if (trim($subject) === '' || isset($subject[64])) {
|
||||
throw new \InvalidArgumentException('The given subject is invalid');
|
||||
}
|
||||
|
||||
|
@ -270,8 +270,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the subject is invalid
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setParsedSubject($subject) {
|
||||
if (!is_string($subject) || $subject === '') {
|
||||
public function setParsedSubject(string $subject) {
|
||||
if (trim($subject) === '') {
|
||||
throw new \InvalidArgumentException('The given parsed subject is invalid');
|
||||
}
|
||||
$this->subjectParsed = $subject;
|
||||
|
@ -293,8 +293,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the subject or parameters are invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setRichSubject($subject, array $parameters = []) {
|
||||
if (!is_string($subject) || $subject === '') {
|
||||
public function setRichSubject(string $subject, array $parameters = []) {
|
||||
if (trim($subject) === '') {
|
||||
throw new \InvalidArgumentException('The given parsed subject is invalid');
|
||||
}
|
||||
|
||||
|
@ -327,8 +327,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setMessage($message, array $parameters = []) {
|
||||
if (!is_string($message) || $message === '' || isset($message[64])) {
|
||||
public function setMessage(string $message, array $parameters = []) {
|
||||
if (trim($message) === '' || isset($message[64])) {
|
||||
throw new \InvalidArgumentException('The given message is invalid');
|
||||
}
|
||||
|
||||
|
@ -360,8 +360,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the message is invalid
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setParsedMessage($message) {
|
||||
if (!is_string($message) || $message === '') {
|
||||
public function setParsedMessage(string $message) {
|
||||
if (trim($message) === '') {
|
||||
throw new \InvalidArgumentException('The given parsed message is invalid');
|
||||
}
|
||||
$this->messageParsed = $message;
|
||||
|
@ -383,8 +383,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setRichMessage($message, array $parameters = []) {
|
||||
if (!is_string($message) || $message === '') {
|
||||
public function setRichMessage(string $message, array $parameters = []) {
|
||||
if (trim($message) === '') {
|
||||
throw new \InvalidArgumentException('The given parsed message is invalid');
|
||||
}
|
||||
|
||||
|
@ -416,8 +416,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the link is invalid
|
||||
* @since 8.2.0
|
||||
*/
|
||||
public function setLink($link) {
|
||||
if (!is_string($link) || $link === '' || isset($link[4000])) {
|
||||
public function setLink(string $link) {
|
||||
if (trim($link) === '' || isset($link[4000])) {
|
||||
throw new \InvalidArgumentException('The given link is invalid');
|
||||
}
|
||||
$this->link = $link;
|
||||
|
@ -438,8 +438,8 @@ class Notification implements INotification {
|
|||
* @throws \InvalidArgumentException if the icon is invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setIcon($icon) {
|
||||
if (!is_string($icon) || $icon === '' || isset($icon[4000])) {
|
||||
public function setIcon(string $icon) {
|
||||
if (trim($icon) === '' || isset($icon[4000])) {
|
||||
throw new \InvalidArgumentException('The given icon is invalid');
|
||||
}
|
||||
$this->icon = $icon;
|
||||
|
|
|
@ -80,7 +80,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the object type or id is invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setObject($type, $id);
|
||||
public function setObject(string $type, $id);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -101,7 +101,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the subject or parameters are invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setSubject($subject, array $parameters = []);
|
||||
public function setSubject(string $subject, array $parameters = []);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -132,7 +132,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the subject is invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setParsedSubject($subject);
|
||||
public function setParsedSubject(string $subject);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -157,7 +157,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the subject or parameters are invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setRichSubject($subject, array $parameters = []);
|
||||
public function setRichSubject(string $subject, array $parameters = []);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -178,7 +178,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setMessage($message, array $parameters = []);
|
||||
public function setMessage(string $message, array $parameters = []);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -209,7 +209,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the message is invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setParsedMessage($message);
|
||||
public function setParsedMessage(string $message);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -234,7 +234,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the message or parameters are invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setRichMessage($message, array $parameters = []);
|
||||
public function setRichMessage(string $message, array $parameters = []);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -254,7 +254,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the link is invalid
|
||||
* @since 9.0.0
|
||||
*/
|
||||
public function setLink($link);
|
||||
public function setLink(string $link);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
@ -268,7 +268,7 @@ interface INotification {
|
|||
* @throws \InvalidArgumentException if the icon is invalid
|
||||
* @since 11.0.0
|
||||
*/
|
||||
public function setIcon($icon);
|
||||
public function setIcon(string $icon);
|
||||
|
||||
/**
|
||||
* @return string
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
declare (strict_types = 1);
|
||||
/**
|
||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||
*
|
||||
|
@ -43,6 +44,7 @@ class NotificationTest extends TestCase {
|
|||
protected function dataValidString($maxLength) {
|
||||
$dataSets = [
|
||||
['test1'],
|
||||
['1564'],
|
||||
[str_repeat('a', 1)],
|
||||
];
|
||||
if ($maxLength !== false) {
|
||||
|
@ -53,20 +55,24 @@ class NotificationTest extends TestCase {
|
|||
|
||||
protected function dataInvalidString($maxLength) {
|
||||
$dataSets = [
|
||||
[true],
|
||||
[false],
|
||||
[0],
|
||||
[1],
|
||||
[''],
|
||||
[[]],
|
||||
['']
|
||||
];
|
||||
if ($maxLength !== false) {
|
||||
$dataSets[] = [str_repeat('a', $maxLength + 1)];
|
||||
$dataSets[] = [[str_repeat('a', $maxLength + 1)]];
|
||||
}
|
||||
return $dataSets;
|
||||
}
|
||||
|
||||
protected function dataInvalidStringType() {
|
||||
return [
|
||||
[true],
|
||||
[false],
|
||||
[16412],
|
||||
[[]],
|
||||
[null],
|
||||
];
|
||||
}
|
||||
|
||||
protected function dataInvalidInt() {
|
||||
return [
|
||||
[true],
|
||||
|
@ -98,6 +104,10 @@ class NotificationTest extends TestCase {
|
|||
return $this->dataInvalidString(32);
|
||||
}
|
||||
|
||||
public function dataSetAppInvalidType() {
|
||||
return $this->dataInvalidStringType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSetAppInvalid
|
||||
* @param mixed $app
|
||||
|
@ -108,6 +118,17 @@ class NotificationTest extends TestCase {
|
|||
$this->notification->setApp($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSetAppInvalidType
|
||||
* @param mixed $app
|
||||
*
|
||||
* @expectedException \TypeError
|
||||
*/
|
||||
public function testSetAppInvalidType($app) {
|
||||
$this->notification->setApp($app);
|
||||
}
|
||||
|
||||
|
||||
public function dataSetUser() {
|
||||
return $this->dataValidString(64);
|
||||
}
|
||||
|
@ -126,6 +147,10 @@ class NotificationTest extends TestCase {
|
|||
return $this->dataInvalidString(64);
|
||||
}
|
||||
|
||||
public function dataSetUserInvalidType() {
|
||||
return $this->dataInvalidStringType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSetUserInvalid
|
||||
* @param mixed $user
|
||||
|
@ -136,6 +161,16 @@ class NotificationTest extends TestCase {
|
|||
$this->notification->setUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataSetUserInvalidType
|
||||
* @param mixed $user
|
||||
*
|
||||
* @expectedException \TypeError
|
||||
*/
|
||||
public function testSetUserInvalidType($user) {
|
||||
$this->notification->setUser($user);
|
||||
}
|
||||
|
||||
public function dataSetDateTime() {
|
||||
$past = new \DateTime();
|
||||
$past->sub(new \DateInterval('P1Y'));
|
||||
|
|
Loading…
Reference in New Issue