Skip to content

Commit

Permalink
Upgrade to PHP 8.1 (#6)
Browse files Browse the repository at this point in the history
* Updated PHP requirements to >=8.0

* Removed Scrutinizer integration

* Updated Codeception to ^5 and replaced `zendframework/zend-diactoros` with `nyholm/psr7`

* Updated `mindplay/middleman` to ^4

* Replaced Travis with Github Actions
  • Loading branch information
vortrixs authored Aug 24, 2022
1 parent a6e8d64 commit 4aeed0d
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 131 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Codeception tests

on: [push]

jobs:
build:
name: ${{matrix.operating-system}}, PHP ${{ matrix.php }}

runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
operating-system: [ ubuntu-latest, ubuntu-20.04 ]
php: [ '8.0', '8.1' ]

steps:
- uses: actions/checkout@master

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: ${{ matrix.php }}

- name: Install dependencies
run: composer install

- name: Run tests
run: php vendor/bin/codecept run
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
/vendor
/tests/_output/
/tests/_support/_generated/**/*
/tests/*.suite.yml
4 changes: 0 additions & 4 deletions .scrutinizer.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kodus/chrome-logger
===================

[![PHP Version](https://img.shields.io/badge/php-7.0%2B-blue.svg)](https://packagist.org/packages/kodus/chrome-logger)
[![PHP Version](https://img.shields.io/badge/php-8.0%2B-blue.svg)](https://packagist.org/packages/kodus/chrome-logger)
[![Build Status](https://travis-ci.org/kodus/chrome-logger.svg?branch=master)](https://travis-ci.org/kodus/chrome-logger)
[![Code Coverage](https://scrutinizer-ci.com/g/kodus/chrome-logger/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/kodus/chrome-logger/?branch=master)

Expand Down
4 changes: 1 addition & 3 deletions codeception.dist.yml → codeception.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
actor: Tester
paths:
tests: tests
log: tests/_output
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=8.0",
"psr/log": "^1",
"psr/http-message": "^1",
"psr/http-server-middleware": "^1"
},
"require-dev": {
"codeception/codeception": "^2",
"mockery/mockery": "^0.9",
"zendframework/zend-diactoros": "^1.8.5",
"mindplay/middleman": "^3.0.3"
"codeception/codeception": "^5",
"codeception/module-asserts": "^3",
"mockery/mockery": "^1.5",
"nyholm/psr7": "^1.5",
"mindplay/middleman": "^4"
},
"autoload": {
"psr-4": {
Expand All @@ -38,4 +39,4 @@
"Kodus\\Logging\\Test\\Unit\\": "tests/unit/"
}
}
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/Bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Kodus\Logging\Test\Fixtures;

class Bar extends Foo
{
public $bat = "BAT";
}
17 changes: 17 additions & 0 deletions tests/Fixtures/Baz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Kodus\Logging\Test\Fixtures;

class Baz
{
public $foo;
public $bar;
public $baz;

public function __construct()
{
$this->foo = new Foo();
$this->bar = new Bar();
$this->baz = $this;
}
}
10 changes: 10 additions & 0 deletions tests/Fixtures/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Kodus\Logging\Test\Fixtures;

class Foo
{
public $foo = "FOO";
protected $bar = "BAR";
private $baz = "BAZ";
}
30 changes: 30 additions & 0 deletions tests/Mocks/MockMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Kodus\Logging\Test\Mocks;

use Kodus\Logging\ChromeLogger;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class MockMiddleware implements MiddlewareInterface
{
/**
* @var ChromeLogger
*/
private $logger;

public function __construct(ChromeLogger $logger)
{
$this->logger = $logger;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->logger->notice("running mock middleware");

return new Response(headers: ['Content-Type' => 'text/plain'], body: "Hello");
}
}
2 changes: 0 additions & 2 deletions tests/_bootstrap.php

This file was deleted.

29 changes: 2 additions & 27 deletions tests/example.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

use Kodus\Logging\ChromeLogger;
use Kodus\Logging\Test\Fixtures\Baz;

require dirname(__DIR__) . '/vendor/autoload.php';

// ChromeLogger output example - run on a web-server and open in a browser.

function foo()
function foo(): void
{
bar();
}
Expand All @@ -16,32 +17,6 @@ function bar()
throw new RuntimeException("ouch!"); // for stack-trace test!
}

class Foo
{
public $foo = "FOO";
protected $bar = "BAR";
private $baz = "BAZ";
}

class Bar extends Foo
{
public $bat = "BAT";
}

class Baz
{
public $foo;
public $bar;
public $baz;

public function __construct()
{
$this->foo = new Foo();
$this->bar = new Bar();
$this->baz = $this;
}
}

