@@ -67,4 +67,54 @@ public function test_assert_json_by_keys_assertion(): void
6767 ->assertJsonByKeys (['id ' => 1 , 'title ' => 'The Odyssee ' ], ['id ' , 'title ' ])
6868 ->assertJsonByKeys (['author ' => ['name ' => 'Homer ' ]], ['author.name ' ]);
6969 }
70+
71+ public function test_update_book (): void
72+ {
73+ $ this ->migrate (
74+ CreateMigrationsTable::class,
75+ CreateBookTable::class,
76+ CreateAuthorTable::class,
77+ );
78+
79+ $ book = Book::create (
80+ title: 'The Odyssee ' ,
81+ author: Author::create (name: 'Homer ' ),
82+ );
83+
84+ $ this ->http
85+ ->post (
86+ uri ([ValidationController::class, 'updateBook ' ], book: 1 ),
87+ body: ['title ' => 'Beyond the Odyssee ' ],
88+ )
89+ ->assertOk ();
90+
91+ $ book ->refresh ();
92+
93+ $ this ->assertSame ($ book ->title , 'Beyond the Odyssee ' );
94+ }
95+
96+ public function test_failing_post_request (): void
97+ {
98+ $ this ->migrate (
99+ CreateMigrationsTable::class,
100+ CreateBookTable::class,
101+ CreateAuthorTable::class,
102+ );
103+
104+ Book::create (
105+ title: 'The Odyssee ' ,
106+ author: Author::create (name: 'Homer ' ),
107+ );
108+
109+ $ this ->http
110+ ->post (
111+ uri ([ValidationController::class, 'updateBook ' ], book: 1 ),
112+ body: ['book ' => ['title ' => 1 ]],
113+ )
114+ ->assertHasJsonValidationError ('title ' , function (array $ errors ): void {
115+ $ this ->assertContains ('Value should be between 1 and 120 ' , $ errors );
116+ });
117+
118+ $ this ->assertSame ('The Odyssee ' , Book::find (id: 1 )->first ()->title );
119+ }
70120}
0 commit comments