Skip to content

Commit

Permalink
Add new php versions to workflow (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
devanych authored Mar 27, 2023
1 parent ecc31f0 commit d02e7c3
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 93 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/.scrutinizer.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/psalm.xml.dist export-ignore
79 changes: 38 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
on:
- pull_request
- push
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'psalm.xml.dist'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'psalm.xml.dist'

name: build

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

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

env:
extensions: curl, mbstring, dom
key: cache-v1

strategy:
Expand All @@ -18,64 +34,45 @@ jobs:
- ubuntu-latest
- windows-latest

php-version:
php:
- "7.4"
- "8.0"
- "8.1"
- "8.2"

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

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

- name: Determine composer cache directory on Linux
- 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
- 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@v1
- name: Cache dependencies installed with composer.
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Update composer
- name: Update composer.
run: composer self-update

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

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

- name: PHPUnit run with coverage on Linux PHP 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
run: vendor/bin/phpunit --coverage-clover=coverage.clover

- name: PHPUnit run without coverage on Linux PHP 8.0
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '8.0'
run: vendor/bin/phpunit

- name: PHPUnit run without coverage on Windows
if: matrix.os == 'windows-latest'
run: vendor/bin/phpunit
- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Code coverage scrutinizer on Linux PHP 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- name: Run tests with phpunit.
run: vendor/bin/phpunit --colors=always
54 changes: 36 additions & 18 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
on:
- pull_request
- push
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'phpunit.xml.dist'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'phpunit.xml.dist'

name: static

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

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

Expand All @@ -15,39 +30,42 @@ jobs:
os:
- ubuntu-latest

php-version:
php:
- "7.4"
- "8.0"
- "8.1"
- "8.2"

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

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

- name: Determine composer cache directory
- 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
- name: Cache dependencies installed with composer.
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Update composer
- name: Update composer.
run: composer self-update

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

- name: PHPCS check
- name: PHPCS check.
run: vendor/bin/phpcs

- name: Psalm static analysis
- name: Psalm static analysis.
run: vendor/bin/psalm --no-progress
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.phpunit.result.cache
composer.lock
phpunit.xml
vendor
psalm.xml
vendor
49 changes: 32 additions & 17 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
build:
environment:
php: "7.4"
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
filter:
paths:
- "src/*"
checks:
php: true
tools:
php_code_coverage:
enabled: true
external_code_coverage:
timeout: 600
php: true

filter:
paths:
- "src/*"

build:
nodes:
analysis:
environment:
php: 7.4.12

tests:
override:
- php-scrutinizer-run

tests-and-coverage:
environment:
php: 7.4.12

dependencies:
override:
- composer self-update
- composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

tests:
override:
- command: "./vendor/bin/phpunit --coverage-clover ./coverage.xml"
on_node: 1
coverage:
file: coverage.xml
format: php-clover
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^5.3"
"vimeo/psalm": "^4.9|^5.2"
},
"provide": {
"psr/container-implementation": "1.0"
Expand Down
19 changes: 10 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="./vendor/autoload.php"
executionOrder="depends,defects"
bootstrap="vendor/autoload.php"
executionOrder="random"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertErrorsToExceptions="true"
resolveDependencies="true"
stopOnFailure="false"
failOnWarning="true"
failOnRisky="true"
verbose="true"
colors="true"
>
Expand All @@ -24,9 +25,9 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
8 changes: 4 additions & 4 deletions psalm.xml → psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
resolveFromConfigFile="true"
errorLevel="1"
findUnusedPsalmSuppress="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="src"/>
<ignoreFiles>
<directory name="vendor" />
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
</psalm>
3 changes: 2 additions & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ private function createObject(string $className): object

foreach ($constructor->getParameters() as $parameter) {
if ($type = $parameter->getType()) {
/** @var string $typeName */
$typeName = $type->getName();

if (!$type->isBuiltin() && ($this->has($typeName) || $this->isClassName($typeName))) {
$arguments[] = $this->get($typeName);
continue;
}

if ($type->isBuiltin() && $typeName === 'array' && !$parameter->isDefaultValueAvailable()) {
if ($typeName === 'array' && $type->isBuiltin() && !$parameter->isDefaultValueAvailable()) {
$arguments[] = [];
continue;
}
Expand Down

0 comments on commit d02e7c3

Please sign in to comment.