Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unit tests #1

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|8.0|8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\""

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\""

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\""

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
with:
folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\""

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache vendor folder
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config .php_cs.dist.php --diff --dry-run

phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache vendor folder
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name : Run PHPStan for Guzzle 7
run: vendor/bin/phpstan analyse -c tests/phpstan.neon

phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ["7.2", "7.3", "8.0", "8.1"]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Cache vendor folder
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}-${{ matrix.php-versions }}

- name: Cache composer folder
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-composer-cache-${{ matrix.php-versions }}

- run: composer install

- name: Run PHPUnit
run: vendor/bin/phpunit --coverage-text
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# lightweight-container

[![Source Code](https://img.shields.io/badge/source-PrestaShopCorp/lightweight--container-blue.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container)
[![Latest Version](https://img.shields.io/github/release/PrestaShopCorp/lightweight-container.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/releases)
[![Software License](https://img.shields.io/badge/license-OSL-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/blob/main/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/PrestaShopCorp/lightweight-container/.github/workflows/php.yml?label=CI&logo=github&style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/actions?query=workflow%3ACI)

[//]: # ([![Total Downloads](https://img.shields.io/packagist/dt/PrestaShopCorp/lightweight-container.svg?style=flat-square)](https://packagist.org/packages/prestashopcorp/lightweight-container))

# Context

A module should not bundle and duplicate a heavy dependency from the framework used by the PrestaShop Core, we propose to replace module-lib-service-container with a simple service container to provide the following benefits :
Expand Down
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"PrestaShopCorp\\LightweightContainer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PrestaShopCorp\\LightweightContainer\\Test\\": "tests/src/"
}
},
"authors": [
{
"name": "hschoenenberger",
Expand All @@ -15,5 +20,14 @@
],
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"phpstan/phpstan": "^1.7",
"prestashop/php-dev-tools": "^4.2"
},
"scripts": {
"phpunit": "./vendor/bin/phpunit --coverage-text",
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config .php_cs.dist.php --diff"
}
}
2 changes: 1 addition & 1 deletion src/ServiceContainer/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
*/
public static function createInstance($configPath)
{
$container = new static($configPath);

Check failure on line 72 in src/ServiceContainer/ServiceContainer.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unsafe usage of new static().

Check failure on line 72 in src/ServiceContainer/ServiceContainer.php

View workflow job for this annotation

GitHub Actions / PHPStan

Unsafe usage of new static().
$container->loadConfig();
$container->init();

Expand All @@ -81,7 +81,7 @@
*/
public function loadConfig()
{
$this->config = require_once $this->configPath;
$this->config = require $this->configPath;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
paths:
- ../src
bootstrapFiles:
- ../vendor/autoload.php
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false

level: 6
16 changes: 16 additions & 0 deletions tests/src/ServiceContainer/ServiceContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace PrestaShopCorp\LightweightContainer\Test\ServiceContainer;

use PHPUnit\Framework\TestCase;

class ServiceContainerTest extends TestCase
{
/**
* @test
*/
public function itShouldTestSomething()
{
// TODO: implement tests
}
}
Loading