File tree Expand file tree Collapse file tree
tests/Service/UseCase/Article Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \DTO \Request ;
4+
5+ use App \Model \PostedArticleInterface ;
6+ use Symfony \Component \Validator \Constraints as Assert ;
7+
8+ class PostedArticle implements PostedArticleInterface
9+ {
10+ /**
11+ * @var string|null
12+ * @Assert\NotBlank
13+ * @Assert\Length(max=255)
14+ */
15+ private $ name ;
16+
17+ /**
18+ * @var string|null
19+ * @Assert\Length(max=1000)
20+ */
21+ private $ body ;
22+
23+ /**
24+ * @return string|null
25+ */
26+ public function getName (): ?string
27+ {
28+ return $ this ->name ;
29+ }
30+
31+ /**
32+ * @param string|null $name
33+ * @return PostedArticle
34+ */
35+ public function setName ($ name )
36+ {
37+ $ this ->name = $ name ;
38+
39+ return $ this ;
40+ }
41+
42+ /**
43+ * @return string|null
44+ */
45+ public function getBody (): ?string
46+ {
47+ return $ this ->body ;
48+ }
49+
50+ /**
51+ * @param string|null $body
52+ * @return PostedArticle
53+ */
54+ public function setBody ($ body )
55+ {
56+ $ this ->body = $ body ;
57+
58+ return $ this ;
59+ }
60+ }
Original file line number Diff line number Diff line change 22
33namespace App \Entity ;
44
5+ use App \Model \ArticleInterface ;
56use DateTimeInterface as DateTimeInterfaceAlias ;
67use Doctrine \ORM \Mapping as ORM ;
7- use Symfony \Component \Validator \Constraints as Assert ;
88
99/**
1010 * @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
1111 * @ORM\HasLifecycleCallbacks()
1212 */
13- class Article
13+ class Article implements ArticleInterface
1414{
1515 /**
1616 * @ORM\Id()
@@ -21,14 +21,11 @@ class Article
2121
2222 /**
2323 * @ORM\Column(type="string", length=255)
24- * @Assert\NotBlank
25- * @Assert\Length(max=255)
2624 */
2725 private $ name ;
2826
2927 /**
3028 * @ORM\Column(type="text")
31- * @Assert\Length(max=1000)
3229 */
3330 private $ body ;
3431
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Service \UseCase \Article \Exception ;
4+
5+ class RegisterException extends \Exception
6+ {
7+
8+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Service \UseCase \Article ;
4+
5+ use App \DTO \Request \PostedArticle ;
6+ use App \Entity \Article ;
7+ use App \Model \ArticlePersisterInterface ;
8+ use App \Service \UseCase \Article \Exception \RegisterException ;
9+
10+ class RegisterUseCase
11+ {
12+ /**
13+ * @var ArticlePersisterInterface
14+ */
15+ private $ articlePersister ;
16+
17+ /**
18+ * @param ArticlePersisterInterface $articlePersister
19+ */
20+ public function __construct (ArticlePersisterInterface $ articlePersister )
21+ {
22+ $ this ->articlePersister = $ articlePersister ;
23+ }
24+
25+ /**
26+ * @param PostedArticle $postedArticle
27+ * @throws RegisterException
28+ */
29+ public function register (PostedArticle $ postedArticle ): void
30+ {
31+ try {
32+ $ this ->articlePersister ->persist ($ postedArticle , new Article ());
33+ } catch (\Exception $ e ) {
34+ throw new RegisterException ($ e ->getMessage (), '' , $ e );
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Tests \Service \UseCase \Article ;
4+
5+ use App \Model \ArticlePersisterInterface ;
6+ use PHPUnit \Framework \TestCase ;
7+ use Prophecy \Prophecy \ObjectProphecy ;
8+
9+ class RegisterUseCaseTest extends TestCase
10+ {
11+ /**
12+ * @var ArticlePersisterInterface|ObjectProphecy
13+ */
14+ private $ articlePersisterP ;
15+ }
You can’t perform that action at this time.
0 commit comments