Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiohm committed Feb 17, 2020
1 parent 1834826 commit 2947b05
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# phpstorm project files
.idea

# netbeans project files
nbproject/*

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# Mac DS_Store Files
.DS_Store

/vendor/
composer.lock
.phpunit.result.cache
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:7.4-cli-alpine3.11

RUN apk add --no-cache \
libzip-dev \
openssl-dev && \
docker-php-ext-install -j$(nproc) \
zip

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

RUN apk add --no-cache --virtual .phpize_deps $PHPIZE_DEPS && \
pecl install xdebug-2.9.2 && \
docker-php-ext-enable xdebug && \
rm -rf /usr/share/php7 && \
rm -rf /tmp/pear && \
apk del .phpize_deps

ENV PATH /var/app/bin:/var/app/vendor/bin:$PATH

WORKDIR /var/app
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
UID=$(shell id -u)
GID=$(shell id -g)
DOCKER_PHP_SERVICE=php

start: erase cache-folders build composer-install bash

erase:
docker-compose down -v

build:
docker-compose build && \
docker-compose pull

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

composer-install:
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} composer install

bash:
docker-compose run --rm -u ${UID}:${GID} ${DOCKER_PHP_SERVICE} sh

logs:
docker-compose logs -f ${DOCKER_PHP_SERVICE}
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "pccomponentes/dbal-transaction",
"description": "DBAL Transaction",
"authors": [
{
"name": "Sergio Hernández Martínez",
"email": "[email protected]"
}
],
"license": "MIT",
"type": "library",
"autoload": {
"psr-4": {
"PcComponentes\\Transaction\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PcComponentes\\Transaction\\Tests\\": "tests/"
}
},
"require": {
"php": "^7.4",
"pccomponentes/transaction": "^1.0",
"doctrine/dbal": "^2.10"
},
"require-dev": {
"pccomponentes/coding-standard": "^1.0",
"phpunit/phpunit": "^8.5",
"dg/bypass-finals": "^1.1"
}
}
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.7'
services:
php:
build: .
volumes:
- .:/var/app
5 changes: 5 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" ?>
<ruleset name="Project rules">
<file>src</file>
<rule ref="vendor/pccomponentes/coding-standard/PccomponentesCodingStandard/ruleset.xml" />
</ruleset>
32 changes: 32 additions & 0 deletions src/Driver/DBAL/DBALTransactionalConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

namespace PcComponentes\Transaction\Driver\DBAL;

use Doctrine\DBAL\Driver\Connection;
use PcComponentes\Transaction\Driver\TransactionalConnection;

final class DBALTransactionalConnection implements TransactionalConnection
{
private Connection $DBALConnection;

public function __construct(Connection $DBALConnection)
{
$this->DBALConnection = $DBALConnection;
}

public function beginTransaction(): void
{
$this->DBALConnection->beginTransaction();
}

public function commit(): void
{
$this->DBALConnection->commit();
}

public function rollBack(): void
{
$this->DBALConnection->rollBack();
}
}
59 changes: 59 additions & 0 deletions tests/Driver/DBAL/DBALTransactionalConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);

namespace PcComponentes\Transaction\Tests\Driver\DBAL;

use Doctrine\DBAL\Driver\Connection;
use PcComponentes\Transaction\Driver\DBAL\DBALTransactionalConnection;
use PHPUnit\Framework\TestCase;

final class DBALTransactionalConnectionTest extends TestCase
{
/**
* @test
*/
public function given_dbal_connection_when_begin_transaction_then_it_is_done_in_dbal_connection()
{
$DBALConnection = $this->createMock(Connection::class);

$DBALConnection
->expects($this->once())
->method('beginTransaction')
;

$transactionalConnection = new DBALTransactionalConnection($DBALConnection);
$transactionalConnection->beginTransaction();
}

/**
* @test
*/
public function given_dbal_connection_when_commit_then_it_is_done_in_dbal_connection()
{
$DBALConnection = $this->createMock(Connection::class);

$DBALConnection
->expects($this->once())
->method('commit')
;

$transactionalConnection = new DBALTransactionalConnection($DBALConnection);
$transactionalConnection->commit();
}

/**
* @test
*/
public function given_dbal_connection_when_roll_back_then_it_is_done_in_dbal_connection()
{
$DBALConnection = $this->createMock(Connection::class);

$DBALConnection
->expects($this->once())
->method('rollBack')
;

$transactionalConnection = new DBALTransactionalConnection($DBALConnection);
$transactionalConnection->rollBack();
}
}
6 changes: 6 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
declare(strict_types=1);

require dirname(__DIR__).'/vendor/autoload.php';

\DG\BypassFinals::enable();

0 comments on commit 2947b05

Please sign in to comment.