From b8fbcc2b7050f37b447c3e2acf3b1cd6b5cdaed1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 23 Apr 2020 09:27:48 +0200 Subject: [PATCH] Fix unit tests after #620 Signed-off-by: Joas Schilling --- tests/Unit/Command/GenerateTest.php | 29 ++++++++++++++-------------- tests/Unit/Notifier/NotifierTest.php | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/Unit/Command/GenerateTest.php b/tests/Unit/Command/GenerateTest.php index 3f868153c..d48a7301a 100644 --- a/tests/Unit/Command/GenerateTest.php +++ b/tests/Unit/Command/GenerateTest.php @@ -64,13 +64,13 @@ protected function setUp(): void { public function dataExecute() { return [ - ['user', '', '', false, null, false, null, 123, null, 1], - ['user', '', '', false, null, false, 'user', 123, null, 1], - ['user', str_repeat('a', 256), '', false, null, false, 'user', 123, null, 1], - ['user', 'short', '', true, false, false, 'user', 123, '7b', 0], - ['user', 'short', str_repeat('a', 4001), false, null, false, 'user', 123, null, 1], - ['user', 'short', str_repeat('a', 4000), true, false, true, 'user', 123, '7b', 0], - ['user', 'short', 'long', true, true, true, 'user', 123, '7b', 1], + ['user', '', '', false, null, false, null, false, 1], + ['user', '', '', false, null, false, 'user', false, 1], + ['user', str_repeat('a', 256), '', false, null, false, 'user', false, 1], + ['user', 'short', '', true, false, false, 'user', true, 0], + ['user', 'short', str_repeat('a', 4001), false, null, false, 'user', false, 1], + ['user', 'short', str_repeat('a', 4000), true, false, true, 'user', true, 0], + ['user', 'short', 'long', true, true, true, 'user', true, 1], ]; } @@ -83,11 +83,10 @@ public function dataExecute() { * @param bool $notifyThrows * @param bool $validLong * @param string|null $user - * @param int $time - * @param string|null $hexTime + * @param bool $isCreated * @param int $exitCode */ - public function testExecute($userId, $short, $long, $createNotification, $notifyThrows, $validLong, $user, $time, $hexTime, $exitCode) { + public function testExecute($userId, $short, $long, $createNotification, $notifyThrows, $validLong, $user, $isCreated, $exitCode) { if ($user !== null) { $u = $this->createMock(IUser::class); $u->expects($createNotification ? $this->once() : $this->never()) @@ -101,9 +100,10 @@ public function testExecute($userId, $short, $long, $createNotification, $notify ->with($userId) ->willReturn($u); - $this->timeFactory->expects($hexTime === null ? $this->never() : $this->once()) - ->method('getTime') - ->willReturn($time); + $dateTime = new \DateTime(); + $this->timeFactory->expects(!$isCreated ? $this->never() : $this->once()) + ->method('getDateTime') + ->willReturn($dateTime); if ($createNotification) { $n = $this->createMock(INotification::class); @@ -117,10 +117,11 @@ public function testExecute($userId, $short, $long, $createNotification, $notify ->willReturnSelf(); $n->expects($this->once()) ->method('setDateTime') + ->with($dateTime) ->willReturnSelf(); $n->expects($this->once()) ->method('setObject') - ->with('admin_notifications', $hexTime) + ->with('admin_notifications', dechex($dateTime->getTimestamp())) ->willReturnSelf(); $n->expects($this->once()) ->method('setSubject') diff --git a/tests/Unit/Notifier/NotifierTest.php b/tests/Unit/Notifier/NotifierTest.php index 8f08e87d3..2772d99ac 100644 --- a/tests/Unit/Notifier/NotifierTest.php +++ b/tests/Unit/Notifier/NotifierTest.php @@ -65,7 +65,7 @@ public function testPrepareWrongApp() { /** @var INotification|\PHPUnit_Framework_MockObject_MockObject $notification */ $notification = $this->createMock(INotification::class); - $notification->expects($this->once()) + $notification->expects($this->exactly(2)) ->method('getApp') ->willReturn('notifications'); $notification->expects($this->never())