Skip to content

Commit 3178465

Browse files
committed
Update tests
1 parent 3733070 commit 3178465

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Form/Review/AddCommentFormType.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4343
$builder->add(
4444
'lineReference',
4545
HiddenType::class,
46-
[
47-
'data' => (string)$lineReference,
48-
'setter' => static function (Comment $comment, string $value): void {
49-
$lineReference = LineReference::fromString($value);
50-
$comment->setLineReference($lineReference);
51-
$comment->setFilePath(Assert::notNull($lineReference->oldPath ?? $lineReference->newPath));
52-
},
53-
]
46+
['data' => (string)$lineReference, 'setter' => $this->setter(...)]
5447
);
5548
$builder->add(
5649
'message',
@@ -63,4 +56,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6356
$builder->add('tag', CommentTagType::class);
6457
$builder->add('save', SubmitType::class, ['label' => 'add.comment']);
6558
}
59+
60+
public function setter(Comment $comment, string $value): void
61+
{
62+
$lineReference = LineReference::fromString($value);
63+
$comment->setLineReference($lineReference);
64+
$comment->setFilePath(Assert::notNull($lineReference->oldPath ?? $lineReference->newPath));
65+
}
6666
}

tests/Unit/Form/Review/AddCommentFormTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use DR\Review\Controller\App\Review\Comment\AddCommentController;
77
use DR\Review\Entity\Review\CodeReview;
8+
use DR\Review\Entity\Review\Comment;
89
use DR\Review\Entity\Review\LineReference;
910
use DR\Review\Form\Review\AddCommentFormType;
1011
use DR\Review\Form\Review\CommentTagType;
@@ -74,4 +75,13 @@ public function testBuildForm(): void
7475

7576
$this->type->buildForm($builder, ['review' => $review, 'lineReference' => $lineReference]);
7677
}
78+
79+
public function testSetter(): void
80+
{
81+
$reference = 'old/path:new/path:1:2:3:commitSha:A';
82+
$comment = new Comment();
83+
$this->type->setter($comment, $reference);
84+
static::assertEquals(LineReference::fromString($reference), $comment->getLineReference());
85+
static::assertSame('old/path', $comment->getFilePath());
86+
}
7787
}

0 commit comments

Comments
 (0)