Skip to content

Commit

Permalink
3.x (#10)
Browse files Browse the repository at this point in the history
* uses psr/log:^2.0|^3.0, colinodell/psr-testlogger for logger implementation

* uses php:^8.0 and phpunit:^9.0|^10.0

* gitignore update

* marked two tests as skipped as it depends on user preference and LoggerInterface implementation

* abstract test class rename

* added guzzlehhtp/promises:^2.0

* github workflows updated

* workflow update - remove guzzle promises from matrix

* type-hints added, isset removed with null coalescing operator

* readme update
  • Loading branch information
ssi-anik authored Aug 5, 2023
1 parent c636f7a commit 0c702ba
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 201 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/sniffer.yml

This file was deleted.

79 changes: 79 additions & 0 deletions .github/workflows/standard-test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: PSR-12 coding standard, Test, Coverage
on:
pull_request:
push:
branches:
- master
- dev

jobs:
coding-standard:
name: PSR-12 coding standard
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Install PHP code sniffer
run: composer global require squizlabs/php_codesniffer

- name: Check against PSR12 standard
run: |
`composer global config bin-dir --absolute --quiet`/phpcs --standard=PSR12 ./src
tests:
needs: coding-standard
name: PHP ${{ matrix.php }} - Guzzle ${{ matrix.guzzle }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: [ 8.0, 8.1, 8.2 ]
guzzle: [ ^6, ^7 ]

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

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json,curl

- name: Install dependencies
run: composer require guzzlehttp/guzzle:${{ matrix.guzzle }} --no-interaction --prefer-dist

- name: Run test suite
run: ./vendor/bin/phpunit --testdox

coverage:
needs: tests
name: Coverage
runs-on: ubuntu-latest

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

- uses: shivammathur/setup-php@v2
with:
coverage: pcov
php-version: 8.2
extensions: json,curl

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run tests for coverage
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Push to Codecov
run: bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
61 changes: 0 additions & 61 deletions .github/workflows/test-coverage.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ vendor/
.idea/
composer.lock
.phpunit.result.cache
coverage/
coverage*/
.phpunit.cache*
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ $options = [
* `\Loguzz\Formatter\ExceptionJsonFormatter`
- `tag` - **string**. **Empty** by default. When non-empty string, it'll log the formatted data under this tag. Tag can
be used to search for specific type of request/response in your log file or your storage.
- `force_json` - **bool**. It is only applicable when **tag** is non-empty string. If enabled, it will then log data as
json string, otherwise it'll log as an array.
- `force_json` - **bool**. **true** by default. It is only applicable when **tag** is non-empty string. If enabled, it
will then log data as
json string, otherwise it'll log as an array. **If set to** `false`, **the code may break due to the type-hint in
psr/log interface. If
your [logger interface supports array](https://github.com/laravel/framework/blob/dd5c5178274e64d0384dc30bf2c8139b00dba098/src/Illuminate/Log/Logger.php#L260),
it will work.**
- `separate` - **bool**. It is only applicable when **tag** is non-empty string. If enabled, it will then log data
in `{tag}.request`, `{tag}.success`, `{tag}.failure` for request logging, successful response and error response.

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": ">=7.1",
"php": "^8.0",
"guzzlehttp/guzzle": "^6.2|^7.1",
"guzzlehttp/promises": "^1.5",
"psr/log": "^1.0|^2.0|^3.0"
"guzzlehttp/promises": "^1.5|^2.0",
"psr/log": "^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5.15|^8.4|^9.0",
"monolog/monolog": "^1.12|^2.0"
"phpunit/phpunit": "^9.0|^10.0",
"colinodell/psr-testlogger": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
43 changes: 22 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="request">
<directory>tests/Formatter/Request</directory>
</testsuite>
<testsuite name="response">
<directory>tests/Formatter/Response</directory>
</testsuite>
<testsuite name="exception">
<directory>tests/Formatter/Exception</directory>
</testsuite>
<testsuite name="middleware">
<directory>tests/Middleware</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage/>
<testsuites>
<testsuite name="request">
<directory>tests/Formatter/Request</directory>
</testsuite>
<testsuite name="response">
<directory>tests/Formatter/Response</directory>
</testsuite>
<testsuite name="exception">
<directory>tests/Formatter/Exception</directory>
</testsuite>
<testsuite name="middleware">
<directory>tests/Middleware</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
19 changes: 5 additions & 14 deletions src/Formatter/RequestCurlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@

class RequestCurlFormatter extends AbstractRequestFormatter
{
/**
* @var string
*/
protected $command;
protected string $command;

/**
* @var int
*/
protected $currentLineLength;
protected int $currentLineLength;

/**
* @var string[]
*/
protected $options;
protected array $options;

/**
* @var int
*/
protected $commandLineLength;
protected int $commandLineLength;

public function __construct($commandLineLength = 100)
public function __construct(int $commandLineLength = 100)
{
$this->commandLineLength = $commandLineLength;
}
Expand Down
Loading

0 comments on commit 0c702ba

Please sign in to comment.