Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: Marvin Winkens <m.winkens@fz-juelich.de>
  • Loading branch information
mwinkens committed Sep 20, 2024
1 parent da28788 commit 702c960
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
55 changes: 27 additions & 28 deletions lib/Command/RemoveNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,47 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RemoveNotifications extends Command
{
protected Manager $manager;
protected LoggerInterface $logger;
public function __construct(Manager $manager, LoggerInterface $logger) {
parent::__construct();
$this->manager = $manager;
$this->logger = $logger;
}
class RemoveNotifications extends Command {
protected Manager $manager;
protected LoggerInterface $logger;
public function __construct(Manager $manager, LoggerInterface $logger) {
parent::__construct();
$this->manager = $manager;
$this->logger = $logger;
}

protected function configure(): void {
$this
->setName('announcementcenter:remove-notifications') # others use minus sign as well
->setDescription('Remove notifications of announcement by id')
->addArgument(
'id',
InputArgument::REQUIRED,
'Id of announcement to remove notifications from',
);
}
protected function configure(): void {
$this
->setName('announcementcenter:remove-notifications') # others use minus sign as well
->setDescription('Remove notifications of announcement by id')
->addArgument(
'id',
InputArgument::REQUIRED,
'Id of announcement to remove notifications from',
);
}

protected function execute(InputInterface $input, OutputInterface $output): int {
try {
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$removeNotId = $this->parseId($input->getArgument('id'));
$this->manager->getAnnouncement($removeNotId, true); # check if announcement exists
$this->manager->removeNotifications($removeNotId);
$this->manager->getAnnouncement($removeNotId, true); # check if announcement exists
$this->manager->removeNotifications($removeNotId);
} catch (AnnouncementDoesNotExistException) {
$output->writeln('Announcement with #' . $removeNotId . ' does not exist!');
return 1;
} catch (InvalidArgumentException $e) {
$output->writeln($e->getMessage());
return 1;
}
$output->writeln('Successfully removed notifications from accouncement #' . $removeNotId);
$output->writeln('Successfully removed notifications from accouncement #' . $removeNotId);
$this->logger->info('Admin removed notifications from announcement #' . $removeNotId . ' over CLI');
return 0;
}
return 0;
}

private function parseId(mixed $value) {
private function parseId(mixed $value) {
if (is_numeric($value)) {
return intval($value);
}
throw new InvalidArgumentException('Id "' . $value . '" is not an integer');
}
}
}
58 changes: 29 additions & 29 deletions tests/Command/RemoveNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,43 @@ protected function setUp(): void {
);
}

public function testRemoveNotificationsSuccessfully() {
$this->input->expects($this->once())
public function testRemoveNotificationsSuccessfully() {
$this->input->expects($this->once())
->method('getArgument')
->with('id')
->willReturn(42);
$this->manager->expects($this->once())
->method('removeNotifications');
$this->manager->expects($this->once())
->method('getAnnouncement');
$this->manager->expects($this->once())
->method('getAnnouncement');
$this->output->expects($this->atLeastOnce())
->method('writeln');
$this->logger->expects($this->atLeastOnce())
$this->logger->expects($this->atLeastOnce())
->method('info');
$result = self::invokePrivate($this->removeNotifictionsCommand, 'execute', [$this->input, $this->output]);
self::assertEquals(0, $result);
}
self::assertEquals(0, $result);
}

public function testRemoveNotificationsInvalidId() {
$this->input->expects($this->once())
->method('getArgument')
->with('id')
->willReturn('invalid');
$result = self::invokePrivate($this->removeNotifictionsCommand, 'execute', [$this->input, $this->output]);
self::assertEquals(true, $result > 0);
}
public function testRemoveNotificationsInvalidId() {
$this->input->expects($this->once())
->method('getArgument')
->with('id')
->willReturn('invalid');
$result = self::invokePrivate($this->removeNotifictionsCommand, 'execute', [$this->input, $this->output]);
self::assertEquals(true, $result > 0);
}

public function testRemoveNotificationsDoesNotExist() {
$this->input->expects($this->once())
->method('getArgument')
->with('id')
->willReturn(42);
$this->manager->expects($this->once())
->method('getAnnouncement')
->willThrowException(new AnnouncementDoesNotExistException('message'));
$this->output->expects($this->atLeastOnce())
->method('writeln');
$result = self::invokePrivate($this->removeNotifictionsCommand, 'execute', [$this->input, $this->output]);
self::assertEquals(true, $result > 0);
}
}
public function testRemoveNotificationsDoesNotExist() {
$this->input->expects($this->once())
->method('getArgument')
->with('id')
->willReturn(42);
$this->manager->expects($this->once())
->method('getAnnouncement')
->willThrowException(new AnnouncementDoesNotExistException('message'));
$this->output->expects($this->atLeastOnce())
->method('writeln');
$result = self::invokePrivate($this->removeNotifictionsCommand, 'execute', [$this->input, $this->output]);
self::assertEquals(true, $result > 0);
}
}

0 comments on commit 702c960

Please sign in to comment.