Skip to content
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

Use nelmio/alice's newer version #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Fixtures/FixtureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

use h4cc\AliceFixturesBundle\ORM\ORMInterface;
use Nelmio\Alice\Fixtures;
use Nelmio\Alice\Loader\Base;
use Nelmio\Alice\LoaderInterface;
use Nelmio\Alice\Fixtures\Loader;
use Nelmio\Alice\ProcessorInterface;
use Psr\Log\LoggerInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -53,7 +52,7 @@ class FixtureManager implements FixtureManagerInterface
*/
protected $options = array();
/**
* @var \Nelmio\Alice\ORM\Doctrine
* @var \Nelmio\Alice\Persister\Doctrine
*/
protected $orm;
/**
Expand Down Expand Up @@ -164,7 +163,7 @@ public function load(FixtureSet $set, array $initialReferences = array())

/**
* @param FixtureSet $set
* @return \Nelmio\Alice\LoaderInterface[]
* @return \Nelmio\Alice\Fixtures\Loader[]
*/
private function createNeededLoaders(FixtureSet $set)
{
Expand All @@ -173,7 +172,7 @@ private function createNeededLoaders(FixtureSet $set)
foreach ($set->getFiles() as $file) {
$type = $file['type'];
if (!isset($loaders[$type])) {
$loader = $this->loaderFactory->getLoader($type, $set->getLocale());
$loader = $this->loaderFactory->getLoader($set->getLocale());
$this->configureLoader($loader);
$loaders[$type] = $loader;
$this->logDebug("Created loader for type '$type'.");
Expand Down Expand Up @@ -273,12 +272,12 @@ public function addProvider($provider)
/**
* Sets all needed options and dependencies to a loader.
*
* @param LoaderInterface $loader
* @param Loader $loader
*/
protected function configureLoader(LoaderInterface $loader)
protected function configureLoader(Loader $loader)
{
if ($loader instanceof Base) {
$loader->setORM($this->getORM());
if ($loader instanceof Loader) {
$loader->setPersister($this->getORM());
if ($this->logger) {
$loader->setLogger($this->logger);
}
Expand Down
3 changes: 1 addition & 2 deletions Fixtures/FixtureManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ interface FixtureManagerInterface
* Does _not_ persist them, use persist() for that.
*
* @param array $files
* @param string $type
* @return array
*/
public function loadFiles(array $files, $type = 'yaml');
public function loadFiles(array $files);

/**
* Creates a new configured fixture set.
Expand Down
27 changes: 4 additions & 23 deletions Loader/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

namespace h4cc\AliceFixturesBundle\Loader;

use Nelmio\Alice\Loader\Base as BaseLoader;
use Nelmio\Alice\Loader\Yaml as YamlLoader;
use Nelmio\Alice\Fixtures\Loader;

/**
* Class Factory
Expand All @@ -25,29 +24,11 @@ class Factory implements FactoryInterface
/**
* Returns a loader for a specific type and locale.
*
* @param $type
* @param $locale
* @return BaseLoader|YamlLoader
* @throws \InvalidArgumentException
* @return Loader
*/
public function getLoader($type, $locale)
public function getLoader($locale)
{
switch ($type) {
case 'yaml':
return $this->newLoaderYaml($locale);
case 'php':
return $this->newLoaderPHP($locale);
}
throw new \InvalidArgumentException("Unknown loader type '$type'.");
}

protected function newLoaderYaml($locale)
{
return new YamlLoader($locale);
}

protected function newLoaderPHP($locale)
{
return new BaseLoader($locale);
return new Loader($locale);
}
}
7 changes: 3 additions & 4 deletions Loader/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace h4cc\AliceFixturesBundle\Loader;

use Nelmio\Alice\LoaderInterface;
use Nelmio\Alice\Fixtures\Loader;

/**
* Interface FactoryInterface
Expand All @@ -23,9 +23,8 @@ interface FactoryInterface
/**
* Returns a loader for a specific type and locale.
*
* @param $type
* @param $locale
* @return LoaderInterface
* @return Loader
*/
public function getLoader($type, $locale);
public function getLoader($locale);
}
2 changes: 1 addition & 1 deletion ORM/ORMInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace h4cc\AliceFixturesBundle\ORM;

use Nelmio\Alice\ORMInterface as NelmioORMInterface;
use Nelmio\Alice\PersisterInterface as NelmioORMInterface;

/**
* Interface for Object Relation Mapping operations.
Expand Down
14 changes: 7 additions & 7 deletions Tests/Fixture/FixtureManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace h4cc\AliceFixturesBundle\Tests\Fixtures;

use h4cc\AliceFixturesBundle\Fixtures\FixtureManager;
use Nelmio\Alice\Loader\Yaml;

use Nelmio\Alice\Fixtures\Loader;

/**
* Class FixtureManagerTest
Expand Down Expand Up @@ -54,9 +55,8 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$this->yamlLoaderMock = $this->getMockBuilder('\Nelmio\Alice\Loader\Yaml')
$this->yamlLoaderMock = $this->getMockBuilder('\Nelmio\Alice\Fixtures\Loader')
->setMethods(array('setProviders', 'addProvider', 'load'))
->disableOriginalConstructor()
->getMock();

$this->factoryMock = $this->getMockBuilder('\h4cc\AliceFixturesBundle\Loader\FactoryInterface')
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testLoadNoFiles()
public function testLoadYaml()
{
$this->factoryMock->expects($this->any())->method('getLoader')
->with('yaml', 'en_EN')->will($this->returnValue(new Yaml()));
->with('en_EN')->will($this->returnValue(new Loader()));

$this->managerRegistryMock->expects($this->any())->method('getManagerForClass')
->will($this->returnValue($this->objectManagerMock));
Expand All @@ -146,7 +146,7 @@ public function testLoadYaml()
public function testProcessor()
{
$this->factoryMock->expects($this->any())->method('getLoader')
->with('yaml', 'en_EN')->will($this->returnValue(new Yaml()));
->with('en_EN')->will($this->returnValue(new Loader()));

$this->managerRegistryMock->expects($this->any())->method('getManagerForClass')
->will($this->returnValue($this->objectManagerMock));
Expand Down Expand Up @@ -185,7 +185,7 @@ public function testRemove()
public function testProviders()
{
$this->factoryMock->expects($this->any())->method('getLoader')
->with('yaml', 'en_EN')->will($this->returnValue($this->yamlLoaderMock));
->with('en_EN')->will($this->returnValue($this->yamlLoaderMock));

$this->yamlLoaderMock->expects($this->once())->method('load')->will($this->returnValue(array()));

Expand All @@ -207,7 +207,7 @@ public function testLocalEntities()
{
// We need a real YAML Loader for this.
$this->factoryMock->expects($this->any())->method('getLoader')
->with('yaml', 'en_EN')->will($this->returnValue(new Yaml()));
->with('en_EN')->will($this->returnValue(new Loader()));

$this->managerRegistryMock->expects($this->any())->method('getManagerForClass')
->will($this->returnValue($this->objectManagerMock));
Expand Down
17 changes: 2 additions & 15 deletions Tests/Loader/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,8 @@ public function setUp()

public function testGetLoader()
{
$loader = $this->factory->getLoader('yaml', 'de_DE');
$loader = $this->factory->getLoader('de_DE');

$this->assertInstanceOf('\Nelmio\Alice\Loader\Yaml', $loader);

$loader = $this->factory->getLoader('php', 'de_DE');

$this->assertInstanceOf('\Nelmio\Alice\Loader\Base', $loader);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unknown loader type 'foo'.
*/
public function testException()
{
$this->factory->getLoader('foo', 'bar');
$this->assertInstanceOf('\Nelmio\Alice\Fixtures\Loader', $loader);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.3.0",
"nelmio/alice": "~1.6",
"nelmio/alice": "~2.0",
"doctrine/common": "~2.1",
"psr/log": "~1.0",
"symfony/finder": "~2.0"
Expand Down