Skip to content

Commit

Permalink
[Fixtures] Another review fixes & tests improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Jun 17, 2016
1 parent 3211986 commit 7acd200
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 48 deletions.
5 changes: 4 additions & 1 deletion src/Sylius/Bundle/FixturesBundle/Fixture/AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ final public function getConfigTreeBuilder()
/**
* @param ArrayNodeDefinition $optionsNode
*/
abstract protected function configureOptionsNode(ArrayNodeDefinition $optionsNode);
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode)
{
// empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ final class HookableFixtureLoader implements FixtureLoaderInterface
/**
* @var FixtureLoaderInterface
*/
private $baseFixtureLoader;
private $decoratedFixtureLoader;

/**
* @param FixtureLoaderInterface $baseFixtureLoader
* @param FixtureLoaderInterface $decoratedFixtureLoader
*/
public function __construct(FixtureLoaderInterface $baseFixtureLoader)
public function __construct(FixtureLoaderInterface $decoratedFixtureLoader)
{
$this->baseFixtureLoader = $baseFixtureLoader;
$this->decoratedFixtureLoader = $decoratedFixtureLoader;
}

/**
Expand All @@ -44,7 +44,7 @@ public function load(SuiteInterface $suite, FixtureInterface $fixture, array $op

$this->executeBeforeFixtureListeners($suite, $fixtureEvent);

$this->baseFixtureLoader->load($suite, $fixture, $options);
$this->decoratedFixtureLoader->load($suite, $fixture, $options);

$this->executeAfterFixtureListeners($suite, $fixtureEvent);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Sylius/Bundle/FixturesBundle/Loader/HookableSuiteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class HookableSuiteLoader implements SuiteLoaderInterface
/**
* @var SuiteLoaderInterface
*/
private $baseSuiteLoader;
private $decoratedSuiteLoader;

/**
* @param SuiteLoaderInterface $baseSuiteLoader
* @param SuiteLoaderInterface $decoratedSuiteLoader
*/
public function __construct(SuiteLoaderInterface $baseSuiteLoader)
public function __construct(SuiteLoaderInterface $decoratedSuiteLoader)
{
$this->baseSuiteLoader = $baseSuiteLoader;
$this->decoratedSuiteLoader = $decoratedSuiteLoader;
}

/**
Expand All @@ -43,7 +43,7 @@ public function load(SuiteInterface $suite)

$this->executeBeforeSuiteListeners($suite, $suiteEvent);

$this->baseSuiteLoader->load($suite);
$this->decoratedSuiteLoader->load($suite);

$this->executeAfterSuiteListeners($suite, $suiteEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ConfigurationTest extends \PHPUnit_Framework_TestCase
/**
* @test
*/
public function it_allows_to_register_suite_with_fixture()
public function suite_can_have_one_fixture()
{
$this->assertConfigurationIsValid(
[['suites' => ['suite' => ['fixtures' => ['fixture' => null]]]]],
Expand All @@ -35,7 +35,7 @@ public function it_allows_to_register_suite_with_fixture()
/**
* @test
*/
public function it_allows_to_register_multiple_suites()
public function multiple_suites_are_allowed()
{
$this->assertConfigurationIsValid(
[['suites' => [
Expand All @@ -49,7 +49,7 @@ public function it_allows_to_register_multiple_suites()
/**
* @test
*/
public function it_allows_to_add_a_new_suite()
public function consecutive_configurations_can_add_suites()
{
$this->assertProcessedConfigurationEquals(
[
Expand All @@ -71,7 +71,7 @@ public function it_allows_to_add_a_new_suite()
/**
* @test
*/
public function it_allows_to_register_multiple_fixtures_for_one_suite()
public function suite_can_have_multiple_fixtures()
{
$this->assertConfigurationIsValid(
[['suites' => ['suite' => ['fixtures' => [
Expand All @@ -85,7 +85,7 @@ public function it_allows_to_register_multiple_fixtures_for_one_suite()
/**
* @test
*/
public function it_allows_to_unset_a_fixture()
public function consecutive_configurations_can_remove_a_fixture_from_the_suite()
{
$this->assertProcessedConfigurationEquals(
[
Expand All @@ -107,7 +107,7 @@ public function it_allows_to_unset_a_fixture()
/**
* @test
*/
public function it_allows_to_add_a_new_fixture_to_a_suite()
public function consecutive_configurations_can_add_fixtures_to_the_suite()
{
$this->assertProcessedConfigurationEquals(
[
Expand All @@ -129,7 +129,7 @@ public function it_allows_to_add_a_new_fixture_to_a_suite()
/**
* @test
*/
public function it_collects_all_fixtures_options()
public function all_fixture_options_from_consecutive_configurations_are_collected()
{
$this->assertProcessedConfigurationEquals(
[
Expand All @@ -150,7 +150,7 @@ public function it_collects_all_fixtures_options()
/**
* @test
*/
public function it_does_not_replace_fixture_options_if_not_defined_explicitly()
public function fixture_options_are_not_replaced_implicitly()
{
$this->assertProcessedConfigurationEquals(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ final class MongoDBPurgerListenerTest extends \PHPUnit_Framework_TestCase
/**
* @test
*/
function its_manager_is_the_default_one()
function managers_are_set_to_null_by_default()
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}

/**
* @test
*/
function its_default_manager_can_be_replaced_with_custom_ones()
function managers_are_optional()
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ final class ORMPurgerListenerTest extends \PHPUnit_Framework_TestCase
/**
* @test
*/
function its_purge_mode_is_delete()
function purge_mode_is_set_to_delete_by_default()
{
$this->assertProcessedConfigurationEquals([[]], ['mode' => 'delete'], 'mode');
}

/**
* @test
*/
function its_purge_mode_can_be_changed_to_truncate()
function purge_mode_can_be_changed_to_truncate()
{
$this->assertProcessedConfigurationEquals([['mode' => 'truncate']], ['mode' => 'truncate'], 'mode');
}

/**
* @test
*/
function its_purge_mode_cannot_be_changed_to_anything_else_than_defined()
function purge_mode_can_be_either_delete_or_truncate()
{
$this->assertPartialConfigurationIsInvalid([['mode' => 'lol']], 'mode');
}

/**
* @test
*/
function its_manager_is_the_default_one()
function managers_are_set_to_null_by_default()
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}

/**
* @test
*/
function its_default_manager_can_be_replaced_with_custom_ones()
function managers_are_optional()
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ final class PHPCRPurgerListenerTest extends \PHPUnit_Framework_TestCase
/**
* @test
*/
function its_manager_is_the_default_one()
function managers_are_set_to_null_by_default()
{
$this->assertProcessedConfigurationEquals([[]], ['managers' => [null]], 'managers');
}

/**
* @test
*/
function its_default_manager_can_be_replaced_with_custom_ones()
function managers_are_optional()
{
$this->assertProcessedConfigurationEquals([['managers' => ['custom']]], ['managers' => ['custom']], 'managers');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
final class HookableFixtureLoaderSpec extends ObjectBehavior
{
function let(FixtureLoaderInterface $baseFixtureLoader)
function let(FixtureLoaderInterface $decoratedFixtureLoader)
{
$this->beConstructedWith($baseFixtureLoader);
$this->beConstructedWith($decoratedFixtureLoader);
}

function it_is_initializable()
Expand All @@ -44,19 +44,19 @@ function it_implements_fixture_loader_interface()
}

function it_delegates_fixture_loading_to_the_base_loader(
FixtureLoaderInterface $baseFixtureLoader,
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture
) {
$suite->getListeners()->willReturn([]);

$baseFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();

$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}

function it_executes_before_fixture_listeners(
FixtureLoaderInterface $baseFixtureLoader,
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
BeforeFixtureListenerInterface $beforeFixtureListener
Expand All @@ -67,13 +67,13 @@ function it_executes_before_fixture_listeners(

$beforeFixtureListener->beforeFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), ['fixture_option' => 'fixture_value']), [])->shouldBeCalledTimes(1);

$baseFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();

$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}

function it_executes_after_fixture_listeners(
FixtureLoaderInterface $baseFixtureLoader,
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
AfterFixtureListenerInterface $afterFixtureListener
Expand All @@ -82,15 +82,15 @@ function it_executes_after_fixture_listeners(
yield $afterFixtureListener->getWrappedObject() => [];
});

$baseFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();

$afterFixtureListener->afterFixture(new FixtureEvent($suite->getWrappedObject(), $fixture->getWrappedObject(), ['fixture_option' => 'fixture_value']), [])->shouldBeCalledTimes(1);

$this->load($suite, $fixture, ['fixture_option' => 'fixture_value']);
}

function it_executes_customized_fixture_listeners(
FixtureLoaderInterface $baseFixtureLoader,
FixtureLoaderInterface $decoratedFixtureLoader,
SuiteInterface $suite,
FixtureInterface $fixture,
BeforeFixtureListenerInterface $beforeFixtureListener,
Expand All @@ -105,7 +105,7 @@ function it_executes_customized_fixture_listeners(

$beforeFixtureListener->beforeFixture($fixtureEvent, ['listener_option1' => 'listener_value1'])->shouldBeCalledTimes(1);

$baseFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();
$decoratedFixtureLoader->load($suite, $fixture, ['fixture_option' => 'fixture_value'])->shouldBeCalled();

$afterFixtureListener->afterFixture($fixtureEvent, ['listener_option2' => 'listener_value2'])->shouldBeCalledTimes(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
final class HookableSuiteLoaderSpec extends ObjectBehavior
{
function let(SuiteLoaderInterface $baseSuiteLoader)
function let(SuiteLoaderInterface $decoratedSuiteLoader)
{
$this->beConstructedWith($baseSuiteLoader);
$this->beConstructedWith($decoratedSuiteLoader);
}

function it_is_initializable()
Expand All @@ -42,17 +42,17 @@ function it_implements_suite_loader_interface()
$this->shouldImplement(SuiteLoaderInterface::class);
}

function it_delegates_suite_loading_to_the_base_loader(SuiteLoaderInterface $baseSuiteLoader, SuiteInterface $suite)
function it_delegates_suite_loading_to_the_base_loader(SuiteLoaderInterface $decoratedSuiteLoader, SuiteInterface $suite)
{
$suite->getListeners()->willReturn([]);

$baseSuiteLoader->load($suite)->shouldBeCalled();
$decoratedSuiteLoader->load($suite)->shouldBeCalled();

$this->load($suite);
}

function it_executes_before_suite_listeners(
SuiteLoaderInterface $baseSuiteLoader,
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
BeforeSuiteListenerInterface $beforeSuiteListener
) {
Expand All @@ -62,29 +62,29 @@ function it_executes_before_suite_listeners(

$beforeSuiteListener->beforeSuite(new SuiteEvent($suite->getWrappedObject()), [])->shouldBeCalledTimes(1);

$baseSuiteLoader->load($suite)->shouldBeCalled();
$decoratedSuiteLoader->load($suite)->shouldBeCalled();

$this->load($suite);
}

function it_executes_after_suite_listeners(
SuiteLoaderInterface $baseSuiteLoader,
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
AfterSuiteListenerInterface $afterSuiteListener
) {
$suite->getListeners()->will(function () use ($afterSuiteListener) {
yield $afterSuiteListener->getWrappedObject() => [];
});

$baseSuiteLoader->load($suite)->shouldBeCalled();
$decoratedSuiteLoader->load($suite)->shouldBeCalled();

$afterSuiteListener->afterSuite(new SuiteEvent($suite->getWrappedObject()), [])->shouldBeCalledTimes(1);

$this->load($suite);
}

function it_executes_customized_suite_listeners(
SuiteLoaderInterface $baseSuiteLoader,
SuiteLoaderInterface $decoratedSuiteLoader,
SuiteInterface $suite,
BeforeSuiteListenerInterface $beforeSuiteListener,
AfterSuiteListenerInterface $afterSuiteListener
Expand All @@ -96,7 +96,7 @@ function it_executes_customized_suite_listeners(

$beforeSuiteListener->beforeSuite(new SuiteEvent($suite->getWrappedObject()), ['listener_option1' => 'listener_value1'])->shouldBeCalledTimes(1);

$baseSuiteLoader->load($suite)->shouldBeCalled();
$decoratedSuiteLoader->load($suite)->shouldBeCalled();

$afterSuiteListener->afterSuite(new SuiteEvent($suite->getWrappedObject()), ['listener_option2' => 'listener_value2'])->shouldBeCalledTimes(1);

Expand Down

0 comments on commit 7acd200

Please sign in to comment.