try {
foo();
} catch (RuntimeException $e) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit.suite.dist.yml → tests/unit.suite.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class_name: UnitTester
actor: UnitTester
modules:
enabled:
- Asserts
Expand Down
58 changes: 17 additions & 41 deletions tests/unit/ChromeLoggerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,20 @@
namespace Kodus\Logging\Test\Unit;

use Codeception\Util\FileSystem;
use function json_decode;
use Kodus\Logging\ChromeLogger;
use Kodus\Logging\Test\Fixtures\Bar;
use Kodus\Logging\Test\Fixtures\Baz;
use Kodus\Logging\Test\Fixtures\Foo;
use Mockery;
use Mockery\MockInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;
use function str_repeat;
use UnitTester;
use Zend\Diactoros\Response;

class Foo
{
public $foo = "FOO";
protected $bar = "BAR";
private $baz = "BAZ";
}

class Bar extends Foo
{
public $bat = "BAT";
}

class Baz
{
public $foo;
public $bar;
public $baz;

public function __construct()
{
$this->foo = new Foo();
$this->bar = new Bar();
$this->baz = $this;
}
}

class ChromeLoggerCest
{
public function writeLogMessages(UnitTester $I)
public function writeLogMessages(UnitTester $I): void
{
$logger = new ChromeLogger();

Expand Down Expand Up @@ -73,7 +48,7 @@ public function writeLogMessages(UnitTester $I)
);
}

public function serializeContextValues(UnitTester $I)
public function serializeContextValues(UnitTester $I): void
{
$logger = new ChromeLogger();

Expand Down Expand Up @@ -129,7 +104,7 @@ public function serializeContextValues(UnitTester $I)
fclose($resource);
}

public function obtainStackTrace(UnitTester $I)
public function obtainStackTrace(UnitTester $I): void
{
try {
$this->foo();
Expand Down Expand Up @@ -157,7 +132,7 @@ public function obtainStackTrace(UnitTester $I)
], $data["rows"]);
}

public function renderTables(UnitTester $I)
public function renderTables(UnitTester $I): void
{
$logger = new ChromeLogger();

Expand All @@ -178,14 +153,14 @@ public function renderTables(UnitTester $I)
], $data["rows"]);
}

public function truncateExcessiveLogData(UnitTester $I)
public function truncateExcessiveLogData(UnitTester $I): void
{
$logger = new ChromeLogger();

$logger->setLimit(10*1024);

for ($n=0; $n<200; $n++) {
$message = str_repeat("0123456789", rand(1,20)); // between 10 and 200 bytes
$message = str_repeat("0123456789", rand(1, 20)); // between 10 and 200 bytes

$logger->debug($message);
}
Expand All @@ -195,7 +170,7 @@ public function truncateExcessiveLogData(UnitTester $I)
$I->assertEquals(ChromeLogger::LIMIT_WARNING, end($data["rows"])[0][0]);
}

public function persistToLocalFiles(UnitTester $I)
public function persistToLocalFiles(UnitTester $I): void
{
$logger = new class extends ChromeLogger
{
Expand Down Expand Up @@ -242,7 +217,7 @@ protected function getTime(): int
$logger->debug(str_repeat("0123456789", 20));
}

$response = new Response(fopen("php://temp", "rw+"));
$response = new Response(body: fopen("php://temp", "rw+"));

$response = $logger->writeToResponse($response);

Expand Down Expand Up @@ -278,7 +253,7 @@ protected function getTime(): int
"previous {$num_files} log-files should be garbage-collected");
}

public function allowMultipleLocationHeaders(UnitTester $I)
public function allowMultipleLocationHeaders(UnitTester $I): void
{
$logger = new ChromeLogger();

Expand All @@ -294,7 +269,7 @@ public function allowMultipleLocationHeaders(UnitTester $I)

$logger->info("TEST");

$response = new Response(fopen("php://temp", "rw+"));
$response = new Response(body: fopen("php://temp", "rw+"));

$response = $response->withHeader("X-ServerLog-Location", "/foo");

Expand All @@ -312,7 +287,7 @@ public function allowMultipleLocationHeaders(UnitTester $I)
*
* @return array
*/
private function extractResult(ChromeLogger $logger)
private function extractResult(ChromeLogger $logger): array
{
/**
* @var MockInterface|ResponseInterface $response
Expand All @@ -336,7 +311,8 @@ private function extractResult(ChromeLogger $logger)
return json_decode(base64_decode($calls[0][1]), true);
}

private function foo() {
private function foo(): void
{
$this->bar();
}

Expand Down
Loading

0 comments on commit 4aeed0d

Please sign in to comment.