Skip to content
Merged
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
4 changes: 4 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.env.local
/.env.local.php
/.env.*.local
.idea
18 changes: 18 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Requirements
- [Docker](https://www.docker.com/)

### Start working
Install and run the application.
```sh
docker/up
```
## Running tests
With this command you will execute all the test (Functional, Integration, Unit and e2e). You don't need to execute something more.
```sh
docker/test
```
![Alt Text](https://64.media.tumblr.com/723987e60ebfffeb744f84fa92e52245/tumblr_neglojBBbo1sx56xso1_400.gif)
<br>
"We are amidst strange beings, in a strange land."
<br><br>
Solaire De Astora
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.7'

services:

# APP SERVICES
php-fpm:
build:
target: development
context: .
dockerfile: ./docker/php-fpm/Dockerfile
volumes:
- ./src/:/opt/app/
- "./docker/php-fpm/conf/php-fpm.conf:/etc/php-fpm.conf"
- "./docker/php-fpm/conf/php.ini:/usr/local/etc/php/conf.d/100-php.ini"

nginx:
build: docker/nginx
volumes:
- "./docker/nginx/conf/project.conf:/etc/nginx/conf.d/00-project.conf"
depends_on:
- php-fpm
ports:
- 80:80
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.16

COPY conf/project.conf /etc/nginx/conf.d/00-project.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
upstream php_upstream { # define our php upstream
server php-fpm:9000;
}

server {
listen 80;
server_name oursuperawesometwittershoutapi.com project.tld;

root /opt/app/public;
index index.php;

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

error_page 404 /index.php;

location ~ ^/(index)\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM php:8.1.5-fpm-alpine as production

# Install needed modules to run the application
RUN apk update \
&& apk --quiet add \
libzip-dev

# Add php extension to work with zip files
RUN docker-php-ext-install -j$(nproc) \
zip

RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
&& pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
&& apk del pcre-dev ${PHPIZE_DEPS}

# Install OPCACHE extension
RUN docker-php-ext-install opcache

WORKDIR /opt/app

# Install XDEBUG extension
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-3.1.4 \
&& docker-php-ext-enable xdebug


# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --version=2.3.5 --install-dir=/usr/local/bin --filename=composer

# Add prestissimo for parallel composer downloads
#RUN composer global require "hirak/prestissimo"

# Copy source code into container
COPY ./src/ .

# Install production dependencies
RUN composer install

FROM production as development

# Install with dev dependencies
CMD sh -c "composer install && docker-php-entrypoint php-fpm"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[global]

error_log = /proc/stderr
daemonize = no

[www]

; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/stdout

; this does the trick for changing the user
user = project
group = project

listen = [::]:9000

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
display_errors = On
display_startup_errors = On
error_reporting = E_ALL

max_execution_time = 60
max_input_time = 60
memory_limit = 256M

post_max_size = 32M
upload_max_filesize = 32M

realpath_cache_size = 4096K
realpath_cache_ttl = 600

date.timezone = "Europe/Paris"

opcache.max_accelerated_files = 20000
opcache.memory_consumption = 256

xdebug.mode=develop,debug,coverage
xdebug.start_with_request=yes
# Default log_level is 7
xdebug.log_level=0
6 changes: 6 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/docker/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

docker-compose run php-fpm vendor/bin/phpunit --testsuite='Unit' --order-by=random
#docker-compose run php-fpm vendor/bin/phpunit --testsuite='Integration' --order-by=random
docker-compose run php-fpm vendor/bin/phpunit --testsuite='e2e' --order-by=random

4 changes: 4 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/docker/up
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker-compose up --build -d

23 changes: 23 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=457f9027edc25ab2ad5714be09f1a00d
REDIS_HOST=redis
REDIS_PORT=6379
###< symfony/framework-bundle ###
###> symfony/messenger ###
#MESSENGER_TRANSPORT_DSN=amqp://rabbit:mq@rabbit:5672
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
#DATABASE_TEST_URL=
REDIS_HOST=redis
REDIS_PORT=6379
22 changes: 22 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
/report/
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
default:
suites:
default:
paths:
- "%paths.base%/tests/Functional/Features/Tweet.feature"
filters:
contexts:
- App\Tests\Functional\Contexts\TweetContext

extensions:
FriendsOfBehat\SymfonyExtension:
bootstrap: 'config/behat/bootstrap.php'
kernel:
environment: test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

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

if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
require dirname(__DIR__) . '/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env.test');
}
43 changes: 43 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/src/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;

if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}

set_time_limit(0);

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

if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
13 changes: 13 additions & 0 deletions exercises/tiered_pricing/solutions/malakaton-php/src/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env php
<?php

if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
Loading