orm icon indicating copy to clipboard operation
orm copied to clipboard

[QUESTION] Any known limitation, such as can we use the assertDatabaseHas

Open bicatu opened this issue 7 years ago • 3 comments

Hi,

I am using Laravel 5.6, Laravel Doctrine ORM 1.4 with sqlite (in memory) for tests.

I've overridden my setupTraits to be

    protected function setUpTraits()
    {
        $uses = parent::setUpTraits();

        if (isset($uses[DatabaseMigrations::class])) {
            $this->runDatabaseMigrations();
        }

        return $uses;
    }

Which is being executed fine.

When I use the $this->assertDatabaseHas and pass the name of the table it gives me

Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: items (SQL: select count(*) as aggregate from "items" where ("id" = d165843f-6792-478b-a77d-ab18f14dd152))

bicatu avatar Jul 27 '18 03:07 bicatu

assertDatabaseHas creates a new connection. I for myself redefined the method assertDatabaseHas and check the data in the current connection with app('em')...

porozhnyy avatar Jul 28 '18 15:07 porozhnyy

Hi could you share a gist or even suggest a PR for that?

On Sat, Jul 28, 2018 at 11:23 AM Ivan [email protected] wrote:

assertDatabaseHas creates a new connection. I for myself redefined the method assertDatabaseHas and check the data in the current connection with app('em')...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/laravel-doctrine/orm/issues/340#issuecomment-408615064, or mute the thread https://github.com/notifications/unsubscribe-auth/AAN40GF5lar6mlOVIVc_Yr4gbbd78fvuks5uLIH4gaJpZM4Vi3ig .

bicatu avatar Aug 01 '18 01:08 bicatu

Here's what I used to get assertDatabaseHas working:

$pdo = app()->make(\Doctrine\ORM\EntityManagerInterface::class)->getConnection()
            ->getWrappedConnection();

app()->make(\Illuminate\Database\ConnectionInterface::class)->setPdo($pdo);

That can go anywhere before the method is called, I put it into a trait for tests that use Doctrine.

Stole the idea from here: https://github.com/laravel-doctrine/orm/issues/304#issuecomment-413218029

keithbrink avatar Jun 10 '22 13:06 keithbrink