Antonella's avatar

Test TDD lesson 1 No tests found in class "Tests\Feature\ProjectsTest".

I'm following this first lesson -> https://laracasts.com/series/build-a-laravel-app-with-tdd/episodes/2?autoplay=true

I wrote this test:

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class ProjectsTest extends TestCase
{
    use WithFaker, RefreshDatabase;

    public function a_user_can_create_a_project()
    {

        $this->withoutExceptionHandling();

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

        $this->post(['/projects', $attributes

        ]);

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

in the phpunit.xml file I changed so:

<php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
     <server name="DB_CONNECTION" value="sqlite"/>
     <server name="DB_DATABASE" value=":memory:"/>
    <server name="MAIL_MAILER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="TELESCOPE_ENABLED" value="false"/>
</php>

when i run the test i get this:

vendor/bin/phpunit tests/Feature/ProjectsTest.php

PHPUnit 9.5.0 by Sebastian Bergmann and contributors.

W 1 / 1 (100%)

Time: 00:00.003, Memory: 8.00 MB

There was 1 warning:

  1. Warning No tests found in class "Tests\Feature\ProjectsTest".

WARNINGS! Tests: 1, Assertions: 0, Warnings: 1.

I don't understand why it doesn't see the statement

0 likes
4 replies
maartenpaauw's avatar
Level 6

add /** @test */ above the method or start the method name with test_.

2 likes
Antonella's avatar

now I don't understand where this error comes from: ErrorException: strncmp() expects parameter 1 to be string, array given @maartenpaauw

i saw it comes from this piece of code :

$this->post(['/projects', $attributes

    ]);
maartenpaauw's avatar

I'm not sure but I think the method does not accept an array but 2 separated attributes (route and attributes).

Like:

$this->post('/projects', $attributes);
1 like
Antonella's avatar

yes

i changed this :

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

and it's work

1 like

Please or to participate in this conversation.