и если есть лучший способ провести тест, сообщите мне, пожалуйста, заранее спасибо
Маршруты
Код: Выделить всё
Route::group(['prefix' => 'categories' , 'namespace' => 'App\Http\Controllers\Admin'] , function () {
Route::post('create', 'CategoryController@store')->name('category.store');
Route::put('update/{category}', 'CategoryController@update')->name('category.update');
});
Контроллер
Код: Выделить всё
public function update(Request $request , Category $category)
{
$category->update($request->all());
}
Код: Выделить всё
/** @test */
public function a_category_can_be_updated()
{
$this->withoutExceptionHandling();
$this->post(
route('category.store'),
[
'name' => 'Food',
'slug' => 'food-and-drinks',
],
);
$category = Category::first();
$this->put(
route('category.update', $category->id),
[
'name' => 'Food and',
],
);
// dd($category);
$this->assertEquals('Food and', $category->name);
$this->assertEquals('Food-and', $category->slug);
}
Код: Выделить всё
• Tests\Feature\CategoriesTest > a category can be updated
Failed asserting that two strings are equal.
at F:\newProject\tests\Feature\CategoriesTest.php:66
62▕ ],
63▕ );
64▕ // dd($category);
65▕
➜ 66▕ $this->assertEquals('Food and', $category->name);
67▕ $this->assertEquals('Food-and', $category->slug);
68▕ }
69▕ }
70▕
1 F:\newProject\vendor\phpunit\phpunit\phpunit:61
PHPUnit\TextUI\Command::main()
--- Expected
+++ Actual
@@ @@
-'Food and'
+'Food'
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/65818126/laravel-phpunit-fails-the-update-method-i-dont-know-why[/url]
Мобильная версия