Skip to content

Commit

Permalink
Merge pull request #406 from IonBazan/feature/test-fix
Browse files Browse the repository at this point in the history
do not allow for output during tests
  • Loading branch information
nyamsprod authored Dec 10, 2020
2 parents fb3ea00 + a6032a5 commit 3ad6641
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 59 deletions.
5 changes: 4 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutOutputDuringTests="true"
processIsolation="false"
stopOnFailure="false">

Expand Down
4 changes: 2 additions & 2 deletions tests/CharsetConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CharsetConverterTest extends TestCase
*/
public function testCharsetConverterTriggersException(): void
{
self::expectException(OutOfRangeException::class);
$this->expectException(OutOfRangeException::class);
(new CharsetConverter())->inputEncoding('');
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public function testCharsetConverterAsStreamFilter(): void
*/
public function testCharsetConverterAsStreamFilterFailed(): void
{
self::expectException(InvalidArgument::class);
$this->expectException(InvalidArgument::class);
stream_filter_register(CharsetConverter::FILTERNAME.'.*', CharsetConverter::class);
$expected = 'Batman,Superman,Anaïs';
$raw = mb_convert_encoding($expected, 'iso-8859-15', 'utf-8');
Expand Down
4 changes: 2 additions & 2 deletions tests/ColumnConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testAutoDetect(): void
*/
public function testColumnsCount(): void
{
self::expectException(CannotInsertRecord::class);
$this->expectException(CannotInsertRecord::class);
$this->csv->addValidator(new ColumnConsistency(3), 'consistency');
$this->csv->insertOne(['john', 'doe', '[email protected]']);
$this->csv->insertOne(['jane', '[email protected]']);
Expand All @@ -82,7 +82,7 @@ public function testColumnsCount(): void
*/
public function testColumsCountTriggersException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
new ColumnConsistency(-2);
}
}
25 changes: 15 additions & 10 deletions tests/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testCreateFromFileObjectPreserveFileObjectCsvControls(): void
*/
public function testCreateFromPathThrowsRuntimeException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
Reader::createFromPath(__DIR__.'/foo/bar', 'r');
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public function bomProvider(): array
*/
public function testCloningIsForbidden(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
clone $this->csv;
}

Expand All @@ -136,7 +136,10 @@ public function testCloningIsForbidden(): void
*/
public function testOutputSize(): void
{
self::assertSame(60, $this->csv->output('test.csv'));
ob_start();
$length = $this->csv->output('test.csv');
ob_end_clean();
self::assertSame(60, $length);
}

/**
Expand All @@ -146,7 +149,7 @@ public function testOutputSize(): void
*/
public function testInvalidOutputFile(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->output('invalid/file.csv');
}

Expand All @@ -165,7 +168,9 @@ public function testOutputHeaders(): void

$raw_csv = Reader::BOM_UTF8."john,doe,[email protected]\njane,doe,[email protected]\n";
$csv = Reader::createFromString($raw_csv);
ob_start();
$csv->output('tést.csv');
ob_end_clean();
$headers = xdebug_get_headers();

// Due to the variety of ways the xdebug expresses Content-Type of text files,
Expand Down Expand Up @@ -203,7 +208,7 @@ public function testToString(): void
*/
public function testChunkTriggersException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$chunk = $this->csv->chunk(0);
iterator_to_array($chunk);
}
Expand Down Expand Up @@ -235,7 +240,7 @@ public function testStreamFilterMode(): void
*/
public function testDelimiter(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->setDelimiter('o');
self::assertSame('o', $this->csv->getDelimiter());
self::assertSame($this->csv, $this->csv->setDelimiter('o'));
Expand Down Expand Up @@ -286,7 +291,7 @@ public function testChangingBOMOnOutput(): void
*/
public function testEscape(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->setEscape('o');
self::assertSame('o', $this->csv->getEscape());
self::assertSame($this->csv, $this->csv->setEscape('o'));
Expand All @@ -300,7 +305,7 @@ public function testEscape(): void
*/
public function testEnclosure(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->setEnclosure('o');
self::assertSame('o', $this->csv->getEnclosure());
self::assertSame($this->csv, $this->csv->setEnclosure('o'));
Expand Down Expand Up @@ -330,7 +335,7 @@ public function testAddStreamFilter(): void
*/
public function testFailedAddStreamFilter(): void
{
self::expectException(UnavailableFeature::class);
$this->expectException(UnavailableFeature::class);
$csv = Writer::createFromFileObject(new SplTempFileObject());
self::assertFalse($csv->supportsStreamFilter());
$csv->addStreamFilter('string.toupper');
Expand All @@ -343,7 +348,7 @@ public function testFailedAddStreamFilter(): void
*/
public function testFailedAddStreamFilterWithWrongFilter(): void
{
self::expectException(InvalidArgument::class);
$this->expectException(InvalidArgument::class);
/** @var resource $tmpfile */
$tmpfile = tmpfile();
$csv = Writer::createFromStream($tmpfile);
Expand Down
4 changes: 2 additions & 2 deletions tests/DetectDelimiterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testDetectDelimiterListWithInvalidRowLimit(): void
$file = new SplTempFileObject();
$file->fwrite("How are you today ?\nI'm doing fine thanks!");
$csv = Reader::createFromFileObject($file);
self::expectException(Exception::class);
$this->expectException(Exception::class);
delimiter_detect($csv, [','], -4);
}

Expand All @@ -37,7 +37,7 @@ public function testDetectDelimiterListWithInvalidDelimiter(): void
$file = new SplTempFileObject();
$file->fwrite("How are you today ?\nI'm doing fine thanks!");
$csv = Reader::createFromFileObject($file);
self::expectException(TypeError::class);
$this->expectException(TypeError::class);
delimiter_detect($csv, [',', []]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EncloseFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function wrongParamProvider(): iterable
*/
public function testEncloseFieldImmutability(): void
{
self::expectException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$csv = Writer::createFromString('');
$csv->setDelimiter('|');
EncloseField::addTo($csv, 'foo');
Expand Down
4 changes: 2 additions & 2 deletions tests/EscapeFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EscapeFormulaTest extends TestCase
*/
public function testConstructorThrowsTypError(): void
{
self::expectException(TypeError::class);
$this->expectException(TypeError::class);
new EscapeFormula("\t", [(object) 'i']);
}

Expand All @@ -41,7 +41,7 @@ public function testConstructorThrowsTypError(): void
*/
public function testConstructorThrowsInvalidArgumentException(): void
{
self::expectException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new EscapeFormula("\t", ['i', 'foo']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function testToHTMLWithBothTableHeaderSection(): void
*/
public function testTableTriggersException(): void
{
self::expectException(DOMException::class);
$this->expectException(DOMException::class);
(new HTMLConverter())->table('table-csv-data', 'te st');
}
}
2 changes: 1 addition & 1 deletion tests/Polyfill/EmptyEscapeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EmptyEscapeParserTest extends TestCase
*/
public function testConstructorThrowsTypeErrorWithUnknownDocument(): void
{
self::expectException(TypeError::class);
$this->expectException(TypeError::class);
$records = EmptyEscapeParser::parse(new stdClass());
$records->rewind();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/RFC4180FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function readerBugsProvider(): array
*/
public function testOnCreateFailedWithoutParams(): void
{
self::expectException(TypeError::class);
$this->expectException(TypeError::class);
(new RFC4180Field())->onCreate();
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public function testDoNotEncloseWhiteSpacedField(): void
*/
public function testDoNotEncloseWhiteSpacedFieldThrowsException(): void
{
self::expectException(InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
RFC4180Field::addTo(Writer::createFromString(''), "\t\0");
}
}
14 changes: 7 additions & 7 deletions tests/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function testCall(): void
*/
public function testHeaderThrowsExceptionOnError(): void
{
self::expectException(SyntaxError::class);
$this->expectException(SyntaxError::class);
$csv = Reader::createFromString(
'field1,field1,field3
1,2,3
Expand All @@ -218,7 +218,7 @@ public function testHeaderThrowsExceptionOnError(): void
*/
public function testHeaderThrowsExceptionOnEmptyLine(): void
{
self::expectException(SyntaxError::class);
$this->expectException(SyntaxError::class);
$str = <<<EOF
foo,bar,baz
Expand Down Expand Up @@ -363,7 +363,7 @@ public function appliedFlagsProvider(): array
*/
public function testGetHeaderThrowsExceptionWithNegativeOffset(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->setHeaderOffset(-3)->getRecords();
}

Expand All @@ -373,7 +373,7 @@ public function testGetHeaderThrowsExceptionWithNegativeOffset(): void
*/
public function testGetHeaderThrowsExceptionWithSplFileObject(): void
{
self::expectException(SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->csv->setHeaderOffset(23)->getRecords();
}

Expand All @@ -383,7 +383,7 @@ public function testGetHeaderThrowsExceptionWithSplFileObject(): void
*/
public function testGetHeaderThrowsExceptionWithStreamObject(): void
{
self::expectException(SyntaxError::class);
$this->expectException(SyntaxError::class);

/** @var resource $tmp */
$tmp = fopen('php://temp', 'r+');
Expand All @@ -400,7 +400,7 @@ public function testGetHeaderThrowsExceptionWithStreamObject(): void
*/
public function testSetHeaderThrowsExceptionOnWrongInputRange(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->csv->setHeaderOffset(-1);
}

Expand Down Expand Up @@ -621,7 +621,7 @@ public function testGetHeaderThrowsIfTheFirstRecordOnlyContainsBOMString(): void
$csv = Reader::createFromString($text);
$csv->setHeaderOffset(0);

self::expectException(Exception::class);
$this->expectException(Exception::class);
$csv->getHeader();
}
}
14 changes: 7 additions & 7 deletions tests/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testSetLimit(): void
*/
public function testSetOffsetThrowsException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->stmt->offset(-1);
}

Expand Down Expand Up @@ -119,7 +119,7 @@ public function testStatementSameInstance(): void
*/
public function testSetLimitThrowException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->stmt->limit(-4);
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public function intervalTest(): array
*/
public function testIntervalThrowException(): void
{
self::expectException(OutOfBoundsException::class);
$this->expectException(OutOfBoundsException::class);
iterator_to_array($this->stmt
->offset(1)
->limit(0)
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testOrderByWithEquity(): void
*/
public function testFetchColumnTriggersException($field): void
{
self::expectException(InvalidArgument::class);
$this->expectException(InvalidArgument::class);
$this->csv->setHeaderOffset(0);
$res = $this->stmt->process($this->csv)->fetchColumn($field);
iterator_to_array($res, false);
Expand All @@ -277,7 +277,7 @@ public function invalidFieldNameProvider(): array
*/
public function testFetchColumnTriggersOutOfRangeException(): void
{
self::expectException(InvalidArgument::class);
$this->expectException(InvalidArgument::class);
$this->csv->setHeaderOffset(0);
$res = $this->stmt->process($this->csv)->fetchColumn(-1);
iterator_to_array($res, false);
Expand Down Expand Up @@ -398,7 +398,7 @@ public function testfetchOne(): void
*/
public function testFetchOneTriggersException(): void
{
self::expectException(Exception::class);
$this->expectException(Exception::class);
$this->stmt->process($this->csv)->fetchOne(-5);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ public function testJsonSerialize(): void
*/
public function testHeaderThrowsExceptionOnError(): void
{
self::expectException(SyntaxError::class);
$this->expectException(SyntaxError::class);
$csv = Reader::createFromString(
'field1,field1,field3
1,2,3
Expand Down
Loading

0 comments on commit 3ad6641

Please sign in to comment.