getMockBuilder(ConnectionPool::class) ->setConstructorArgs(['connection string', \count($connections)]) ->setMethods(['createConnection']) ->getMock(); $mock->method('createConnection') ->will($this->returnCallback(function () use ($connections): Promise { static $count = 0; return new Success($connections[$count++]); })); return $mock; } }