Skip to content

Unit tests are failing when Postgres persistent connection is enabled  #6150

@somayajulu

Description

@somayajulu

What are you trying to achieve?

Unit test should pass when db persistent connection is enabled

What do you get instead?

Receiving error "[PDOException] There is already an active transaction"

[PDOException] There is already an active transaction

This is the database.php file db configuration in Laravel
'connections' => [

    'cockroach' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', 'xxxxx'),
        'port' => env('DB_PORT', 'xxxxx'),
        'database' => env('DB_DATABASE', 'xxxxx'),
        'username' => env('DB_USERNAME', 'xxxx'),
        'sslmode' => 'require',           
        'sslkey' => env('DB_SSLKEY', "xxxx"),
        'sslcert' => env('DB_SSLCERT', "xxxxx"),           
        'options' => array(
        PDO::ATTR_ERRMODE  => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_EMULATE_PREPARES => true,
        PDO::ATTR_PERSISTENT => true),

    ],

]

Mocking database query builder to test functions written in Laravel repository classes (holds database logic)

   $this->builder = Mockery::mock('Illuminate\Database\Query\Builder');
        $this->db = DB::shouldReceive('commit')->andReturnNull()
            ->shouldReceive('rollback')->andReturnNull()
            ->shouldReceive('beginTransaction')->andReturnNull()
            ->shouldReceive('getConnections')->andReturn([])
            ->shouldReceive('table')->andReturn($this->builder)
            ->shouldReceive('raw')->andReturn("");

Details

  • Codeception version: 4.1.17
  • PHP Version: 7.4.4
  • Operating System: Ubuntu
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
unit.suit.yml
actor: UnitTester
modules:
    enabled:
        - Asserts
        - \Helper\Unit
        - Laravel5
    step_decorators: ~

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions