1

this is my config/database will be if i can get prompt reply

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'url' => env('DATABASE_URL'),
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
        'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    ]

...this is the phpunit.ml.....

 <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
</testsuites>
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
    </whitelist>
</filter>
<php>
    <server name="APP_ENV" value="testing"/>
    <server name="DB_CONNECTION" value="sqlite"/>
     <server name="DB_DATABASE" value=":memory:"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
</php>

this is the test.php has created database.sqlite already pls what am i missing here am confused

namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ThreadTest extends TestCase
 {
   use DatabaseMigrations ;

  public function a_user_can_browse_threads()
 {
     $thread=factory('App\Thread')->create();
     $response = $this->get('/threads');

     $response->assertSee($thread->title);

     };
  }
2
  • it doesn't know that method is a test method most likely Commented Nov 14, 2019 at 2:36
  • pls can you be more elaborate Commented Nov 14, 2019 at 13:23

3 Answers 3

2

Have you browsed the documentation for this?

The tests are public methods that are named test*.

Try using the following:

public function testUserCanBrowseThreads() // <-- note the camelCase
{
    $thread = factory(\App\Thread::class)->create();

    $response = $this->get('/threads');

    $response->assertStatus(200); // <-- did you view the thread?

    $response->assertSee($value); //<-- whatever you want to look for 
}

You can always write a function not named test* and consume it another.

// This won't run by itself
public function fooBar()
{
    $foo = factory(\App\Foo::class)->create();

    $this->assertDatabaseHas('foos', [
        'id' => $foo->id
    ]);

    return $foo;
}


// This will 
public function testFoo()
{
    $bar = $this->fooBar();

    // Use the information in your test
}
Sign up to request clarification or add additional context in comments.

Comments

1

You need to start your test method's name with test or add a @test annotation in a docblock for the method:

public function test_a_user_can_browse_threads()
{
    // Starting the tests name with 'test'
}

public function testUserCanBrowseThreads()
{
    // Starting the tests name with 'test' in another format
}

/**
 * @test
 */
public function a_user_can_browse_threads()
{
    // Using the @test annotation
}

PHPUnit Docs - Writing Tests

4 Comments

I might be mistaken here, but aren't the test names supposed to be camelCase? Perhaps just a preferential thing?
Learn something new every day! +1 for the tip.
probably looks nicer in camelCase though :)
"this does not work" ... thanks but yes "it does work", try again
0

have resolved it

./vendor/bin/phpunit did the trick.. calling phpunit direct doesn't work for most latest laravel versio

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.