1
0
Fork 0
mirror of https://github.com/archtechx/template.git synced 2025-12-12 13:24:03 +00:00

Initial commit

This commit is contained in:
Samuel Štancl 2021-05-23 13:13:38 +02:00
commit aaa8f56cf6
14 changed files with 530 additions and 0 deletions

13
.gitattributes vendored Normal file
View file

@ -0,0 +1,13 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/docker-compose.yml export-ignore
/tests export-ignore
/phpstan.neon export-ignore
/.php_cs.php export-ignore
/psalm.xml export-ignore
/phpunit.xml export-ignore
/check export-ignore
/coverage export-ignore

60
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,60 @@
name: CI
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
PHP_CS_FIXER_IGNORE_ENV: 1
MYSQL_PORT: 3307
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
pull_request:
branches: [ master ]
jobs:
phpunit:
name: Tests (PHPUnit)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Start docker containers
run: docker-compose up -d
- name: Install composer dependencies
run: composer install
- name: Run tests
run: vendor/bin/phpunit
steps:
- uses: actions/checkout@v2
- name: Install composer dependencies
run: composer install
- name: Run psalm
run: vendor/bin/psalm
phpstan:
name: Static analysis (PHPStan)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install composer dependencies
run: composer install
- name: Run phpstan
run: vendor/bin/phpstan analyse
php-cs-fixer:
name: Code style (php-cs-fixer)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install php-cs-fixer
run: composer global require friendsofphp/php-cs-fixer
- name: Run php-cs-fixer
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php_cs.php
- name: Commit changes from php-cs-fixer
uses: EndBug/add-and-commit@v5
with:
author_name: "PHP CS Fixer"
author_email: "phpcsfixer@example.com"
message: Fix code style (php-cs-fixer)

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
.phpunit.result.cache
package-lock.json
composer.lock
vendor/
.php_cs.cache
.vscode/
coverage/
node_modules

144
.php_cs.php Normal file
View file

@ -0,0 +1,144 @@
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => null,
'|' => 'no_space',
]
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_superfluous_phpdoc_tags' => true,
'blank_line_before_statement' => [
'statements' => ['return']
],
'braces' => true,
'cast_spaces' => true,
'class_attributes_separation' => [
'elements' => ['method']
],
'class_definition' => true,
'concat_space' => [
'spacing' => 'one'
],
'declare_equal_normalize' => true,
'elseif' => true,
'encoding' => true,
'full_opening_tag' => true,
'declare_strict_types' => true,
'fully_qualified_strict_types' => true, // added by Shift
'function_declaration' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'increment_style' => ['style' => 'post'],
'indentation_type' => true,
'linebreak_after_opening_tag' => true,
'line_ending' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true, // added from Symfony
'magic_method_casing' => true, // added from Symfony
'magic_constant_casing' => true,
'method_argument_space' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'use',
'use_trait',
]
],
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => [
'use' => 'echo'
],
'no_multiline_whitespace_around_double_arrow' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line'
],
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'psr4' => true,
'self_accessor' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false, // disabled by Shift
'single_blank_line_at_eof' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'no_unused_imports' => true,
'single_line_comment_style' => [
'comment_types' => ['hash']
],
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
];
$project_path = getcwd();
$finder = Finder::create()
->in([
$project_path . '/src',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
return Config::create()
->setFinder($finder)
->setRules($rules)
->setRiskyAllowed(true)
->setUsingCache(true);

41
README.md Normal file
View file

@ -0,0 +1,41 @@
# REPLACE
Simple and flexible package template.
# Usage
- Replace all occurances of `REPLACE` (case sensitive) with the name of the package namespace. E.g. the `Foo` in `ArchTech\Foo`.
- Replace all occurances of `replace2` with the name of the package on composer, e.g. the `bar` in `archtechx/bar`.
- If MySQL is not needed, remove `docker-compose.yml`, remove the line that runs docker from `./check`, and set `DB_CONNECTION` in `phpunit.xml` to `sqlite`, and `DB_DATABASE` to `:memory:`.
---
## Installation
```sh
composer require stancl/replace2
```
## Usage
```php
// ...
```
## Development
Running all checks locally:
```sh
./check
```
Running tests:
```sh
MYSQL_PORT=3307 docker-compose up -d
phpunit
```
Code style will be automatically fixed by php-cs-fixer.

56
check Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
set -e
offer_run() {
read -p "For more output, run $1. Run it now (Y/n)? " run
case ${run:0:1} in
n|N )
exit 1
;;
* )
$1
;;
esac
exit 1
}
if (php-cs-fixer fix --dry-run --config=.php_cs.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
read -p "⚠️ php-cs-fixer found issues. Fix (Y/n)? " fix
case ${fix:0:1} in
n|N )
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php_cs.php'
;;
* )
if (php-cs-fixer fix --config=.php_cs.php > /dev/null 2>/dev/null); then
echo '✅ php-cs-fixer OK'
else
echo '❌ php-cs-fixer FAIL'
offer_run 'php-cs-fixer fix --config=.php_cs.php'
fi
;;
esac
fi
if (./vendor/bin/phpstan analyse > /dev/null 2>/dev/null); then
echo '✅ PHPStan OK'
else
echo '❌ PHPStan FAIL'
offer_run './vendor/bin/phpstan analyse'
fi
(MYSQL_PORT=3307 docker-compose up -d > /dev/null 2>/dev/null) || true
if (./vendor/bin/pest > /dev/null 2>/dev/null); then
echo '✅ PEST OK'
else
echo '❌ PEST FAIL'
offer_run './vendor/bin/pest'
fi
echo '=================='
echo '✅ Everything OK'

