Skip to content

Commit

Permalink
Merge pull request #1 from cspray/feature/buffer-object
Browse files Browse the repository at this point in the history
Refactor API to use Buffer object instead of identifier
  • Loading branch information
cspray committed May 14, 2023
2 parents e52d27f + bbcb7b2 commit 950a9da
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 477 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ jobs:

runs-on: ubuntu-latest

env:
XDEBUG_MODE: coverage

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Composer
uses: php-actions/composer@v6
- name: Tests
uses: php-actions/phpunit@v3
with:
version: 10.0
php_extensions: "xdebug"
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Let's take a look at a quick code example.

namespace Cspray\StreamBufferDemo;

use Cspray\StreamBufferIntercept\BufferIdentifier;use Cspray\StreamBufferIntercept\StreamBuffer;
use Cspray\StreamBufferIntercept\Buffer;
use Cspray\StreamBufferIntercept\StreamFilter;
use PHPUnit\Framework\TestCase;

class MyLogger {
Expand All @@ -44,36 +45,36 @@ class MyLogger {

class MyLoggerTest extends TestCase {

private BufferIdentifier $stdout;
private Buffer $stdout;

private BufferIdentifier $stderr;
private Buffer $stderr;

private MyLogger $subject;

protected function setUp() : void{
StreamBuffer::register();
$this->stdout = StreamBuffer::intercept(STDOUT);
$this->stderr = StreamBuffer::intercept(STDERR);
StreamFilter::register();
$this->stdout = StreamFilter::intercept(STDOUT);
$this->stderr = StreamFilter::intercept(STDERR);
$this->subject = new MyLogger(STDOUT, STDERR);
}

protected function tearDown() : void{
StreamBuffer::stopIntercepting($this->stdout);
StreamBuffer::stopIntercepting($this->stderr);
StreamFilter::stopIntercepting($this->stdout);
StreamFilter::stopIntercepting($this->stderr);
}

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

self::assertSame('My stdout output', StreamBuffer::output($this->stdout));
self::assertSame('', StreamBuffer::output($this->stderr));
self::assertSame('My stdout output', $this->stdout->output());
self::assertSame('', $this->stderr->output());
}

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

self::assertSame('My stderr output', StreamBuffer::output($this->stderr));
self::assertSame('', StreamBuffer::output($this->stdout));
self::assertSame('My stderr output', $this->stderr->output());
self::assertSame('', $this->stdout->output());
}
}
```
73 changes: 39 additions & 34 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 16 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<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">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
26 changes: 26 additions & 0 deletions phpunit.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<text outputFile="php://stdout" showOnlySummary="true" />
</report>
</coverage>
</phpunit>
13 changes: 13 additions & 0 deletions src/Buffer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace Cspray\StreamBufferIntercept;

interface Buffer {

public function stopIntercepting() : void;

public function output() : string;

public function reset() : void;

}
Loading

0 comments on commit 950a9da

Please sign in to comment.