fureszk

Experience

12,570

0 Best Reply Awards

  • Member Since 11 Months Ago
  • 125 Lessons Completed
  • 7 Favorites

13th September, 2017

fureszk left a reply on AssertDatabaseHas Not Working As Expected • 2 months ago

All I had to do is show PHPStorm what configuration file to use (phpunit.xml). Solved.

fureszk left a reply on [5.5] Parsing Whoops Errors In AssertSee • 2 months ago

well, you can check storage/logs/laravel.log clear the file before running the single test

fureszk started a new conversation AssertDatabaseHas Not Working As Expected • 2 months ago

Hello Everyone,

I'm having an issue with testing Laravel 5.5.

I have modified phpunit.xml to use DB_CONNECTION "testing", which is a mysql database. I have overridden assertDatabaseHas to use the same connection and using DatabaseTransactions, so my TestCase class looks like this:

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication, DatabaseTransactions;
    //...
    public function assertDatabaseHas($table, array $data, $connection = 'testing')
    {
        return parent::assertDatabaseHas($table, $data, $connection);
    }
}

My other tests work great, but assertDatabaseHas doesnt seem to work. I created an example:

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $details = [
            'email' => sha1('[email protected]'),
            'token' => str_random(10),
        ];

        \DB::table('tokens')->insert($details);

        $this->assertDatabaseHas('tokens', $details);
    }
}

Fails with the following message:

Failed asserting that a row in the table [tokens] matches the attributes {
    "email": "16a6ce8524fcf78c938b8b98e97525c8b20c9fb3",
    "token": "xlCqvCD1Np"
}.

The table is empty.
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.