Skip to content

Commit 0f730f5

Browse files
authored
Merge pull request #6 from PcComponentes/feature/dbal-4-support
feat: add dbal 4 support
2 parents 51311b6 + 092d92e commit 0f730f5

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
FROM php:8.0-cli-alpine3.13
1+
FROM php:8.4-cli-alpine3.22
22

3-
RUN apk add --no-cache \
3+
RUN apk update && \
4+
apk add --no-cache \
45
libzip-dev \
6+
git \
57
openssl-dev && \
68
docker-php-ext-install -j$(nproc) \
79
zip
810

911
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
1012

11-
RUN apk add --no-cache --virtual .phpize_deps $PHPIZE_DEPS && \
12-
pecl install xdebug-3.1.1 && \
13+
RUN apk add --no-cache --virtual .phpize_deps $PHPIZE_DEPS linux-headers && \
14+
pecl install xdebug-3.4.7 && \
1315
docker-php-ext-enable xdebug && \
14-
rm -rf /usr/share/php7 && \
1516
rm -rf /tmp/pear && \
1617
apk del .phpize_deps
1718

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ DOCKER_PHP_SERVICE=php
55
start: erase cache-folders build composer-install bash
66

77
erase:
8-
docker-compose down -v
8+
docker compose down -v
99

1010
build:
11-
docker-compose build && \
12-
docker-compose pull
11+
docker compose build && \
12+
docker compose pull
1313

1414
cache-folders:
1515
mkdir -p ~/.composer && chown ${UID}:${GID} ~/.composer
1616

1717
composer-install:
18-
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} composer install
18+
docker compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} composer install
1919

2020
bash:
21-
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} sh
21+
docker compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} sh
2222

2323
logs:
24-
docker-compose logs -f ${DOCKER_PHP_SERVICE}
24+
docker compose logs -f ${DOCKER_PHP_SERVICE}
2525

2626
.PHONY: tests
2727
tests:
28-
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} phpunit
28+
docker compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} phpunit

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
}
2121
},
2222
"require": {
23-
"php": "^7.4 | ^8.0",
23+
"php": "^7.4 || ^8.0",
2424
"pccomponentes/transaction": "^2.0",
25-
"doctrine/dbal": "^2.10 | ^3.0"
25+
"doctrine/dbal": "^2.10 || ^3.0 || ^4.0"
2626
},
2727
"require-dev": {
2828
"pccomponentes/coding-standard": "^1.0",

src/Driver/DBAL/DBALTransactionalConnection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ public function __construct(Connection $DBALConnection, bool $nestTransactionsWi
1515
$this->DBALConnection = $DBALConnection;
1616

1717
if (true === $nestTransactionsWithSavepoints) {
18-
$this->DBALConnection->setNestTransactionsWithSavepoints(true);
18+
// In DBAL 4+, savepoints are always enabled for nested transactions
19+
// The setNestTransactionsWithSavepoints method is deprecated and will be removed in DBAL 5
20+
// We only call it if it exists to maintain backward compatibility with DBAL 2.x and 3.x
21+
if (\method_exists($this->DBALConnection, 'setNestTransactionsWithSavepoints')) {
22+
@$this->DBALConnection->setNestTransactionsWithSavepoints(true);
23+
}
1924
}
2025
}
2126

tests/Driver/DBAL/DBALTransactionalConnectionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,25 @@ public function given_dbal_connection_when_is_not_in_transaction_active_then_ret
9090
$transactionalConnection = new DBALTransactionalConnection($DBALConnection);
9191
$this->assertFalse($transactionalConnection->isTransactionActive());
9292
}
93+
94+
/**
95+
* @test
96+
*/
97+
public function given_dbal_connection_with_nest_transactions_enabled_when_construct_then_works_correctly()
98+
{
99+
$DBALConnection = $this->createMock(Connection::class);
100+
101+
// In DBAL 4+, setNestTransactionsWithSavepoints is deprecated
102+
// The code should handle this gracefully by checking if method exists
103+
if (\method_exists($DBALConnection, 'setNestTransactionsWithSavepoints')) {
104+
$DBALConnection
105+
->expects($this->once())
106+
->method('setNestTransactionsWithSavepoints')
107+
->with(true)
108+
;
109+
}
110+
111+
$transactionalConnection = new DBALTransactionalConnection($DBALConnection, true);
112+
$this->assertInstanceOf(DBALTransactionalConnection::class, $transactionalConnection);
113+
}
93114
}

0 commit comments

Comments
 (0)