E
E
EVOSandru62019-12-18 11:06:25
PHPUnit
EVOSandru6, 2019-12-18 11:06:25

Why doesn't a simple Feature test work in laravel?

Hey guys.
Why does Test return an empty $article->id ?
--------------------------------------
Array ([$article->id] => )
_ ------------

class ArticlesController extends Controller
{
    public function update(ArticleRequest $request, Article $article)
    {
        throw new Exception(print_r([
            '$article->id' => $article->id
        ]));
    }
}

class ArticleTest extends TestCase
{
    public function test_article_update_success(): void
    {
        $this->withoutMiddleware();
        $article = factory(Article::class)->create();

        $putArr = [
            'name' => $this->faker->name,
            'body' => $this->faker->sentence,
        ];

        $response = $this->put(route('admin.articles.update', $article), $putArr);

        throw $response->exception;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EVOSandru6, 2019-12-18
@EVOSandru6

$this->withoutMiddleware(VerifyCsrfToken::class);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question