Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 3, 2020
1 parent 6a045e1 commit cae1a94
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.1] - 2020-12-03
### Added
- Support for PHP 8.0

## [2.0.0] - 2019-11-30
### Added
- Added a second argument to the constructor to set a `ResponseFactoryInterface`
Expand All @@ -21,5 +25,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## 1.0.0 - 2018-06-07
First version

[2.0.1]: https://github.com/middlewares/reporting-logger/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/middlewares/reporting-logger/compare/v1.1.0...v2.0.0
[1.1.0]: https://github.com/middlewares/reporting-logger/compare/v1.0.0...v1.1.0
53 changes: 33 additions & 20 deletions tests/ReportingLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

class ReportingLoggerTest extends TestCase
{
/**
* phpunit 8 support
*/
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
if (method_exists(parent::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
return;
}

self::assertRegExp($pattern, $string, $message);
}

private function createLogger(): array
{
$logs = fopen('php://temp', 'r+');
Expand All @@ -36,9 +49,9 @@ function () {

rewind($logs);

$this->assertSame(200, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
$this->assertMatchesRegularExpression('#.* test.ERROR: Reporting .*#', stream_get_contents($logs));
self::assertSame(200, $response->getStatusCode());
self::assertEmpty((string) $response->getBody());
self::assertMatchesRegularExpression('#.* test.ERROR: Reporting .*#', stream_get_contents($logs));
}

public function testCustomMessage()
Expand All @@ -57,9 +70,9 @@ function () {

rewind($logs);

$this->assertSame(200, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
$this->assertMatchesRegularExpression('#.* test.ERROR: Csp Error .*#', stream_get_contents($logs));
self::assertSame(200, $response->getStatusCode());
self::assertEmpty((string) $response->getBody());
self::assertMatchesRegularExpression('#.* test.ERROR: Csp Error .*#', stream_get_contents($logs));
}

public function testCustomMessageWithVariable()
Expand All @@ -78,9 +91,9 @@ function () {

rewind($logs);

$this->assertSame(200, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
$this->assertMatchesRegularExpression('#.* test.ERROR: Error: Foo in %{var2} and \[1,2,3\] .*#', stream_get_contents($logs));
self::assertSame(200, $response->getStatusCode());
self::assertEmpty((string) $response->getBody());
self::assertMatchesRegularExpression('#.* test.ERROR: Error: Foo in %{var2} and \[1,2,3\] .*#', stream_get_contents($logs));
}

public function testCustomPath()
Expand All @@ -99,9 +112,9 @@ function () {

rewind($logs);

$this->assertSame(200, $response->getStatusCode());
$this->assertEmpty((string) $response->getBody());
$this->assertMatchesRegularExpression('#.* test.ERROR: Reporting .*#', stream_get_contents($logs));
self::assertSame(200, $response->getStatusCode());
self::assertEmpty((string) $response->getBody());
self::assertMatchesRegularExpression('#.* test.ERROR: Reporting .*#', stream_get_contents($logs));
}

public function testMethod()
Expand All @@ -120,8 +133,8 @@ function () {

rewind($logs);

$this->assertEquals('no reporting', (string) $response->getBody());
$this->assertEmpty(stream_get_contents($logs));
self::assertEquals('no reporting', (string) $response->getBody());
self::assertEmpty(stream_get_contents($logs));
}

public function testPath()
Expand All @@ -140,8 +153,8 @@ function () {

rewind($logs);

$this->assertEquals('no reporting', (string) $response->getBody());
$this->assertEmpty(stream_get_contents($logs));
self::assertEquals('no reporting', (string) $response->getBody());
self::assertEmpty(stream_get_contents($logs));
}

public function testEmptyData()
Expand All @@ -159,8 +172,8 @@ function () {

rewind($logs);

$this->assertEquals('no reporting', (string) $response->getBody());
$this->assertEmpty(stream_get_contents($logs));
self::assertEquals('no reporting', (string) $response->getBody());
self::assertEmpty(stream_get_contents($logs));
}

public function testCspReport()
Expand Down Expand Up @@ -193,7 +206,7 @@ function () {

rewind($logs);

$this->assertEmpty((string) $response->getBody());
$this->assertMatchesRegularExpression('#.* test.ERROR: Reporting \{"csp-report"\:\{.*#', stream_get_contents($logs));
self::assertEmpty((string) $response->getBody());
self::assertMatchesRegularExpression('#.* test.ERROR: Reporting \{"csp-report"\:\{.*#', stream_get_contents($logs));
}
}

0 comments on commit cae1a94

Please sign in to comment.