Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
* Remove phan from dev dependencies
* Add static analysis, mutation testing, readme docs
* More tests and 100% MSI
  • Loading branch information
samdark committed Dec 25, 2020
1 parent 26210fb commit 4d7d71b
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 61 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,83 @@
on:
- pull_request
- push

name: build

jobs:
tests:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
extensions: ctype, json, mbstring
key: cache-v1

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest
- windows-latest

php:
- "7.4"
- "8.0"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: date.timezone='UTC'
coverage: pcov
tools: composer:v2

- name: Determine composer cache directory on Linux
if: matrix.os == 'ubuntu-latest'
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows
if: matrix.os == 'windows-latest'
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer php 7.4
if: matrix.php == '7.4'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install dependencies with composer php 8.0
if: matrix.php == '8.0'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit
run: vendor/bin/phpunit --colors=always
61 changes: 61 additions & 0 deletions .github/workflows/mutation.yml
@@ -0,0 +1,61 @@
on:
pull_request:
push:
branches:
- "master"

name: mutation test

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
extensions: ctype, json, mbstring

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "7.4"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: ${{ env.extensions }}
ini-values: memory_limit=-1
coverage: "pcov"
tools: composer:v2

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run infection
run: |
git fetch --depth=1 origin $GITHUB_BASE_REF
vendor/bin/roave-infection-static-analysis-plugin -j2 --git-diff-filter=A --git-diff-base=origin/$GITHUB_BASE_REF --logger-github --ignore-msi-with-no-mutations --only-covered
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
50 changes: 50 additions & 0 deletions .github/workflows/static.yml
@@ -0,0 +1,50 @@
on:
- pull_request
- push

name: static analysis

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "7.4"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize
74 changes: 69 additions & 5 deletions README.md
@@ -1,21 +1,85 @@
<p align="center">
<a href="https://github.com/yiisoft" target="_blank">
<img src="https://avatars0.githubusercontent.com/u/993323" height="100px">
<img src="https://yiisoft.github.io/docs/images/yii_logo.svg" height="100px">
</a>
<h1 align="center">i18n</h1>
<h1 align="center">Yii Caching Library</h1>
<br>
</p>

The package provides common internationalization utilities such as locale.

[![Latest Stable Version](https://poser.pugx.org/yiisoft/i18n/v/stable.png)](https://packagist.org/packages/yiisoft/i18n)
[![Total Downloads](https://poser.pugx.org/yiisoft/i18n/downloads.png)](https://packagist.org/packages/yiisoft/i18n)
[![Build Status](https://travis-ci.com/yiisoft/i18n.svg?branch=master)](https://travis-ci.com/yiisoft/i18n)
[![Build status](https://github.com/yiisoft/i18n/workflows/build/badge.svg)](https://github.com/yiisoft/i18n/actions?query=workflow%3Abuild)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/i18n/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/i18n/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/i18n/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/i18n/?branch=master)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fi18n%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/i18n/master)
[![static analysis](https://github.com/yiisoft/i18n/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/i18n/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/i18n/coverage.svg)](https://shepherd.dev/github/yiisoft/i18n)

The package provides common internationalization utilities.

## Features

- Locale - stores locale information created from BCP 47 formatted string. Can parse locale string, modify locale parts,
form locale string from parts, and derive fallback locale.

## Installation

The package could be installed with composer:

```
composer install yiisoft/i18n
```

## General usage

```php
$locale = new \Yiisoft\I18n\Locale('es-CL');
echo $locale->language(); // es
echo $locale->region(); // CL

$locale = $locale->withLanguage('en');
echo $locale->asString(); // en-CL

echo $locale->fallbackLocale()->asString(); // en
```

### Unit testing

```shell
./vendor/bin/phpunit
```

### Mutation testing

The package tests are checked with [Infection](https://infection.github.io/) mutation framework. To run it:

```shell
./vendor/bin/infection
```

### Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```shell
./vendor/bin/psalm
```

### Support the project

[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective&logoColor=7eadf1&labelColor=555555)](https://opencollective.com/yiisoft)

### Follow updates

[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)
[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555?style=flat)](https://twitter.com/yiiframework)
[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat&logo=telegram)](https://t.me/yii3ru)
[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat&logo=facebook&logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)
[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat&logo=slack)](https://yiiframework.com/go/slack)

## License

The Yii i18n Library is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.

Maintained by [Yii Software](https://www.yiiframework.com/).
5 changes: 1 addition & 4 deletions composer.json
Expand Up @@ -4,9 +4,7 @@
"description": "Yii i18n",
"keywords": [
"i18n",
"translation",
"internationalization",
"formatting"
"locale"
],
"homepage": "http://www.yiiframework.com/",
"license": "BSD-3-Clause",
Expand All @@ -21,7 +19,6 @@
"php": "^7.4|^8.0"
},
"require-dev": {
"phan/phan": "^3.0",
"phpunit/phpunit": "^9.4",
"roave/infection-static-analysis-plugin": "^1.5",
"spatie/phpunit-watcher": "^1.23",
Expand Down
16 changes: 16 additions & 0 deletions infection.json.dist
@@ -0,0 +1,16 @@
{
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "php:\/\/stderr",
"badge": {
"branch": "master"
}
},
"mutators": {
"@default": true
}
}
47 changes: 18 additions & 29 deletions phpunit.xml.dist
@@ -1,31 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Yii i18n tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Yii i18n tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 4d7d71b

Please sign in to comment.