Skip to content

Commit 80ba040

Browse files
committed
ArticleTypeで扱うのをエンティティからDTO\Request\PostedArticleに変更する
1 parent 0db4027 commit 80ba040

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/Form/ArticleType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Form;
44

5-
use App\Entity\Article;
5+
use App\DTO\Request\PostedArticle;
66
use Symfony\Component\Form\AbstractType;
77
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
88
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
@@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2424
public function configureOptions(OptionsResolver $resolver)
2525
{
2626
$resolver->setDefaults([
27-
'data_class' => Article::class,
27+
'data_class' => PostedArticle::class,
2828
]);
2929
}
3030
}

tests/Form/ArticleTypeTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Tests\Form;
4+
5+
use App\DTO\Request\PostedArticle;
6+
use App\Form\ArticleType;
7+
use Symfony\Component\Form\Test\TypeTestCase;
8+
9+
class ArticleTypeTest extends TypeTestCase
10+
{
11+
public function test_submit()
12+
{
13+
$form = $this->factory->create(ArticleType::class);
14+
$form->submit([
15+
'name' => 'aaa',
16+
'body' => 'bbb',
17+
]);
18+
19+
$this->assertTrue($form->isSubmitted());
20+
$this->assertTrue($form->isValid());
21+
$this->assertInstanceOf(PostedArticle::class, $form->getData());
22+
}
23+
}

0 commit comments

Comments
 (0)