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

Fix #26

Merged
merged 1 commit into from
Sep 22, 2015
Merged

Fix #26

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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ matrix:
before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
- travis_retry composer require doctrine/orm
- travis_retry composer require respect/relational

script:
- phpunit --configuration phpunit.xml.dist --coverage-text --coverage-clover=coverage.clover
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"require": {
"php" : ">=5.4",
"ocramius/generated-hydrator": "1.1.0",
"symfony/console": "~2.7"
"symfony/console": "~2.7",
"respect/relational": "^0.8.0"
},
"require-dev": {
"phpunit/phpunit" : "4.*",
Expand Down
764 changes: 764 additions & 0 deletions coverage.clover

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions src/Repository/CollectionFieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,35 @@ class CollectionFieldRepository
extends RepositoryAbstract
implements RepositoryInterface
{
/**
* @var object StorageORMInterface
*/
protected $storage;

public function __construct(StorageORMInterface $storage)
{
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\CollectionField');
}

/**
* @param StorageORMInterface $storage
* @param string $repository
* @return RepositoryAbstract
*/
public function setStorage(StorageORMInterface $storage, $repository)
{
$storage->setRepository($repository);

$this->storage = $storage->getStorage();

return $this;
}

/**
* @return StorageInterface
*/
public function getStorage()
{
return $this->storage;
}
}
27 changes: 27 additions & 0 deletions src/Repository/CollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,35 @@ class CollectionRepository
extends RepositoryAbstract
implements RepositoryInterface
{
/**
* @var object StorageORMInterface
*/
protected $storage;

public function __construct(StorageORMInterface $storage)
{
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Collection');
}

/**
* @param StorageORMInterface $storage
* @param string $repository
* @return RepositoryAbstract
*/
public function setStorage(StorageORMInterface $storage, $repository)
{
$storage->setRepository($repository);

$this->storage = $storage->getStorage();

return $this;
}

/**
* @return StorageInterface
*/
public function getStorage()
{
return $this->storage;
}
}
27 changes: 27 additions & 0 deletions src/Repository/FieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,35 @@ class FieldRepository
extends RepositoryAbstract
implements RepositoryInterface
{
/**
* @var object StorageORMInterface
*/
protected $storage;

public function __construct(StorageORMInterface $storage)
{
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Field');
}

/**
* @param StorageORMInterface $storage
* @param string $repository
* @return RepositoryAbstract
*/
public function setStorage(StorageORMInterface $storage, $repository)
{
$storage->setRepository($repository);

$this->storage = $storage->getStorage();

return $this;
}

/**
* @return StorageInterface
*/
public function getStorage()
{
return $this->storage;
}
}
27 changes: 27 additions & 0 deletions src/Repository/OptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,35 @@ class OptionRepository
extends RepositoryAbstract
implements RepositoryInterface
{
/**
* @var object StorageORMInterface
*/
protected $storage;

public function __construct(StorageORMInterface $storage)
{
$this->setStorage($storage, 'WilliamEspindola\Field\Entity\Options');
}

/**
* @param StorageORMInterface $storage
* @param string $repository
* @return RepositoryAbstract
*/
public function setStorage(StorageORMInterface $storage, $repository)
{
$storage->setRepository($repository);

$this->storage = $storage->getStorage();

return $this;
}

/**
* @return StorageInterface
*/
public function getStorage()
{
return $this->storage;
}
}
25 changes: 2 additions & 23 deletions src/Repository/RepositoryAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,9 @@

abstract class RepositoryAbstract
{
/**
* @var object StorageORMInterface
*/
protected $storage;

/**
* @param StorageORMInterface $storage
* @param string $repository
* @return RepositoryAbstract
*/
public function setStorage(StorageORMInterface $storage, $repository)
{
$this->storage = $storage->setRepository($repository);
abstract public function setStorage(StorageORMInterface $storage, $repository);

return $this;
}

/**
* @return StorageInterface
*/
public function getStorage()
{
return $this->storage;
}
abstract public function getStorage();

/**
* @return \ArrayObject
Expand Down
7 changes: 5 additions & 2 deletions src/Storage/ORM/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ public function getRepository()
return $this->getMapper()->getRepository($this->repository);
}

public function getStorage()
{
return $this;
}

public function setRepository($repository)
{
$this->repository = $repository;

return $this;
}

/**
Expand Down
29 changes: 26 additions & 3 deletions src/Storage/ORM/RespectRelational.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Respect\Relational\Mapper;
use Respect\Data\Styles;
use \InvalidArgumentException as Argument;
use Respect\Data\Collections\Collection;

/**
* Providers the Respect\Relational\Mapper ORM behavior
Expand All @@ -15,6 +16,9 @@
*/
class RespectRelational implements StorageORMInterface
{
/**
*
*/
const INVALID_MAPPER_MESSAGE = 'Argument must be Respect\Relational\Mapper';

/**
Expand All @@ -27,6 +31,9 @@ class RespectRelational implements StorageORMInterface
*/
protected $repository;

/**
* @param Mapper $mapper
*/
public function __construct(Mapper $mapper)
{
$this->setMapper($mapper);
Expand All @@ -51,6 +58,10 @@ public function getMapper()
return $this->mapper;
}

/**
* @param $repository
* @throws \InvalidArgumentException
*/
public function setRepository($repository)
{
if (empty($repository))
Expand All @@ -61,22 +72,34 @@ public function setRepository($repository)
$repository = strtolower($reflect->getShortName());
}

$this->repository = $repository;
$this->repository = new Collection($repository);
$this->repository->setMapper($this->mapper);
}

/**
* @return $this
*/
public function getStorage()
{
return $this;
}

/**
* @return string
*/
public function getRepository()
{
return $this->getMapper()->{$this->repository};
return $this->repository;
}

/**
* @return array
*/
public function findAll()
{
return $this->getRepository()->fetchAll();
$repository = $this->getRepository();

return $repository->fetchAll();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Storage/ORM/StorageORMInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace WilliamEspindola\Field\Storage\ORM;

use WilliamEspindola\Field\Entity\EntityInterface;

/**
* Interface StorageORMInterface
*
Expand Down Expand Up @@ -77,4 +75,9 @@ public function getRepository();
* @return mixed
*/
public function setRepository($repository);

/**
* @return mixed
*/
public function getStorage();
}
28 changes: 18 additions & 10 deletions tests/unit/Repository/FiendRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@

class FieldRepositoryTest extends PHPUnit_Framework_TestCase
{
protected function setUp()
public function testFindAllShouldReturnAnArrayObject()
{
$this->storage = $this->getMock('\WilliamEspindola\Field\Storage\ORM\StorageORMInterface');
$storageAbstract = $this->getMock('sdtClass', ['findAll']);

$this->storage->expects($this->any())
->method('findAll')
->will($this->returnValue([]));
$storageAbstract->expects($this->any())
->method('findAll')
->will($this->returnValue((object)([])));

$this->repository = new FieldRepository($this->storage);
}
$storage = $this->getMock('\WilliamEspindola\Field\Storage\ORM\StorageORMInterface');

public function testFindAllShouldReturnAnArrayObject()
{
$this->assertInstanceOf('ArrayObject', $this->repository->findAll());
$storage->expects($this->any())
->method('__get')
->with($this->equalTo('storage'))
->will($this->returnValue($storageAbstract));

$storage->expects($this->any())
->method('getRepository')
->will($this->returnValue($storageAbstract));

$repository = new FieldRepository($storage);

$this->assertInstanceOf('stdClass', $repository->findAll());
}
}
22 changes: 0 additions & 22 deletions tests/unit/Repository/OptionRepositoryTest.php

This file was deleted.

Loading