Skip to content

Commit

Permalink
Merge pull request #17 from tattersoftware/service-path
Browse files Browse the repository at this point in the history
Service Path
  • Loading branch information
MGatner committed Feb 16, 2021
2 parents d37c7f5 + 9f695be commit e621791
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 68 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/.github export-ignore
/docs export-ignore
/examples export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/phpstan.neon.dist export-ignore

# Configure diff output for .php and .phar files.
*.php diff=php
*.phar -diff
3 changes: 1 addition & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
interval: daily
24 changes: 17 additions & 7 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
paths:
- 'src/**'
- 'tests/**'
- 'composer.**'
- 'phpstan*'
- '.github/workflows/analyze.yml'
push:
Expand All @@ -17,46 +18,55 @@ on:
paths:
- 'src/**'
- 'tests/**'
- 'composer.**'
- 'phpstan*'
- '.github/workflows/analyze.yml'

jobs:
build:
name: Analyze code (PHPStan)
name: PHP ${{ matrix.php-versions }} Static Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4', '8.0']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: intl
php-version: ${{ matrix.php-versions }}
tools: composer, pecl, phpunit
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Create composer cache directory
run: mkdir -p ${{ steps.composer-cache.outputs.dir }}

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Create PHPStan result cache directory
- name: Create PHPStan cache directory
run: mkdir -p build/phpstan

- name: Cache PHPStan result
- name: Cache PHPStan results
uses: actions/cache@v2
with:
path: build/phpstan
key: ${{ runner.os }}-phpstan-${{ github.sha }}
restore-keys: ${{ runner.os }}-phpstan-

- name: Install dependencies
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

Expand Down
43 changes: 37 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ name: PHPUnit

on:
pull_request:
branches:
branches:
- develop
push:
branches:
- develop

jobs:
main:
name: Build and test
name: PHP ${{ matrix.php-versions }} Unit Tests

strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0']

runs-on: ubuntu-latest

Expand Down Expand Up @@ -41,9 +44,37 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
run: composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
- name: Test with PHPUnit
run: vendor/bin/phpunit --verbose --coverage-text
env:
TERM: xterm-256color

- if: matrix.php-versions == '8.0'
name: Mutate with Infection
run: |
composer global require infection/infection
git fetch --depth=1 origin $GITHUB_BASE_REF
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
- if: matrix.php-versions == '8.0'
name: Run Coveralls
run: vendor/bin/php-coveralls --verbose --coverage_clover=build/phpunit/clover.xml --json_path build/phpunit/coveralls-upload.json
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }}

coveralls:
needs: [main]
name: Coveralls Finished
runs-on: ubuntu-latest
steps:
- name: Upload Coveralls results
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
38 changes: 18 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "tatter/handlers",
"type": "library",
"description": "Cross-module handler registration, for CodeIgniter 4",
"keywords": [
"codeigniter",
Expand All @@ -20,41 +21,38 @@
"role": "Developer"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php" : ">=7.2"
"php": "^7.3 || ^8.0"
},
"require-dev": {
"codeigniter4/codeigniter4": "dev-develop",
"fzaninotto/faker": "^1.9@dev",
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.5",
"codeigniter4/codeigniter4-standard": "^1.0"
"tatter/tools": "^1.6"
},
"autoload": {
"psr-4": {
"Tatter\\Handlers\\": "src"
}
},
"exclude-from-classmap": [
"**/Database/Migrations/**"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\Support\\": "tests/_support"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"analyze": "phpstan analyze",
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 src/ tests/",
"test": "phpunit",
"post-update-cmd": [
"composer dump-autoload"
]
"mutate": "infection --threads=2 --coverage=build/phpunit",
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
"test": "phpunit"
}
}
19 changes: 19 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"source": {
"directories": [
"src"
],
"excludes": [
"Config",
"Database/Migrations",
"Views"
]
},
"logs": {
"text": "build/infection.log"
},
"mutators": {
"@default": true
},
"bootstrap": "vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
}
13 changes: 10 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ parameters:
- tests
bootstrapFiles:
- vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php
excludes_analyse:
- src/Config/Routes.php
- src/Views/*
ignoreErrors:
- '#Call to an undefined static method Config\\Services::[A-Za-z]+\(\)#'
universalObjectCratesClasses:
- CodeIgniter\Entity
- Faker\Generator
scanDirectories:
- vendor/codeigniter4/codeigniter4/system/Helpers
dynamicConstantNames:
- ENVIRONMENT
- APP_NAMESPACE
- CI_DEBUG
ignoreErrors:
- '#Call to an undefined static method Config\\Services::handlers\(\)#'
- ENVIRONMENT
66 changes: 39 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
executionOrder="random"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
stopOnSkipped="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/Config/Routes.php</file>
</exclude>
<report>
<clover outputFile="build/phpunit/clover.xml"/>
<html outputDirectory="build/phpunit/html"/>
<php outputFile="build/phpunit/coverage.serialized"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
<xml outputDirectory="build/phpunit/xml-coverage"/>
</report>
</coverage>

<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/Config/Routes.php</file>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/logs/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="testdox-html" target="build/logs/testdox.html"/>
<log type="testdox-text" target="build/logs/testdox.txt"/>
<log type="junit" target="build/logs/logfile.xml"/>
<testdoxHtml outputFile="build/phpunit/testdox.html"/>
<testdoxText outputFile="build/phpunit/testdox.txt"/>
<junit outputFile="build/phpunit/junit.xml"/>
</logging>

<php>
<env name="XDEBUG_MODE" value="coverage"/>
<server name="app.baseURL" value="http://example.com"/>

<!-- Directory containing phpunit.xml -->
Expand All @@ -47,13 +55,17 @@
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>

<!-- <env name="database.tests.hostname" value="localhost"/> -->
<!-- <env name="database.tests.database" value="tests"/> -->
<!-- <env name="database.tests.username" value="tests_user"/> -->
<!-- <env name="database.tests.password" value=""/> -->
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
<env name="database.tests.database" value=":memory:"/>
<env name="database.tests.DBDriver" value="SQLite3"/>
<!-- https://getcomposer.org/xdebug -->
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>

<!-- Database configuration -->
<!-- Uncomment to use alternate testing database configuration
<env name="database.tests.hostname" value="localhost"/>
<env name="database.tests.database" value="tests"/>
<env name="database.tests.username" value="tests_user"/>
<env name="database.tests.password" value=""/>
<env name="database.tests.DBDriver" value="MySQLi"/>
<env name="database.tests.DBPrefix" value="tests_"/>
-->
</php>
</phpunit>
14 changes: 11 additions & 3 deletions src/Config/Services.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php namespace Tatter\Handlers\Config;

use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\BaseService;
use Config\Services as BaseServices;
use Tatter\Handlers\Handlers;
use Tatter\Handlers\Config\Handlers as HandlersConfig;

class Services extends BaseService
class Services extends BaseServices
{
/**
* @param string $path
Expand All @@ -17,7 +17,15 @@ public static function handlers(string $path = '', HandlersConfig $config = null
{
if ($getShared)
{
return static::getSharedInstance('handlers', $path, $config, $cache);
$service = static::getSharedInstance('handlers', $path, $config, $cache);

// Need to make sure the path is correct
if ($path && $path !== $service->getPath())
{
$service = (clone $service)->setPath($path);
}

return $service;
}

return new Handlers($path, $config, $cache);
Expand Down

0 comments on commit e621791

Please sign in to comment.