Skip to content

Commit

Permalink
Merge pull request #25 from cPintiuta/5.0
Browse files Browse the repository at this point in the history
Implemented tests, code sniffer, psalm and laminas coding standard
  • Loading branch information
alexmerlin authored Jul 28, 2023
2 parents 53c8976 + b03415f commit f5ab5ad
Show file tree
Hide file tree
Showing 24 changed files with 760 additions and 184 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run phpcs checks

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

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- 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@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
46 changes: 46 additions & 0 deletions .github/workflows/static-analisys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run static analysis

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

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- 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@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
46 changes: 46 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
- push

name: Run PHPUnit tests

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

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

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- 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@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
clover.xml
coveralls-upload.json
.phpcs-cache
.phpunit.result.cache

# Created by .ignore support plugin (hsz.mobi)
### Composer template
composer.phar
Expand Down
83 changes: 77 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,96 @@
# dot-session

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-session)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-session/5.2.0)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-session/5.4.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-session)](https://github.com/dotkernel/dot-session/blob/5.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-session/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/dot-session/actions/workflows/static-analysis.yml)

[![SymfonyInsight](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a/big.svg)](https://insight.symfony.com/projects/f6038340-d76b-4da8-9016-0472d4899f0a)


DotKernel session component extending and customizing [laminas-session](https://github.com/laminas/laminas-session)

## Installation

Run the following command in your project folder
```bash
$ composer require dotkernel/dot-session
```

composer require dotkernel/dot-session


## Configuration
Register `SessionMiddleware` in your application's pipeline by adding the following line to `config/pipeline.php`:

$app->pipe(Dot\Session\SessionMiddleware::class);


Register `dot-session`'s ConfigProvider in your application's configurations by adding the following line to `config/config.php`:

\Dot\Session\ConfigProvider::class,


## Usage
Basic usage to access and use the session object in your services:

### Method #1 - Factory
#### Step 1: Create a factory that retrieves the SessionManger from the container

Next, inject this service in you classes, wherever you need session.
```php
$app->pipe(SessionMiddleware::class);
class ExampleFactory
{
// code

public function __invoke(ContainerInterface $container)
{
return new ExampleService(
$container->get(SessionManager::class)
)
}
}
```

Register the factory in any mode you register factories on your project.

#### Step 2: Access through your Service

```php

class ExampleService
{
private SessionManager $session;

public function __construct(SessionManager $session)
{
$this->session = $session;
}

//you methods
}
```

### Method 2 - Injection
If you use annotated injection you can inject the Session Manager in your services.

```php
use Dot\AnnotatedServices\Annotation\Inject;
use Laminas\Session\SessionManager;

class ExampleService
{
private SessionManager $session;

/**
* @Inject({SessionManager::class})
*/
public function __construct(SessionManager $session)
{
$this->session = $session;
}

//your methods
}
```
31 changes: 27 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,39 @@
"psr/http-message": "^1.0.1",
"laminas/laminas-servicemanager": "^3.11.1",
"laminas/laminas-session": "^2.12.1",
"psr/http-server-middleware": "^1.0.1"
"psr/http-server-middleware": "^1.0.1",
"laminas/laminas-stdlib": "^3.7.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5.20",
"squizlabs/php_codesniffer": "^3.6.2",
"laminas/laminas-stdlib": "^3.7.1"
"phpunit/phpunit": "^10.2",
"laminas/laminas-coding-standard": "^2.5",
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": {
"Dot\\Session\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotTest\\Session\\": "test/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
20 changes: 20 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
12 changes: 12 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/|version|/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Dot Session Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
17 changes: 17 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
findUnusedCode="false"
findUnusedBaselineEntry="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" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
Loading

0 comments on commit f5ab5ad

Please sign in to comment.