Kodaf's avatar
Level 19

Laravel PHPUnit test error

I'm follow this series https://laracasts.com/series/build-a-laravel-app-with-tdd .

I got the following error:

Tests\Feature\ProjectsTest::a_user_can_create_a_project Illuminate\Session\TokenMismatchException: CSRF token mismatch.

	/** @test */
	public function a_user_can_create_a_project()
	{
		$this->withoutExceptionHandling();

		$this->actingAs(factory('App\User')->create());

		$attributes = [
			'title' => $this->faker->sentence,
			'description' => $this->faker->paragraph,
		];

		$this->post('projects', $attributes)->assertRedirect('projects');

		$this->assertDatabaseHas('projects', $attributes);

		$this->get('projects')->assertSee($attributes['title']);
	}
0 likes
8 replies
Sinnbeck's avatar

Why are you disabling exception handling?

Try removing this

$this->withoutExceptionHandling();
Kodaf's avatar
Level 19

Now i got: Tests\Feature\ProjectsTest::a_user_can_create_a_project Response status code [419] is not a redirect status code. Failed asserting that false is true.

tykus's avatar

The VerifyCsrfToken middleware should be automatically disabled whenever you re running tests; why is it throwing an exception? Do you have the APP_ENV environment variable set to testing?

Kodaf's avatar
Level 19

in phpunit.xml i have line

<server name="APP_ENV" value="testing"/>
tykus's avatar

And is that configuration being read; un phpunit with the -vvv option to see which configuration file is used?

Kodaf's avatar
Level 19

Yes, i got line with configuration path. Configuration: E:\birdboard\phpunit.xml

Kodaf's avatar
Level 19

Solved. I used command php artisan config:clear and all tests passed.

tykus's avatar
tykus
Best Answer
Level 104

Great! You don't need to cache your config in development.

Please or to participate in this conversation.