Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
COil authored May 24, 2023
0 parents commit 463228c
Show file tree
Hide file tree
Showing 84 changed files with 11,059 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.
# https://symfony.com/doc/current/configuration/secrets.html
#
# 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=prod
APP_SECRET=155f2a3ce20caf4c940aad5a3aa29410
###< symfony/framework-bundle ###
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
69 changes: 69 additions & 0 deletions .github/workflows/symfony.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Symfony

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
# run tests (critical)
symfony-tests:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: xdebug
- uses: actions/checkout@v3
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute tests via PHPUnit
run: vendor/bin/simple-phpunit

# run all lint/cs checks (non critical)
symfony-lint:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: cs2pr
- uses: actions/checkout@v3
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

# native Symfony lints
- name: Lint the DI container
run: bin/console lint:container
- name: Lint Twig templates
run: bin/console lint:twig
- name: Lint Yaml files
run: bin/console lint:yaml config/

# vendors
- name: php-cs-fixer
run: vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run --format=checkstyle | cs2pr
- name: PHPStan
run: |
bin/console about --env=dev
vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G -vvv
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

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

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

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

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
13 changes: 13 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;

return (new PhpCsFixer\Config())->setRules([
'@Symfony' => true, // https://cs.symfony.com/doc/ruleSets/Symfony.html
'declare_strict_types' => true, // https://cs.symfony.com/doc/rules/strict/declare_strict_types.html
])->setFinder($finder);
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SHELL = sh
.DEFAULT_GOAL = help

## —— 🎶 The MicroSymfony Makefile 🎶 ——————————————————————————————————————————
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
.PHONY: help start stop test coverage cov-report stan fix-php cs ci


## —— Symfony binary 💻 ————————————————————————————————————————————————————————
start: ## Serve the application with the Symfony binary
@symfony serve --daemon

stop: ## Stop the web server
@symfony server:stop


## —— Tests ✅ —————————————————————————————————————————————————————————————————
test: ## Run all PHPUnit tests
@vendor/bin/simple-phpunit

coverage: ## Generate the HTML PHPUnit code coverage report (stored in var/coverage)
@XDEBUG_MODE=coverage php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/simple-phpunit --coverage-html=var/coverage

cov-report: ## Open the PHPUnit code coverage report (var/coverage/index.html)
@open var/coverage/index.html


## —— Coding standards ✨ ——————————————————————————————————————————————————————
stan: ## Run PHPStan
@vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G -vvv --xdebug

fix-php: ## Fix PHP files with php-cs-fixer (ignore PHP 8.2 warning)
@PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --allow-risky=yes

cs: ## Run all CS checks
cs: fix-php stan

ci: ## Run CI locally
ci: cs test
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# MicroSymfony 🎶

MicroSymfony is a template to initialize an application to use Symfony as a microframework.

It can be used to create a POC or prototyping something without having to take care
of the design, while having something still enjoyable (and fit to be seen).

Even it is minimalist, we don't want to sacrifice quality.
There are some tests (100% coverage) and CS checks: php-cs-fixer + PHPStan.

It's not really intented to be used in production, use a your onw risks.
Well at least you should remove the classless framework to use a modern CSS framework.


## Demo 🌈

Because a live demo is always better than all explanations. Here is it:

* Live demo at [https://microsymfony.ovh](https://microsymfony.ovh)
* Another barreccs demo can be found [here](https://dohliam.github.io/dropin-minimal-css/?bare#text)


## Todo

* Install the code coverage report plugin for PHPUnit
* Use import maps (doc not done yet):
* https://github.com/symfony/asset-mapper


## To try/test

* try dropin minimal: https://github.com/dohliam/dropin-minimal-css


## Requirements ⚙

* [PHP 8.1](https://www.php.net/releases/8.1/en.php)
* The [Symfony CLI](https://symfony.com/download)
* The [Xdebug](https://xdebug.org/) PHP extension if you want to run the code coverage report


## Stack 🔗

* [Symfony 6.3](https://symfony.com)
* [Twig 3](https://twig.symfony.com)
* [PHPUnit 9.5](https://phpunit.de)
* The classless [BareCSS](http://barecss.com) CSS framework

## Barecss forks

* https://github.com/zonradkuse


## What does it ship? 🚀

* A [demo with some JavaScript and Stimulus](https://github.com/strangebuzz/MicroSymfony/blob/main/templates/stimulus.html.twig)
* A [default error page extending the base layout](https://github.com/strangebuzz/symfony-micro/blob/main/templates/bundles/TwigBundle/Exception/error.html.twig)


## What it doesn't ship? ❌

* The debug toolbar
* Doctrine ORM


## Installation & first run 🚀

composer install
make start

Then open [https://127.0.0.1:8000](https://127.0.0.1:8000)

The port can change if 8000 is already used.


## Tests ✅

Run tests with:

vendor/bin/simple-phpunit

or

composer app-test

or

make test


## Dev-tools ✨

* php-cs-fixer with the [Symfony ruleset and PHP strict types](https://github.com/strangebuzz/MicroSymfony/blob/main/.php-cs-fixer.dist.php)
* PHPStan at [maximum level](https://github.com/strangebuzz/MicroSymfony/blob/main/phpstan.neon)
* A simple [Makefile](https://github.com/strangebuzz/MicroSymfony/blob/main/Makefile)
17 changes: 17 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
19 changes: 19 additions & 0 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
} else {
if (!is_file(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);
}

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

0 comments on commit 463228c

Please sign in to comment.