Refactor readers for better di (#457)

* Refactor readers to get a proper DI

Similar to what was done with writers, readers also needed to be updated to match the new way of doing things.
This commits promotes a better DI (factories, injection through constructors).

* Escapers should not be singletons

Instead, they should be proper object that can be injected where needed.
This commit is contained in:
Adrien Loison authored and GitHub committed 2017-08-27 00:01:17 +02:00
1 parent 4d6437fa77
commit b7e46740ce
66 files changed
+1095 -618

No files matched your search

@@ -0,0 +1,44 @@
<?php
namespace Box\Spout\Common\Helper\Escaper;
use Box\Spout\Common\Helper\Escaper;
/**
* Class ODSTest
*
* @package Box\Spout\Common\Helper\Escaper
*/
class ODSTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestEscape()
{
return [
['test', 'test'],
['carl\'s "pokemon"', 'carl\'s "pokemon"'],
["\n", "\n"],
["\r", "\r"],
["\t", "\t"],
["\v", "�"],
["\f", "�"],
];
}
/**
* @dataProvider dataProviderForTestEscape
*
* @param string $stringToEscape
* @param string $expectedEscapedString
* @return void
*/
public function testEscape($stringToEscape, $expectedEscapedString)
{
$escaper = new Escaper\ODS();
$escapedString = $escaper->escape($stringToEscape);
$this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string');
}
}
@@ -0,0 +1,83 @@
<?php
namespace Box\Spout\Common\Helper\Escaper;
use Box\Spout\Common\Helper\Escaper;
/**
* Class XLSXTest
*
* @package Box\Spout\Common\Helper\Escaper
*/
class XLSXTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestEscape()
{
return [
['test', 'test'],
['adam\'s "car"', 'adam\'s "car"'],
["\n", "\n"],
["\r", "\r"],
["\t", "\t"],
[chr(0), '_x0000_'],
[chr(4), '_x0004_'],
['_x0000_', '_x005F_x0000_'],
[chr(21), '_x0015_'],
['control '.chr(21).' character', 'control _x0015_ character'],
['control\'s '.chr(21).' "character"', 'control\'s _x0015_ "character"'],
];
}
/**
* @dataProvider dataProviderForTestEscape
*
* @param string $stringToEscape
* @param string $expectedEscapedString
* @return void
*/
public function testEscape($stringToEscape, $expectedEscapedString)
{
$escaper = new Escaper\XLSX();
$escapedString = $escaper->escape($stringToEscape);
$this->assertEquals($expectedEscapedString, $escapedString, 'Incorrect escaped string');
}
/**
* @return array
*/
public function dataProviderForTestUnescape()
{
return [
['test', 'test'],
['adam&#039;s &quot;car&quot;', 'adam&#039;s &quot;car&quot;'],
["\n", "\n"],
["\r", "\r"],
["\t", "\t"],
['_x0000_', chr(0)],
['_x0004_', chr(4)],
['_x005F_x0000_', '_x0000_'],
['_x0015_', chr(21)],
['control _x0015_ character', 'control '.chr(21).' character'],
['control&#039;s _x0015_ &quot;character&quot;', 'control&#039;s '.chr(21).' &quot;character&quot;'],
];
}
/**
* @dataProvider dataProviderForTestUnescape
*
* @param string $stringToUnescape
* @param string $expectedUnescapedString
* @return void
*/
public function testUnescape($stringToUnescape, $expectedUnescapedString)
{
$escaper = new Escaper\XLSX();
$unescapedString = $escaper->unescape($stringToUnescape);
$this->assertEquals($expectedUnescapedString, $unescapedString, 'Incorrect escaped string');
}
}