-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from akeneo/1.1
v1.1.0 - Added CSV support
- Loading branch information
Showing
64 changed files
with
1,095 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ vendor | |
composer.lock | ||
phpunit.xml | ||
~$*.xlsx | ||
|
||
/nbproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
spec/Akeneo/Component/SpreadsheetParser/Csv/RowIteratorFactorySpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
); | ||
} | ||
|
||
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; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
spec/Akeneo/Component/SpreadsheetParser/Csv/RowIteratorSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
$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); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
spec/Akeneo/Component/SpreadsheetParser/Csv/SpreadsheetLoaderSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
spec/Akeneo/Component/SpreadsheetParser/Csv/SpreadsheetSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
spec/Akeneo/Component/SpreadsheetParser/Csv/fixtures/iso-8859-15.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
�,�,� |
2 changes: 2 additions & 0 deletions
2
spec/Akeneo/Component/SpreadsheetParser/Csv/fixtures/test.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
value,"enclosed value",15 | ||
,value2, |
2 changes: 2 additions & 0 deletions
2
spec/Akeneo/Component/SpreadsheetParser/Csv/fixtures/with_options.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
value|@enclosed value@|15 | ||
|value2| |
35 changes: 35 additions & 0 deletions
35
spec/Akeneo/Component/SpreadsheetParser/SpreadsheetLoaderSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.