Skip to content

Commit 950a9da

Browse files
authored
Merge pull request #1 from cspray/feature/buffer-object
Refactor API to use Buffer object instead of identifier
2 parents e52d27f + bbcb7b2 commit 950a9da

File tree

12 files changed

+501
-477
lines changed

12 files changed

+501
-477
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ jobs:
1111

1212
runs-on: ubuntu-latest
1313

14+
env:
15+
XDEBUG_MODE: coverage
16+
1417
steps:
15-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1619
- name: Composer
1720
uses: php-actions/composer@v6
1821
- name: Tests
1922
uses: php-actions/phpunit@v3
2023
with:
21-
version: 10.0
24+
php_extensions: "xdebug"

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Let's take a look at a quick code example.
1919

2020
namespace Cspray\StreamBufferDemo;
2121

22-
use Cspray\StreamBufferIntercept\BufferIdentifier;use Cspray\StreamBufferIntercept\StreamBuffer;
22+
use Cspray\StreamBufferIntercept\Buffer;
23+
use Cspray\StreamBufferIntercept\StreamFilter;
2324
use PHPUnit\Framework\TestCase;
2425

2526
class MyLogger {
@@ -44,36 +45,36 @@ class MyLogger {
4445

4546
class MyLoggerTest extends TestCase {
4647

47-
private BufferIdentifier $stdout;
48+
private Buffer $stdout;
4849

49-
private BufferIdentifier $stderr;
50+
private Buffer $stderr;
5051

5152
private MyLogger $subject;
5253

5354
protected function setUp() : void{
54-
StreamBuffer::register();
55-
$this->stdout = StreamBuffer::intercept(STDOUT);
56-
$this->stderr = StreamBuffer::intercept(STDERR);
55+
StreamFilter::register();
56+
$this->stdout = StreamFilter::intercept(STDOUT);
57+
$this->stderr = StreamFilter::intercept(STDERR);
5758
$this->subject = new MyLogger(STDOUT, STDERR);
5859
}
5960

6061
protected function tearDown() : void{
61-
StreamBuffer::stopIntercepting($this->stdout);
62-
StreamBuffer::stopIntercepting($this->stderr);
62+
StreamFilter::stopIntercepting($this->stdout);
63+
StreamFilter::stopIntercepting($this->stderr);
6364
}
6465

6566
public function testLogMessageSentToStdOutAndNotStdErr() : void {
6667
$this->subject->log('My stdout output');
6768

68-
self::assertSame('My stdout output', StreamBuffer::output($this->stdout));
69-
self::assertSame('', StreamBuffer::output($this->stderr));
69+
self::assertSame('My stdout output', $this->stdout->output());
70+
self::assertSame('', $this->stderr->output());
7071
}
7172

7273
public function testLogErrorMessageSentToStdErrAndNotStdOut() : void {
7374
$this->subject->logError('My stderr output');
7475

75-
self::assertSame('My stderr output', StreamBuffer::output($this->stderr));
76-
self::assertSame('', StreamBuffer::output($this->stdout));
76+
self::assertSame('My stderr output', $this->stderr->output());
77+
self::assertSame('', $this->stdout->output());
7778
}
7879
}
7980
```

composer.lock

Lines changed: 39 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
cacheDirectory=".phpunit.cache"
6-
executionOrder="depends,defects"
7-
requireCoverageMetadata="true"
8-
beStrictAboutCoverageMetadata="true"
9-
beStrictAboutOutputDuringTests="true"
10-
failOnRisky="true"
11-
failOnWarning="true">
12-
<testsuites>
13-
<testsuite name="default">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
18-
<coverage>
19-
<include>
20-
<directory suffix=".php">src</directory>
21-
</include>
22-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" requireCoverageMetadata="true" beStrictAboutCoverageMetadata="true" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true">
3+
<testsuites>
4+
<testsuite name="default">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<text outputFile="php://stdout" showOnlySummary="true"/>
11+
</report>
12+
</coverage>
13+
<source>
14+
<include>
15+
<directory suffix=".php">src</directory>
16+
</include>
17+
</source>
2318
</phpunit>

phpunit.xml.bak

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
requireCoverageMetadata="true"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
10+
failOnRisky="true"
11+
failOnWarning="true">
12+
<testsuites>
13+
<testsuite name="default">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<coverage>
19+
<include>
20+
<directory suffix=".php">src</directory>
21+
</include>
22+
<report>
23+
<text outputFile="php://stdout" showOnlySummary="true" />
24+
</report>
25+
</coverage>
26+
</phpunit>

src/Buffer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Cspray\StreamBufferIntercept;
4+
5+
interface Buffer {
6+
7+
public function stopIntercepting() : void;
8+
9+
public function output() : string;
10+
11+
public function reset() : void;
12+
13+
}

0 commit comments

Comments
 (0)