Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inclusão de Testes Unitários #77

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/coverage/
/.phpunit.cache/
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:8.2-apache

RUN apt-get update && \
apt-get install -y \
libzip-dev unzip \
&& docker-php-ext-install pdo pdo_mysql zip

# Necessário para gerar o coverage
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

RUN echo "xdebug.coverage_enable" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

COPY --from=composer/composer:latest-bin /composer /usr/bin/composer

RUN a2enmod rewrite \
&& a2enmod actions

CMD bash -c "composer install" && apache2-foreground
68 changes: 45 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
[![Quality Score](https://img.shields.io/scrutinizer/g/robsonvleite/datalayer.svg?style=flat-square)](https://scrutinizer-ci.com/g/robsonvleite/datalayer)
[![Total Downloads](https://img.shields.io/packagist/dt/coffeecode/datalayer.svg?style=flat-square)](https://packagist.org/packages/coffeecode/datalayer)

###### The data layer is a persistent abstraction component of your database that PDO has prepared instructions for performing common routines such as registering, reading, editing, and removing data.
**The data layer is a persistent abstraction component of your database that PDO has prepared instructions for performing common routines such as registering, reading, editing, and removing data.**

O data layer é um componente para abstração de persistência no seu banco de dados que usa PDO com prepared statements
para executar rotinas comuns como cadastrar, ler, editar e remover dados.

## About CoffeeCode

###### CoffeeCode is a set of small and optimized PHP components for common tasks. Held by Robson V. Leite and the UpInside team. With them you perform routine tasks with fewer lines, writing less and doing much more.
**CoffeeCode is a set of small and optimized PHP components for common tasks. Held by Robson V. Leite and the UpInside team. With them you perform routine tasks with fewer lines, writing less and doing much more.**

CoffeeCode é um conjunto de pequenos e otimizados componentes PHP para tarefas comuns. Mantido por Robson V. Leite e a
equipe UpInside. Com eles você executa tarefas rotineiras com poucas linhas, escrevendo menos e fazendo muito mais.
Expand Down Expand Up @@ -44,13 +44,13 @@ composer require coffeecode/datalayer

## Documentation

###### For details on how to use the Data Layer, see the sample folder with details in the component directory
**For details on how to use the Data Layer, see the sample folder with details in the component directory.**

Para mais detalhes sobre como usar o Data Layer, veja a pasta de exemplo com detalhes no diretório do componente

#### connection
### connection

###### To begin using the Data Layer, you need to connect to the database (MariaDB / MySql). For more connections [PDO connections manual on PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php)
**To begin using the Data Layer, you need to connect to the database (MariaDB / MySql). For more connections [PDO connections manual on PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php).**

Para começar a usar o Data Layer precisamos de uma conexão com o seu banco de dados. Para ver as conexões possíveis
acesse o [manual de conexões do PDO em PHP.net](https://www.php.net/manual/pt_BR/pdo.drivers.php)
Expand All @@ -72,9 +72,9 @@ const DATA_LAYER_CONFIG = [
];
```

#### your model
### your model

###### The Data Layer is based on an MVC structure with the Layer Super Type and Active Record design patterns. Soon to consume it is necessary to create the model of your table and inherit the Data Layer.
**The Data Layer is based on an MVC structure with the Layer Super Type and Active Record design patterns. Soon to consume it is necessary to create the model of your table and inherit the Data Layer.**

O Data Layer é baseado em uma estrutura MVC com os padrões de projeto Layer Super Type e Active Record. Logo para
consumir é necessário criar o modelo de sua tabela e herdar o Data Layer.
Expand All @@ -95,7 +95,7 @@ class User extends DataLayer
}
```

#### find
### find

```php
<?php
Expand Down Expand Up @@ -140,7 +140,7 @@ foreach ($users as $user) {
}
```

#### findById
### findById

```php
<?php
Expand All @@ -152,9 +152,9 @@ $user = $model->findById(2);
echo $user->first_name;
```

#### secure params
### secure params

###### See example find_example.php and model classes
**See example find_example.php and model classes.**

Consulte exemplo find_example.php e classes modelo

Expand All @@ -166,9 +166,9 @@ $company = (new Company())->find("name = :name", $params);
var_dump($company, $company->fetch());
```

#### join method
### join method

###### See example find_example.php and model classes
**See example find_example.php and model classes.**

Consulte exemplo find_example.php e classes modelo

Expand All @@ -182,7 +182,7 @@ $address->user();
var_dump($address);
```

#### count
### count

```php
<?php
Expand All @@ -193,7 +193,7 @@ $model = new User();
$count = $model->find()->count();
```

#### save create
### save create

```php
<?php
Expand All @@ -206,7 +206,7 @@ $user->last_name = "Leite";
$userId = $user->save();
```

#### save update
### save update

```php
<?php
Expand All @@ -218,7 +218,7 @@ $user->first_name = "Robson";
$userId = $user->save();
```

#### destroy
### destroy

```php
<?php
Expand All @@ -229,7 +229,7 @@ $user = (new User())->findById(2);
$user->destroy();
```

#### fail
### fail

```php
<?php
Expand All @@ -242,7 +242,7 @@ if($user->fail()){
}
```

#### custom data method
### custom data method

````php
<?php
Expand All @@ -262,17 +262,39 @@ class User{

echo $this->full_name; //Robson V. Leite
echo $this->document; //Restrict
````
````

## Testes Unitários

Para executar o conjunto de testes, você precisará clonar o repositório e instalar as dependências. É necessário ter instalado o `XDEBUG` para executar os relatórios de cobertura.

````bash
git clone https://github.com/robsonvleite/datalayer.git
cd datalayer
composer install
composer test
# Or
# composer coverage
````

Uma melhor alternativa para executar os testes sem precisar "mexer" no seu ambiente é utilizando o `Docker + Docker Compose`. Na raiz do projeto existe os arquivos de configuração para isso, basta executar o comando:

````bash
docker compose up -d --build
docker exec -it datalayer composer coverage
````

O container disponibilizará um endereço para acessar a página com o relatório da cobertura do código: [http://localhost:8080/coverage/index.html](http://localhost:8080/coverage/index.html)

## Contributing

Please see [CONTRIBUTING](https://github.com/robsonvleite/datalayer/blob/master/CONTRIBUTING.md) for details.

## Support

###### Security: If you discover any security related issues, please email [email protected] instead of using the issue tracker.
**Security: If you discover any security related issues, please email <[email protected]> instead of using the issue tracker.**

Se você descobrir algum problema relacionado à segurança, envie um e-mail para [email protected] em vez de usar o
Se você descobrir algum problema relacionado à segurança, envie um e-mail para <[email protected]> em vez de usar o
rastreador de problemas.

Thank you
Expand All @@ -286,4 +308,4 @@ Thank you
## License

The MIT License (MIT). Please see [License File](https://github.com/robsonvleite/datalayer/blob/master/LICENSE) for more
information.
information.
24 changes: 24 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
php-apache:
container_name: datalayer
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:80
restart: always
volumes:
- .:/var/www/html
links:
- mariadb

mariadb:
container_name: datalayer-db-test
image: mariadb:lts
ports:
- 33060:3306
environment:
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1
- MARIADB_DATABASE=datalayer
- MARIADB_USER=datalayer
- MARIADB_PASSWORD=datalayer
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,24 @@
"psr-4": {
"CoffeeCode\\DataLayer\\": "src"
}
},
"require-dev": {
"phpunit/phpunit": "^11.3",
"robmorgan/phinx": "^0.16.2",
"symfony/yaml": "^7.1"
},
"autoload-dev": {
"psr-4": {
"CoffeeCode\\DataLayer\\Tests\\": "tests"
}
},
"scripts": {
"migrate": "phinx migrate",
"test": "phpunit",
"coverage": "phpunit --coverage-html=coverage",
"coveralls": "phpunit --coverage-clover build/logs/clover.xml",
"post-install-cmd": [
"@migrate"
]
}
}
Loading