-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add exporter infrastructure #37
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e928fef
added basic exporter-infrastructure
e05f3b7
implementation of the first exporter with exportCommand.
b423fb2
Updated README with information about exporter usage and definition o…
de48cf5
removed unused use statement
46bf217
removed commented code from travis-file, fixed typo in README
4c24632
removed service definition for export controller and ExportDataContro…
8f0d730
removed event hook method and constant from ExporterRegistry
3b3c859
removed routing for export controller
470aa2f
moved output and exit of command to the listExporters method
4ae2412
added some TypeHints and simplyfied plugin-assignment in pluginpool
c8259d1
Updated the README with an example of a real exporter. Explained the …
5a3b3bc
fixed problem with types of parameters
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
13 changes: 13 additions & 0 deletions
13
features/export/cli/exporting_countries_to_csv_via_cli.feature
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 @@ | ||
@managing_countries | ||
Feature: exporting countries to csv-file | ||
In order to have my countries exported to an external target | ||
As a Developer | ||
I want to be able to export country data to csv file from the commandline | ||
|
||
Background: | ||
Given I have a working command-line-interface | ||
|
||
@cli_importer_exporter | ||
Scenario: Exporting countries to csv-file | ||
When I export "country" data as "csv" to the file "countries_export.csv" with the cli-command | ||
Then I should see "Exported" in the output |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
spec/DependencyInjection/Compiler/RegisterExporterPassSpec.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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\FriendsOfSylius\SyliusImportExportPlugin\DependencyInjection\Compiler; | ||
|
||
use FriendsOfSylius\SyliusImportExportPlugin\DependencyInjection\Compiler\RegisterExporterPass; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class RegisterExporterPassSpec extends ObjectBehavior | ||
{ | ||
function it_is_a_compiler_pass(): void | ||
{ | ||
$this->shouldImplement(CompilerPassInterface::class); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(RegisterExporterPass::class); | ||
} | ||
|
||
function it_processes_the_exporter_services( | ||
ContainerBuilder $container, | ||
Definition $exporterRegistry, | ||
Definition $blockEventDefinition | ||
) { | ||
$exporterType = 'csv'; | ||
/** | ||
* prepare the mock for the container builder | ||
*/ | ||
$container->getParameter('sylius.importer.web_ui')->willReturn(true); | ||
$container->has('sylius.exporters_registry')->willReturn(true); | ||
$container->has(Argument::type('string'))->willReturn(false); | ||
$container->findDefinition('sylius.exporters_registry')->willReturn($exporterRegistry); | ||
$container->findTaggedServiceIds('sylius.exporter')->willReturn([ | ||
'exporter_id' => [ | ||
[ | ||
'type' => $exporterType, | ||
'format' => 'exporter_format', | ||
], | ||
], | ||
]); | ||
|
||
/** | ||
* prepare the mock for the exporterRegistry | ||
*/ | ||
$exporterRegistry->addMethodCall( | ||
'register', | ||
Argument::type('array') | ||
)->shouldBeCalled(); | ||
|
||
/** | ||
* run the test | ||
*/ | ||
$this->process($container); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin; | ||
|
||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin\PluginFactory; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin\PluginFactoryInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class PluginFactorySpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(PluginFactory::class); | ||
} | ||
|
||
function it_implements_the_plugin_factory_interface() | ||
{ | ||
$this->shouldImplement(PluginFactoryInterface::class); | ||
} | ||
} |
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,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin; | ||
|
||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin\PluginInterface; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin\PluginPool; | ||
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\Plugin\PluginPoolInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class PluginPoolSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
PluginInterface $plugin1, | ||
PluginInterface $plugin2 | ||
) { | ||
$this->beConstructedWith([$plugin1, $plugin2], ['description', 'name']); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(PluginPool::class); | ||
} | ||
|
||
function it_implements_the_plugin_pool_interface() | ||
{ | ||
$this->shouldImplement(PluginPoolInterface::class); | ||
} | ||
|
||
function it_returns_array_of_plugins_after_creation( | ||
PluginInterface $plugin1, | ||
PluginInterface $plugin2 | ||
) { | ||
$this | ||
->getPlugins() | ||
->shouldReturn( | ||
[ | ||
$plugin1, | ||
$plugin2, | ||
] | ||
); | ||
} | ||
|
||
function it_inits_plugins_with_ids( | ||
PluginInterface $plugin1, | ||
PluginInterface $plugin2 | ||
) { | ||
$ids = [ | ||
'id1', | ||
'id2', | ||
'id3', | ||
]; | ||
$plugin1->init($ids)->shouldBeCalled(); | ||
$plugin2->init($ids)->shouldBeCalled(); | ||
$this->initPlugins($ids); | ||
} | ||
|
||
function it_gets_correct_data_from_multiple_plugins( | ||
PluginInterface $plugin1, | ||
PluginInterface $plugin2 | ||
) { | ||
$plugin1 | ||
->getData('id1', ['description', 'name']) | ||
->willReturn( | ||
[ | ||
'description' => '', | ||
'name' => 'testName', | ||
] | ||
); | ||
$plugin2 | ||
->getData('id1', ['description', 'name']) | ||
->willReturn( | ||
[ | ||
'description' => 'this is a description', | ||
'name' => '', | ||
] | ||
); | ||
|
||
$this->getDataForId('id1') | ||
->shouldReturn( | ||
[ | ||
'description' => 'this is a description', | ||
'name' => 'testName', | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
While reading this without any knowledge about the internal workings, I found it rather hard to understand what I have to do to get it working quickly. I think it would be good to extend the documentation with some more 'real' examples (no
foo
,bar
) but also more explanation about the concept oftype
,format
andplugins
.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.
I have added a example based on the existing exporter. Also added a section where I described my idea of the PluginPool.