Skip to content

Commit

Permalink
Allow - values for %O and %I
Browse files Browse the repository at this point in the history
  • Loading branch information
kassner committed Aug 20, 2024
1 parent ebde075 commit 71f5a6f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Modified
- Replace psalm with phpstan
- Allow `-` values for `%O` and `%I`: https://github.com/kassner/log-parser/issues/66

## [2.1.1] - 2023-07-18
### Added
Expand Down
4 changes: 2 additions & 2 deletions src/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ final class LogParser
'%>s' => '(?P<status>\d{3}|-)',
'%b' => '(?P<responseBytes>(\d+|-))',
'%T' => '(?P<requestTime>(\d+\.?\d*))',
'%O' => '(?P<sentBytes>[0-9]+)',
'%I' => '(?P<receivedBytes>[0-9]+)',
'%O' => '(?P<sentBytes>(\d+|-))',
'%I' => '(?P<receivedBytes>(\d+|-))',
'\%\{(?P<name>[a-zA-Z]+)(?P<name2>[-]?)(?P<name3>[a-zA-Z]+)\}i' => '(?P<Header\\1\\3>.*?)',
'%D' => '(?P<timeServeRequest>[0-9]+)',
'%S' => '(?P<scheme>http|https)',
Expand Down
4 changes: 2 additions & 2 deletions tests/Format/BytesReceivedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Kassner\LogParser\Tests\Format;

use Kassner\LogParser\LogParser;
use Kassner\LogParser\Tests\Provider\PositiveInteger as PositiveIntegerProvider;
use Kassner\LogParser\Tests\Provider\NullableInteger as NullableIntegerProvider;

/**
* @format %I
*
* @description Bytes received, including request and headers, cannot be zero. You need to enable mod_logio to use this.
*/
class BytesReceivedTest extends PositiveIntegerProvider
class BytesReceivedTest extends NullableIntegerProvider
{
protected $parser;

Expand Down
4 changes: 2 additions & 2 deletions tests/Format/BytesSentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Kassner\LogParser\Tests\Format;

use Kassner\LogParser\LogParser;
use Kassner\LogParser\Tests\Provider\PositiveInteger as PositiveIntegerProvider;
use Kassner\LogParser\Tests\Provider\NullableInteger as NullableIntegerProvider;

/**
* @format %O
*
* @description Bytes sent, including headers, cannot be zero. You need to enable mod_logio to use this.
*/
class BytesSentTest extends PositiveIntegerProvider
class BytesSentTest extends NullableIntegerProvider
{
protected $parser;

Expand Down
31 changes: 31 additions & 0 deletions tests/Provider/NullableInteger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Kassner\LogParser\Tests\Provider;

class NullableInteger extends \PHPUnit\Framework\TestCase
{
public function successProvider()
{
return [
['1'],
['1234'],
['99999999'],
['100000000000000000000000'],
['0'],
['-'],
];
}

public function invalidProvider()
{
return [
['-1'],
['dummy 1234'],
['lala'],
['-100000000000000000000000'],
['12.34'],
['0.0'],
['-0'],
];
}
}

0 comments on commit 71f5a6f

Please sign in to comment.