-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.1 #3
1.1 #3
Changes from all commits
bb04b27
a5d2d92
ba3b217
8b193c3
2e4c00c
ba5ca9f
571b8ed
5f25a4f
ff516f9
1af0e60
b4a9e33
4093a36
031652f
abc600a
8e0c1c9
2280c0e
287b832
fbd16a3
a438e45
107434d
5c14d8c
95fba11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ vendor | |
composer.lock | ||
phpunit.xml | ||
~$*.xlsx | ||
|
||
/nbproject |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# CHANGELOG | ||
|
||
## 1.1 | ||
|
||
### Features | ||
|
||
* CSV support | ||
|
||
### BC Breaks | ||
|
||
* WorkbookInterface is now SpreasheetInterface | ||
* WorkbookLoaderInterface is now SpreadsheetLoaderInterface | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Component\SpreadsheetParser\Csv; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class RowIteratorFactorySpec extends ObjectBehavior | ||
{ | ||
public function let() | ||
{ | ||
$this->beConstructedWith( | ||
'spec\Akeneo\Component\SpreadsheetParser\Csv\StubRowIterator' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you pass the class to create namespace in the ctor? Is it to override it easily? Cause it seems pretty hackish to me. Instead I would override the whole factory if I need to change the created object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is really easy to override, with the component and with the bundle. It also makes testing the factory easier. This is a design pattern, it is not hackish ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instanciating a class through a variable value is (new $class()). What if 2014-06-09 11:14 GMT+02:00 Antoine Guigan [email protected]:
Gildas Quéméner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree, for two reasons :
All of this makes more sense if you look at the bundle : https://github.com/akeneo/SpreadsheetParserBundle/blob/1.1/Resources/config/xlsx.yml |
||
); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\RowIteratorFactory'); | ||
} | ||
|
||
public function it_creates_row_iterators( | ||
) { | ||
$iterator = $this->create('path', ['options']); | ||
$iterator->getPath()->shouldReturn('path'); | ||
$iterator->getOptions()->shouldReturn(['options']); | ||
} | ||
} | ||
|
||
class StubRowIterator | ||
{ | ||
protected $path; | ||
protected $options; | ||
public function __construct($path, $options) | ||
{ | ||
$this->path = $path; | ||
$this->options = $options; | ||
} | ||
public function getOptions() | ||
{ | ||
return $this->options; | ||
} | ||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Component\SpreadsheetParser\Csv; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class RowIteratorSpec extends ObjectBehavior | ||
{ | ||
protected $values = [ | ||
['value', 'enclosed value', '15'], | ||
['', 'value2', ''] | ||
]; | ||
|
||
public function it_is_initializable() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove |
||
{ | ||
$this->beConstructedWith('path', []); | ||
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\RowIterator'); | ||
} | ||
|
||
public function it_parses_csv_files() | ||
{ | ||
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv' , []); | ||
$this->rewind(); | ||
foreach ($this->values as $i=>$row) { | ||
$this->key()->shouldReturn($i); | ||
$this->valid()->shouldReturn(true); | ||
$this->current()->shouldReturn($row); | ||
$this->next(); | ||
} | ||
$this->valid()->shouldReturn(false); | ||
} | ||
|
||
public function it_can_be_rewinded() | ||
{ | ||
$this->beConstructedWith(__DIR__ . '/fixtures/test.csv' , []); | ||
$this->rewind(); | ||
$this->current()->shouldReturn($this->values[0]); | ||
$this->next(); | ||
$this->rewind(); | ||
$this->current()->shouldReturn($this->values[0]); | ||
} | ||
|
||
public function it_accepts_options() | ||
{ | ||
$this->beConstructedWith( | ||
__DIR__ . '/fixtures/with_options.csv', | ||
[ | ||
'delimiter' => '|', | ||
'enclosure' => "@" | ||
] | ||
); | ||
$this->rewind(); | ||
foreach ($this->values as $i => $row) { | ||
$this->key()->shouldReturn($i); | ||
$this->valid()->shouldReturn(true); | ||
$this->current()->shouldReturn($row); | ||
$this->next(); | ||
} | ||
$this->valid()->shouldReturn(false); | ||
} | ||
|
||
public function it_converts_between_encodings() | ||
{ | ||
$this->beConstructedWith( | ||
__DIR__ . '/fixtures/iso-8859-15.csv', | ||
[ | ||
'encoding' => 'iso-8859-15' | ||
] | ||
); | ||
$values = [['é', 'è', '€']]; | ||
$this->rewind(); | ||
foreach ($values as $i => $row) { | ||
$this->key()->shouldReturn($i); | ||
$this->valid()->shouldReturn(true); | ||
$this->current()->shouldReturn($row); | ||
$this->next(); | ||
} | ||
$this->valid()->shouldReturn(false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Component\SpreadsheetParser\Csv; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Akeneo\Component\SpreadsheetParser\Csv\RowIteratorFactory; | ||
|
||
class SpreadsheetLoaderSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
RowIteratorFactory $rowIteratorFactory | ||
) { | ||
$this->beConstructedWith( | ||
$rowIteratorFactory, | ||
'spec\Akeneo\Component\SpreadsheetParser\Csv\StubSpreadsheet', | ||
'sheet' | ||
); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\SpreadsheetLoader'); | ||
} | ||
|
||
public function it_creates_spreadsheet_objects( | ||
RowIteratorFactory $rowIteratorFactory | ||
) { | ||
$spreadsheet = $this->open('path'); | ||
$spreadsheet->getPath()->shouldReturn('path'); | ||
$spreadsheet->getSheetName()->shouldReturn('sheet'); | ||
$spreadsheet->getRowIteratorFactory()->shouldReturn($rowIteratorFactory); | ||
} | ||
} | ||
|
||
class StubSpreadsheet | ||
{ | ||
protected $rowIteratorFactory; | ||
protected $sheetName; | ||
protected $path; | ||
public function __construct($rowIteratorFactory, $sheetName, $path) | ||
{ | ||
$this->rowIteratorFactory = $rowIteratorFactory; | ||
$this->sheetName = $sheetName; | ||
$this->path = $path; | ||
} | ||
public function getRowIteratorFactory() | ||
{ | ||
return $this->rowIteratorFactory; | ||
} | ||
public function getSheetName() | ||
{ | ||
return $this->sheetName; | ||
} | ||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Component\SpreadsheetParser\Csv; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Akeneo\Component\SpreadsheetParser\Csv\RowIterator; | ||
use Akeneo\Component\SpreadsheetParser\Csv\RowIteratorFactory; | ||
|
||
class SpreadsheetSpec extends ObjectBehavior | ||
{ | ||
public function let(RowIteratorFactory $rowIteratorFactory) | ||
{ | ||
$this->beConstructedWith($rowIteratorFactory, 'sheet', 'path'); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\Csv\Spreadsheet'); | ||
} | ||
|
||
public function it_returns_the_worksheet_list() | ||
{ | ||
$this->getWorksheets()->shouldReturn(['sheet']); | ||
} | ||
|
||
public function it_creates_row_iterators( | ||
RowIteratorFactory $rowIteratorFactory, | ||
RowIterator $rowIterator1, | ||
RowIterator $rowIterator2 | ||
) { | ||
$rowIteratorFactory->create('path', ['options1'])->willReturn($rowIterator1); | ||
$rowIteratorFactory->create('path', ['options2'])->willReturn($rowIterator2); | ||
|
||
$this->createRowIterator(0, ['options1'])->shouldReturn($rowIterator1); | ||
$this->createRowIterator(1, ['options2'])->shouldReturn($rowIterator2); | ||
} | ||
|
||
public function it_finds_a_worksheet_index_by_name() | ||
{ | ||
$this->getWorksheetIndex('sheet')->shouldReturn(0); | ||
} | ||
|
||
public function it_returns_false_if_a_worksheet_does_not_exist() | ||
{ | ||
$this->getWorksheetIndex('sheet3')->shouldReturn(false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�,�,� |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
value,"enclosed value",15 | ||
,value2, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
value|@enclosed value@|15 | ||
|value2| |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace spec\Akeneo\Component\SpreadsheetParser; | ||
|
||
use Akeneo\Component\SpreadsheetParser\SpreadsheetInterface; | ||
use Akeneo\Component\SpreadsheetParser\SpreadsheetLoaderInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class SpreadsheetLoaderSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
SpreadsheetLoaderInterface $loader, | ||
SpreadsheetLoaderInterface $otherLoader, | ||
SpreadsheetInterface $spreadsheet | ||
) { | ||
$this->addLoader('extension', $loader)->addLoader('other_extension', $otherLoader); | ||
$loader->open('file.extension')->willReturn($spreadsheet); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Akeneo\Component\SpreadsheetParser\SpreadsheetLoader'); | ||
} | ||
|
||
public function it_uses_the_loader_corresponding_to_the_file_extension( | ||
SpreadsheetInterface $spreadsheet | ||
) { | ||
$this->open('file.extension')->shouldReturn($spreadsheet); | ||
} | ||
|
||
public function it_throws_an_exception_if_no_loader_is_available() | ||
{ | ||
$this->shouldThrow('\InvalidArgumentException')->duringOpen('file'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might prefer to rely on ~2.4.0 (otherwise you'll get 2.5, 2.6, etc.).