@@ -67,4 +67,52 @@ 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 ->post (
85+ uri ([ValidationController::class, 'updateBook ' ], book: 1 ),
86+ body: ['title ' => 'Beyond the Odyssee ' ],
87+ )
88+ ->assertOk ();
89+
90+ $ book ->refresh ();
91+
92+ $ this ->assertSame ($ book ->title , 'Beyond the Odyssee ' );
93+ }
94+
95+ public function test_failing_post_request (): void
96+ {
97+ $ this ->migrate (
98+ CreateMigrationsTable::class,
99+ CreateBookTable::class,
100+ CreateAuthorTable::class,
101+ );
102+
103+ Book::create (
104+ title: 'The Odyssee ' ,
105+ author: Author::create (name: 'Homer ' ),
106+ );
107+
108+ $ this ->http ->post (
109+ uri ([ValidationController::class, 'updateBook ' ], book: 1 ),
110+ body: ['book ' => ['title ' => 1 ]],
111+ )
112+ ->assertHasJsonValidationError ('title ' , function (array $ errors ): void {
113+ $ this ->assertContains ('Value should be between 1 and 120 ' , $ errors );
114+ });
115+
116+ $ this ->assertSame ('The Odyssee ' , Book::find (id: 1 )->first ()->title );
117+ }
70118}
0 commit comments