Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/examples/ export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^4.8"
"phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.36"
},
"autoload": {
"psr-4": { "Clue\\StreamFilter\\": "src/" },
"files": [ "src/functions_include.php" ]
},
"autoload-dev": {
"psr-4": { "Clue\\Tests\\StreamFilter\\": "tests/" }
}
}
9 changes: 2 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite>
<testsuite name="Stream Filter Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
53 changes: 37 additions & 16 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Clue\Tests\StreamFilter;

use Clue\StreamFilter;
use PHPUnit\Framework\TestCase;

class FilterTest extends PHPUnit_Framework_TestCase
class FilterTest extends TestCase
{
public function testAppendSimpleCallback()
{
Expand Down Expand Up @@ -254,9 +257,12 @@ public function testAppendThrows()

$this->removeErrorHandler();
$this->assertCount(1, $errors);
$this->assertContains('test', $errors[0]);
$this->assertContainsString('test', $errors[0]);
}

/**
* @doesNotPerformAssertions
*/
public function testAppendThrowsDuringEnd()
{
$stream = $this->createStream();
Expand Down Expand Up @@ -305,7 +311,7 @@ public function testAppendThrowsShouldTriggerEnd()

$this->removeErrorHandler();
$this->assertCount(1, $errors);
$this->assertContains('test', $errors[0]);
$this->assertContainsString('test', $errors[0]);
}

public function testAppendThrowsShouldTriggerEndButIgnoreExceptionDuringEnd()
Expand All @@ -326,41 +332,33 @@ public function testAppendThrowsShouldTriggerEndButIgnoreExceptionDuringEnd()

$this->removeErrorHandler();
$this->assertCount(1, $errors);
$this->assertContains('test', $errors[0]);
$this->assertContainsString('test', $errors[0]);
}

/**
* @expectedException RuntimeException
*/
public function testAppendInvalidStreamIsRuntimeError()
{
$this->setExpectedException('RuntimeException');
if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid stream)');
StreamFilter\append(false, function () { });
}

/**
* @expectedException RuntimeException
*/
public function testPrependInvalidStreamIsRuntimeError()
{
$this->setExpectedException('RuntimeException');
if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid stream)');
StreamFilter\prepend(false, function () { });
}

/**
* @expectedException RuntimeException
*/
public function testRemoveInvalidFilterIsRuntimeError()
{
$this->setExpectedException('RuntimeException');
if (defined('HHVM_VERSION')) $this->markTestSkipped('Not supported on HHVM (does not reject invalid filters)');
StreamFilter\remove(false);
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidCallbackIsInvalidArgument()
{
$this->setExpectedException('InvalidArgumentException');
$stream = $this->createStream();

StreamFilter\append($stream, 'a-b-c');
Expand All @@ -383,4 +381,27 @@ private function removeErrorHandler()
{
restore_error_handler();
}

public function setExpectedException($exception, $message = '', $code = 0)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if ($message !== '') {
$this->expectExceptionMessage($message);
}
$this->expectExceptionCode($code);
} else {
parent::setExpectedException($exception, $message, $code);
}
}

public function assertContainsString($needle, $haystack)
{
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString($needle, $haystack);
} else {
$this->assertContains($needle, $haystack);
}
}

}
27 changes: 20 additions & 7 deletions tests/FunTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Clue\Tests\StreamFilter;

use Clue\StreamFilter as Filter;
use PHPUnit\Framework\TestCase;

class FunTest extends PHPUnit_Framework_TestCase
class FunTest extends TestCase
{
public function testFunInRot13()
{
Expand All @@ -23,22 +26,18 @@ public function testFunInQuotedPrintable()
$this->assertEquals(null, $encode());
}

/**
* @expectedException RuntimeException
*/
public function testFunWriteAfterCloseRot13()
{
$this->setExpectedException('RuntimeException');
$rot = Filter\fun('string.rot13');

$this->assertEquals(null, $rot());
$rot('test');
}

/**
* @expectedException RuntimeException
*/
public function testFunInvalid()
{
$this->setExpectedException('RuntimeException');
Filter\fun('unknown');
}

Expand All @@ -58,4 +57,18 @@ public function testFunInBase64()
$encode = Filter\fun('convert.base64-encode');
$this->assertEquals(null, $encode());
}

public function setExpectedException($exception, $message = '', $code = 0)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if ($message !== '') {
$this->expectExceptionMessage($message);
}
$this->expectExceptionCode($code);
} else {
parent::setExpectedException($exception, $message, $code);
}
}

}
5 changes: 4 additions & 1 deletion tests/FunZlibTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace Clue\Tests\StreamFilter;

use Clue\StreamFilter;
use PHPUnit\Framework\TestCase;

class BuiltInZlibTest extends PHPUnit_Framework_TestCase
class BuiltInZlibTest extends TestCase
{
public function testFunZlibDeflateHelloWorld()
{
Expand Down