Skip to content

Commit

Permalink
Deprecate EncodeField stream filter
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 3, 2023
1 parent 65105be commit 5a97cc2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'phpdoc_summary' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_blank_line_before_namespace' => true,
'blank_lines_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All Notable changes to `Csv` will be documented in this file

### Deprecated

- None
- `EncloseField` stream filter in favor of the new `Writer::forceEnclosure` method.

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions src/EncloseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
/**
* A stream filter to improve enclosure character usage.
*
* DEPRECATION WARNING! This class will be removed in the next major point release
*
* @deprecated since version 9.10.0
* @see Writer::forceEnclosure()
*
* @see https://tools.ietf.org/html/rfc4180#section-2
* @see https://bugs.php.net/bug.php?id=38301
*/
Expand Down
5 changes: 5 additions & 0 deletions src/EncloseFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
use PHPUnit\Framework\TestCase;
use function stream_get_filters;

/**
* DEPRECATION WARNING! This class will be removed in the next major point release.
*
* @deprecated since version 9.10.0
*/
#[Group('filter')]
final class EncloseFieldTest extends TestCase
{
Expand Down
30 changes: 30 additions & 0 deletions src/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,34 @@ public static function compliantRFC4180Provider(): array
],
];
}

public function testEncloseAll(): void
{
/**
* @see https://en.wikipedia.org/wiki/Comma-separated_values#Example
*/
$records = [
['Year', 'Make', 'Model', 'Description', 'Price'],
[1997, 'Ford', 'E350', 'ac,abs,moon', '3000.00'],
[1999, 'Chevy', 'Venture "Extended Edition"', null, '4900.00'],
[1999, 'Chevy', 'Venture "Extended Edition, Very Large"', null, '5000.00'],
[1996, 'Jeep', 'Grand Cherokee', 'MUST SELL!
air, moon roof, loaded', '4799.00'],
];

$csv = Writer::createFromString();
$csv->setDelimiter('|');
$csv->forceEnclosure();
$csv->insertAll($records);

$expected = <<<CSV
"Year"|"Make"|"Model"|"Description"|"Price"
"1997"|"Ford"|"E350"|"ac,abs,moon"|"3000.00"
"1999"|"Chevy"|"Venture ""Extended Edition"""|""|"4900.00"
"1999"|"Chevy"|"Venture ""Extended Edition, Very Large"""|""|"5000.00"
"1996"|"Jeep"|"Grand Cherokee"|"MUST SELL!
air, moon roof, loaded"|"4799.00"
CSV;
self::assertStringContainsString($expected, $csv->toString());
}
}

0 comments on commit 5a97cc2

Please sign in to comment.