39
composer.json Normal file
View file

@ -0,0 +1,39 @@
{
"name": "archtechx/replace",
"description": "",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Samuel Štancl",
"email": "samuel@archte.ch"
}
],
"autoload": {
"psr-4": {
"ArchTech\\REPLACE\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ArchTech\\REPLACE\\Tests\\": "tests/"
}
},
"require": {
"illuminate/support": "^8.24"
},
"require-dev": {
"orchestra/testbench": "^6.9",
"vimeo/psalm": "^4.2",
"nunomaduro/larastan": "^0.6.10",
"pestphp/pest": "^1.2",
"pestphp/pest-plugin-laravel": "^1.0"
},
"extra": {
"laravel": {
"providers": [
"ArchTech\\REPLACE\\PackageServiceProvider"
]
}
}
}

12
docker-compose.yml Normal file
View file

@ -0,0 +1,12 @@
version: '3'
services:
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: main
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_TCP_PORT: ${MYSQL_PORT}
ports:
- "${MYSQL_PORT}:${MYSQL_PORT}"

24
phpstan.neon Normal file
View file

@ -0,0 +1,24 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
parameters:
paths:
- src
level: 8
universalObjectCratesClasses:
- Illuminate\Routing\Route
ignoreErrors:
# -
# message: '#Offset (.*?) does not exist on array\|null#'
# paths:
# - tests/*
# -
# message: '#expects resource, resource\|false given#'
# paths:
# - tests/*
# - '#should return \$this#'
checkMissingIterableValueType: false

31
phpunit.xml Normal file
View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="coverage/phpunit/clover.xml"/>
<html outputDirectory="coverage/phpunit/html" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:uYlmYxcuuO7dC34yUn2hQcPu8PnlC98LTyOZg4fNAZU="/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="redis"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="testbench"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value="main"/>
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="AWS_DEFAULT_REGION" value="us-west-2"/>
</php>
</phpunit>

View file

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace ArchTech\REPLACE;
use Illuminate\Support\ServiceProvider;
class REPLACEServiceProvider extends ServiceProvider
{
public function register(): void
{
}
public function boot(): void
{
// $this->loadViewsFrom(__DIR__ . '/../assets/views', 'package');
// $this->publishes([
// __DIR__ . '/../assets/views' => resource_path('views/vendor/package'),
// ], 'package-views');
// $this->mergeConfigFrom(
// __DIR__ . '/../assets/package.php',
// 'package'
// );
// $this->publishes([
// __DIR__ . '/../assets/package.php' => config_path('package.php'),
// ], 'package-config');
}
}

45
tests/Pest.php Normal file
View file

@ -0,0 +1,45 @@
<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
uses(ArchTech\REPLACE\Tests\TestCase::class)->in('Pest');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}

View file

@ -0,0 +1,9 @@
<?php
it('succeeds', function () {
expect(true)->toBeTrue();
});
it('fails', function () {
expect(false)->toBeTrue();
});

16
tests/TestCase.php Normal file
View file

@ -0,0 +1,16 @@
<?php
namespace ArchTech\REPLACE\Tests;
use Orchestra\Testbench\TestCase as TestbenchTestCase;
use ArchTech\REPLACE\REPLACEServiceProvider;
class TestCase extends TestbenchTestCase
{
protected function getPackageProviders($app)
{
return [
REPLACEServiceProvider::class,
];
}
}