Skip to content

Commit

Permalink
fix more issues with unit tests and psalm tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timotheus Pokorra <[email protected]>
  • Loading branch information
tpokorra committed Oct 23, 2023
1 parent 77aa329 commit 655e5ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace OCA\Forms\Controller;

use OCA\Forms\Constants;
use OCA\Forms\Activity\ActivityManager;
use OCA\Forms\Db\Answer;
use OCA\Forms\Db\AnswerMapper;
use OCA\Forms\Db\Form;
Expand Down Expand Up @@ -68,6 +69,7 @@ public function __construct(
string $appName,
IRequest $request,
IUserSession $userSession,
private ActivityManager $activityManager,
private AnswerMapper $answerMapper,
private FormMapper $formMapper,
private OptionMapper $optionMapper,
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function getForm(Form $form): array {
if ($this->currentUser->getUID() && $form->getAllowEdit()) {
$submissionEntity = null;

Check warning on line 184 in lib/Service/FormsService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/FormsService.php#L184

Added line #L184 was not covered by tests
try {
$submissionEntity = $this->submissionMapper->findByFormAndUser($id, $this->currentUser->getUID());
$submissionEntity = $this->submissionMapper->findByFormAndUser($form->getId(), $this->currentUser->getUID());
$answers = $this->getAnswers($form->getId(), $submissionEntity->getId(), $this->currentUser->getUID());
if ($answers !== false) {

Check failure on line 188 in lib/Service/FormsService.php

View workflow job for this annotation

GitHub Actions / Nextcloud

RedundantCondition

lib/Service/FormsService.php:188:9: RedundantCondition: array<array-key, mixed> can never contain false (see https://psalm.dev/122)
$result['answers'] = $answers;
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function time($expected = null) {

namespace OCA\Forms\Tests\Unit\Controller;

use OCA\Forms\Activity\ActivityManager;
use OCA\Forms\Constants;
use OCA\Forms\Controller\ApiController;
use OCA\Forms\Db\AnswerMapper;
Expand Down Expand Up @@ -75,6 +76,8 @@ function time($expected = null) {

class ApiControllerTest extends TestCase {
private ApiController $apiController;
/** @var ActivityManager|MockObject */
private $activityManager;
/** @var AnswerMapper|MockObject */
private $answerMapper;
/** @var FormMapper|MockObject */
Expand Down Expand Up @@ -103,6 +106,7 @@ class ApiControllerTest extends TestCase {
private $l10n;

public function setUp(): void {
$this->activityManager = $this->createMock(ActivityManager::class);
$this->answerMapper = $this->createMock(AnswerMapper::class);
$this->formMapper = $this->createMock(FormMapper::class);
$this->optionMapper = $this->createMock(OptionMapper::class);
Expand All @@ -125,6 +129,7 @@ public function setUp(): void {
'forms',
$this->request,
$this->createUserSession(),
$this->activityManager,
$this->answerMapper,
$this->formMapper,
$this->optionMapper,
Expand Down Expand Up @@ -372,6 +377,7 @@ public function testCreateNewForm($expectedForm) {
->setConstructorArgs(['forms',
$this->request,
$this->createUserSession(),
$this->activityManager,
$this->answerMapper,
$this->formMapper,
$this->optionMapper,
Expand Down Expand Up @@ -531,6 +537,7 @@ public function testCloneForm($old, $new) {
->setConstructorArgs(['forms',
$this->request,
$this->createUserSession(),
$this->activityManager,
$this->answerMapper,
$this->formMapper,
$this->optionMapper,
Expand Down

0 comments on commit 655e5ec

Please sign in to comment.