Can you please share the error that you have? What do you use to run the tests?
Have you tried with .:
./vendor/bin/phpunit /tests/feature/ProjectTest.php
Please how can i run test on windows. My test command "/vendor/bin/phpunit /tests/feature/ProjectTest.php" is failing. Please help.
Can you please share the error that you have? What do you use to run the tests?
Have you tried with .:
./vendor/bin/phpunit /tests/feature/ProjectTest.php
This is the command C:\xampp\htdocs\laravel\birdboard>./vendor/bin/phpunit /tests/feature/ProjectTest.php and the response is '.' is not recognized as an internal or external command, operable program or batch file.
And then another command C:\xampp\htdocs\laravel\birdboard>/vendor/bin/phpunit /tests/feature/ProjectTest.php and response is The system cannot find the path specified.
Yes and i'm on windows
Try
/vendor/bin/phpunit --filter=ProjectTest
Not too sure if it will work. On the mac I would do:
./vendor/bin/phpunit --filter=ProjectTest
Also, have you managed to run any tests. To run all tests - on the mac - you would do
./vendor/bin/phpunit
Update: after a bit of surfing it looks like you should probably just do:
vendor\bin\phpunit --filter=ProjectTest
Again untested
how you install phpunit? first you need to
composer global require phpunit/phpunit
then add C:\Users\you name\AppData\Roaming\Composer\vendor\bin to you system path
he is on windows , your suggestion won't work
The last comment that I made was what other people suggest on stackoverflow for a windows setup:
vendor\bin\phpunit --filter=ProjectTest
Have you given it a try? as mentioned, not tested by me.
I've tried it. See the response. C:\xampp\htdocs\laravel\birdboard>vendor\bin\phpunit --filter=ProjectTest PHPUnit 7.5.17 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 1.73 seconds, Memory: 4.00 MB
There was 1 warning:
WARNINGS! Tests: 1, Assertions: 0, Warnings: 1. But i've written this test
public function a_user_can_create_a_project() { $attributes = [ 'title' => $this->faker->sentence, 'description' => $this->faker->paragraph, ]; $this->post('/projects', $attributes); $this->assertDatabaseHas('projects', $attributes); }
@markomeje you need to set a comment over the test with annotation @test
/** @test */
public function a_user_can_create_a_project() {... }
Thank you so much. It worked.
Thanks
I'm getting another error
PHPUnit 7.5.17 by Sebastian Bergmann and contributors.
..F.FF. 7 / 7 (100%)
Time: 1.45 seconds, Memory: 18.00 MB
There were 3 failures:
1) Tests\Feature\ProjectTest::a_user_can_create_a_project
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/projects'
+'http://localhost/login'
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:207
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:152
C:\xampp\htdocs\laravel\birdboard\tests\Feature\ProjectTest.php:22
2) Tests\Feature\ProjectTest::a_project_requires_a_title
Session is missing expected key [errors].
Failed asserting that false is true.
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:879
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:917
C:\xampp\htdocs\laravel\birdboard\tests\Feature\ProjectTest.php:37
3) Tests\Feature\ProjectTest::a_project_requires_a_description
Session is missing expected key [errors].
Failed asserting that false is true.
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:879
C:\xampp\htdocs\laravel\birdboard\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:917
C:\xampp\htdocs\laravel\birdboard\tests\Feature\ProjectTest.php:43
FAILURES!
Tests: 7, Assertions: 10, Failures: 3.
And this is my code
<?php
namespace Tests\Feature;
use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ProjectTest extends TestCase
{
use WithFaker, RefreshDatabase;
/** @test */
public function a_user_can_create_a_project() {
//$this->withoutExceptionHandling();
$attributes = [
'title' => $this->faker->sentence,
'description' => $this->faker->paragraph,
'owner_id' => factory(User::class)->create()->id,
];
$this->post('/projects', $attributes)->assertRedirect('/projects');
$this->assertDatabaseHas('projects', $attributes);
$this->get('/projects')->assertSee($attributes['title']);
}
/** @test */
public function a_user_can_view_a_project() {
//$this->withoutExceptionHandling();
$project = factory('App\Project')->create();
$this->get($project->path())->assertSee($project->title)->assertSee($project->description);
}
/** @test */
public function a_project_requires_a_title() {
$attributes = factory('App\Project')->raw(['title' => '']);
$this->post('/projects', $attributes)->assertSessionHasErrors('title');
}
/** @test */
public function a_project_requires_a_description() {
$attributes = factory('App\Project')->raw(['description' => '']);
$this->post('/projects', $attributes)->assertSessionHasErrors('description');
}
/** @test */
public function a_project_requires_an_owner() {
//$this->withoutExceptionHandling();
$attributes = factory('App\Project')->raw();
$this->post('/projects', $attributes)->assertRedirect('login');
}
}
Please help. Thanks
@markomeje the new question is not related to the original question here. So you should start a new discussion.
.. So to give you a clue here on what to spent time yourself first on is, that you need a logged in user now as you added the auth middleware to the Projects route, so now it redirects you to the login page and you cannot create a project using a guest user. So take a look at $this->actingAs method..
https://laravel.com/docs/master/http-tests#session-and-authentication
Adding /** @test */ to the top of the test method worked for me
Please or to participate in this conversation.