nolros's avatar
Level 23

Best approach to test DB

Hey guys

What would be the best testing lib and approach to testing DB related methods. Example,

        $count = 0;
        foreach($create as $userPermission)
        {
            $spaceUser = SpaceUser::where('id', '=', $userPermission->target_user_id)->first();
  
            $granted = $this->userPermissionEloquent->hasAnyUserPermissions($space, $spaceUser);

            if($granted === true )
            {
                $isVerify[] = $granted;
                $count++;
            }
        }
        $overall['verified'] = [$count, count($isVerify)];

        $count = 0;
        foreach($create as $userPermission)
        {

            $spaceUser = SpaceUser::where('id', '=', $userPermission->target_user_id)->first();

            $container = Container::find($userPermission->target_object_id);

            $granted = $this->userPermissionEloquent->permissionsGranted($space, $spaceUser, $container);

            $firstGranted = $granted->first();

                if ($firstGranted instanceof UserPermission)
                {
                    $find[] = $granted;
                    $count++;
                }
        }
        $overall['found'] = [$count, count($find)];

0 likes
2 replies
davorminchorov's avatar
Level 53

I'd say write integration tests for that. Codeception or PHPUnit with the Integrated package would be a good choice. The newest series is about how to use the package.

1 like
olimorris's avatar

Agree with @Ruffles. TestDummy is a really neat package for populating your database with dummy data for the purposes of testing.

Jeff's LaraBook series used CodeCeption throughout and he showed loads of neat ways to use Integration Testing

1 like

Please or to participate in this conversation.