Skip to content

Commit 761d524

Browse files
authored
Merge pull request #1 from codeigniter4/templates
Templates
2 parents 163343e + e5235f5 commit 761d524

File tree

13 files changed

+842
-10
lines changed

13 files changed

+842
-10
lines changed

README.md

Lines changed: 102 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,123 @@ Development toolkit for CodeIgniter libraries and projects
55

66
* Install via Composer: `> composer require --dev codeigniter4/devkit`
77

8-
## Included
8+
## Included Dependencies
99

1010
### Styles and Standards
1111

1212
* [CodeIgniter Coding Standard](https://github.com/CodeIgniter/coding-standard)
13-
* NexusPHP CS Config
13+
* [NexusPHP CS Config](https://github.com/NexusPHP/cs-config)
1414

1515
### Testing and Analysis
1616

17-
* NexusPHP Tachycardia
18-
* PHPStan
19-
* PHPUnit
17+
* [NexusPHP Tachycardia](https://github.com/NexusPHP/tachycardia)
18+
* [PHPStan](https://phpstan.org/user-guide/getting-started)
19+
* [PHPUnit](http://phpunit.readthedocs.io)
2020

2121
### Mocking
2222

23-
* FakerPHP
24-
* VFS Stream
23+
* [FakerPHP](https://fakerphp.github.io)
24+
* [VFS Stream](https://github.com/bovigo/vfsStream/wiki)
2525

26-
## Additional Tools
26+
### Security
2727

28-
These are integrated into the workflows but not included via Composer so need to be installed separately.
29-
All of them are available via [Phive](https://phar.io/#Tools).
28+
* [Dependabot](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates)
29+
* [Roave Security Advisories](https://github.com/Roave/SecurityAdvisories)
30+
31+
### Additional Tools
32+
33+
These are integrated into the workflows but not included via Composer. If you want to use them
34+
locally they will need to be installed. All of them are available via [Phive](https://phar.io/#Tools).
3035

3136
* [Composer Normalize](https://github.com/ergebnis/composer-normalize)
3237
* [Composer Unused](https://github.com/composer-unused/composer-unused)
38+
* [Deptrac](https://github.com/qossmic/deptrac)
3339
* [Infection](https://infection.github.io/)
3440
* [PHP Coveralls](https://php-coveralls.github.io/php-coveralls/)
3541
* [PHP CS Fixer](https://cs.symfony.com/)
42+
43+
## Source Files
44+
45+
The provided source files should be considered guidelines or templates for your own use, as
46+
they may need changing to fit your environment. These are based on the following assumptions:
47+
48+
1. Your default repository branch is set to `develop`
49+
2. You use Composer to manage all necessary dependencies
50+
3. Your source code is located in **app/** (for projects) or **src/** (for libraries)
51+
4. Your unit tests are located in **tests/**
52+
5. Your CodeIgniter dependency is `codeigniter4/framework` (some paths need to be changed for `dev-develop`)
53+
54+
### Workflows
55+
56+
This kit includes a number of workflow templates for integrating [GitHub Actions](https://docs.github.com/en/actions)
57+
into your library or project development process. To add these to your repo simply copy the
58+
workflows into a **.github/workflows/** directory.
59+
60+
> Hint: the [source files](src/.github) also include a configuration for Dependabot which will help keep your dependencies and workflows updated.
61+
62+
Below is a brief description of each workflow; see the links above for help with each tool.
63+
64+
#### Deptrac
65+
66+
*Requires **depfile.yaml***
67+
68+
Deptrac is a "dependency tracing" tool that allows developers to define which components should
69+
be allowed to access each other. This helps keep your project architecture logical and concise
70+
by enforcing the rules you set. For example, you may want to impose an MVC-style architecture
71+
by allowing a `Controller` to use any `Model` but not vice-versa.
72+
73+
#### Infection
74+
75+
*Requires **infection.json.dist***
76+
77+
Just because your tests reach a high level of code coverage does not mean they are comprehensive.
78+
Mutation Testing is a way of gauging the *quality* of your unit tests. A silly example: your
79+
code has an increment function with a single unit test for 100% coverage:
80+
81+
```php
82+
function increment(int $num1, int $num2): int
83+
{
84+
return $num1 + $num2;
85+
}
86+
87+
function testIncrementWithZero()
88+
{
89+
$result = increment(42, 0);
90+
$this->assertSame(42, $result);
91+
}
92+
```
93+
94+
Infection will re-run your unit test against "mutated" versions of your code that *should*
95+
cause failures and report "escaped mutations" when they still pass. In this example, Infection
96+
mutates your `increment()` function to use `-` instead of `+`, but since your test case
97+
still asserts `42` as the result it is considered an "escape" and you should plan to add
98+
more tests.
99+
100+
#### PHPCPD
101+
102+
PHP Copy-Paste Detector analyzes your code and reports when there are blocks of duplicate code
103+
more than a certain number of lines long (default: 5). In most cases this is a sign of poor
104+
code structure and an opportunity to consolidate classes or functions.
105+
106+
#### PHPStan
107+
108+
*Requires **phpstan.neon.dist***
109+
110+
Static analysis is a major factor in catching bugs and issues before they happen. PHPStan will
111+
analyze your code for mistakes based on the configuration supplied.
112+
113+
#### PHPUnit
114+
115+
*Requires **phpunit.xml.dist***
116+
117+
Unit testing automates running your code through all the possible scenarios before putting it
118+
into use in production. PHPUnit is a highly-configurable framework and suite for writing and
119+
running unit tests. This workflow also configures PHPUnit to report on code coverage and
120+
upload the results to [Coveralls.io](https://coveralls.io) (you will need a free account,
121+
but it is also fine to use this workflow without Coveralls).
122+
123+
#### Unused
124+
125+
Composer Unused does one thing: checks that your code actually uses the dependencies you
126+
have included via Composer. It can be easy to forget to update your **composer.json** when
127+
your code drops a dependency, so this workflow will help track those down.

src/.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: composer
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: daily

src/.github/workflows/deptrac.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Deptrac
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- 'composer.**'
10+
- 'depfile.yaml'
11+
- '.github/workflows/deptrac.yml'
12+
push:
13+
branches:
14+
- develop
15+
paths:
16+
- '**.php'
17+
- 'composer.**'
18+
- 'depfile.yaml'
19+
- '.github/workflows/deptrac.yml'
20+
21+
jobs:
22+
build:
23+
name: Dependency Tracing
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Set up PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: '8.0'
35+
tools: phive
36+
extensions: intl, json, mbstring, xml
37+
coverage: none
38+
env:
39+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Get composer cache directory
42+
id: composer-cache
43+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v2
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
50+
restore-keys: ${{ runner.os }}-composer-
51+
52+
- name: Create Deptrac cache directory
53+
run: mkdir -p build/
54+
55+
- name: Cache Deptrac results
56+
uses: actions/cache@v2
57+
with:
58+
path: build
59+
key: ${{ runner.os }}-deptrac-${{ github.sha }}
60+
restore-keys: ${{ runner.os }}-deptrac-
61+
62+
- name: Install dependencies
63+
run: |
64+
composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}"
65+
if [ -f composer.lock ]; then
66+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
67+
else
68+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
69+
fi
70+
71+
- name: Trace dependencies
72+
run: |
73+
sudo phive --no-progress install --global --trust-gpg-keys B8F640134AB1782E,A98E898BB53EB748 qossmic/deptrac
74+
deptrac analyze --cache-file=build/deptrac.cache

src/.github/workflows/infection.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Infection
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- 'composer.**'
10+
- 'phpunit*'
11+
- '.github/workflows/infection.yml'
12+
push:
13+
branches:
14+
- develop
15+
paths:
16+
- '**.php'
17+
- 'composer.**'
18+
- 'phpunit*'
19+
- '.github/workflows/infection.yml'
20+
21+
jobs:
22+
main:
23+
name: Mutation Testing
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Set up PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: '8.0'
35+
tools: infection, phpunit
36+
extensions: intl, json, mbstring, gd, xml, sqlite3
37+
coverage: xdebug
38+
env:
39+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Set up problem matchers for PHPUnit
42+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
43+
44+
- name: Configure matchers
45+
uses: mheap/phpunit-matcher-action@v1
46+
47+
- name: Get composer cache directory
48+
id: composer-cache
49+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
50+
51+
- name: Cache composer dependencies
52+
uses: actions/cache@v2
53+
with:
54+
path: ${{ steps.composer-cache.outputs.dir }}
55+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
56+
restore-keys: ${{ runner.os }}-composer-
57+
58+
- name: Install dependencies
59+
run: |
60+
composer -q config -g github-oauth.github.com "${{ secrets.GITHUB_TOKEN }}"
61+
if [ -f composer.lock ]; then
62+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
63+
else
64+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
65+
fi
66+
67+
- name: Test with PHPUnit
68+
run: vendor/bin/phpunit --teamcity
69+
70+
- name: Mutate with Infection
71+
run: |
72+
git fetch --depth=1 origin $GITHUB_BASE_REF
73+
infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations

src/.github/workflows/phpcpd.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PHPCPD
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- '.github/workflows/phpcpd.yml'
10+
push:
11+
branches:
12+
- develop
13+
paths:
14+
- '**.php'
15+
- '.github/workflows/phpcpd.yml'
16+
17+
jobs:
18+
build:
19+
name: Code Copy-Paste Detection
20+
runs-on: ubuntu-latest
21+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: '8.0'
31+
tools: phpcpd
32+
extensions: dom, mbstring
33+
coverage: none
34+
35+
- name: Detect duplicate code
36+
run: phpcpd app/ src/ tests/

0 commit comments

Comments
 (0)