Skip to content

Commit

Permalink
Adding all
Browse files Browse the repository at this point in the history
  • Loading branch information
victormln committed May 23, 2022
1 parent 9165a9b commit 0859aef
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM php:8.1-fpm

RUN apt-get update && \
apt-get -y install --no-install-recommends curl gnupg gnupg2 git wget curl libpng-dev libjpeg62-turbo-dev net-tools \
libssl-dev libcurl4-openssl-dev pkg-config libxml2-dev zlib1g-dev \
libpq-dev openssh-client libzip-dev libfreetype6-dev libonig-dev

RUN docker-php-ext-install bcmath curl xml mbstring zip intl gd

# Install xdebug
RUN pecl install xdebug
RUN echo "xdebug.mode=debug,coverage\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.start_with_request=yes\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.discover_client_host=1\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.client_host=\"host.docker.internal\"\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN docker-php-ext-enable xdebug

# Install composer
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# Install infection
RUN wget https://github.com/infection/infection/releases/download/0.26.10/infection.phar \
&& chmod +x infection.phar \
&& mv infection.phar /usr/local/bin/infection
1 change: 1 addition & 0 deletions .docker/php/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#upload_max_filesize = 1M
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.idea
composer.lock
vendor/
.phpunit.result.cache
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.PHONY: help start stop

.DEFAULT_GOAL := help

help: # Show Help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

install: ## First entry command to install all the necessary
make startd
make composer-install

start: ## Start docker-compose
@docker-compose up

startd: ## Startd
@docker-compose up -d

stop: ## Stop
@docker-compose stop

composer-install: ## Install composer dependencies
@docker exec php sh -c "XDEBUG_MODE=off composer install"

test: ## Execute PHPUnite test
@docker exec php sh -c "XDEBUG_MODE=off php ./vendor/bin/phpunit -c phpunit.xml.dist"

coverage-text: ## Execute phpunit coverage in text format
@docker exec php sh -c "XDEBUG_MODE=coverage php -n -dzend_extension=xdebug ./vendor/phpunit/phpunit/phpunit --coverage-text"

infection: ## Execute Infection
@docker exec php sh -c "XDEBUG_MODE=coverage infection --threads=1"
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "victormln/docker-php-testing",
"type": "template",
"description": "A project template to have PHP 8.1 and testing tools (PHPUnit + Infection)",
"keywords": ["template"],
"homepage": "https://victormln.gitlab.io",
"license": "MIT",
"authors": [
{
"name": "Víctor Molina",
"email": "victor.molinaf@gmail.com",
"homepage": "https://victormln.gitlab.io"
}
],
"autoload":{
"psr-4":{
"Victormln\\DockerPHPTesting\\":"src/"
}
},
"autoload-dev":{
"psr-4":{
"Victormln\\DockerPHPTesting\\Tests\\":"tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.7"

services:

php:
build: ./.docker/php
container_name: php
working_dir: /var/www/php
volumes:
- .:/var/www/php:cached
- ./.docker/php/php.ini:/usr/local/etc/php/php.ini:cached
11 changes: 11 additions & 0 deletions infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/infection/infection/0.26.10/resources/schema.json",
"source": {
"directories": [
"src"
]
},
"mutators": {
"@default": true
}
}
19 changes: 19 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
executionOrder="random"
>
<testsuites>
<testsuite name="Unit Test">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
15 changes: 15 additions & 0 deletions src/Id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Victormln\DockerPHPTesting;

final class Id
{
public function __construct(private readonly string $id)
{
}

public function value(): string
{
return $this->id;
}
}
18 changes: 18 additions & 0 deletions tests/IdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Victormln\DockerPHPTesting\Tests;

use PHPUnit\Framework\TestCase;
use Victormln\DockerPHPTesting\Id;

class IdTest extends TestCase
{
private const EXPECTED_ID = '8b82112f-67ed-46bf-9c60-0c8cf169aabb';

public function test_Id_is_created(): void
{
$id = new Id(self::EXPECTED_ID);

self::assertSame(self::EXPECTED_ID, $id->value());
}
}

0 comments on commit 0859aef

Please sign in to comment.