mardi 23 février 2016

Laravel DatabaseTransactions

I've a very weird problem. I'm trying to test the following function in my api with phpunit.

 use DatabaseTransactions;
    public $url = 'test.dev';

    /** @test */
    function show_school_stagiair_authorized()
    {
        factory(Company::class,1)
            ->create(['CompanyId' => 1]);
        factory(School::class,1)
            ->create(['SchoolId' => 1, 'CompanyId' => 1]);
        factory(Mentor::class,1)
            ->create(['MentorId' => 1, 'SchoolId' => 1, 'CompanyId' => 1]);
        factory(Department::class,1)
            ->create(['DepartmentId' => 1,'CompanyId' => 1]);
        factory(Intern::class,1)
            ->create(['InternId' => 1, 'MentorId' => 1]);
        factory(Employee::class,1)
            ->create(['EmployeeId' => 1, 'RoleId' => 1, 'DepartmentId' => 1, 'InternId' => 1, ]);


        $client = new Client();
        $res = $client->request('POST', $this->url.'/api/v1/school/1',[
            'form_params' => [
                'currentUserId' => 1
            ]
        ]);
        $this->assertEquals(200, $res->getStatusCode());
    }

This returns a status code of 500. But when I remove use DatabaseTransaction it's working!? In my config/database.php I've set the default to my testing connection 'default' => env('DB_CONNECTION', 'mysql_testing'), Could anybody tell me what I'm doing wrong.

Aucun commentaire:

Enregistrer un commentaire