Skip to content

Commit

Permalink
Merge branch 'fix/storage-acessors-on-repository'
Browse files Browse the repository at this point in the history
* fix/storage-acessors-on-repository:
  remove optional modules
  Fix
  • Loading branch information
williamespindola committed Sep 22, 2015
2 parents f1205db + 7e0a3b8 commit 07bfa71
Show file tree
Hide file tree
Showing 13 changed files with 973 additions and 50 deletions.
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: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
],
"require": {
"php" : ">=5.4",
"ocramius/generated-hydrator": "1.1.0",
"symfony/console": "~2.7"
"ocramius/generated-hydrator": "1.1.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;
}
}
27 changes: 2 additions & 25 deletions src/Repository/RepositoryAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,9 @@

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

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

$this->storage = $storage->getRepository();
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();
}
36 changes: 34 additions & 2 deletions tests/unit/Repository/RepositoryAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use WilliamEspindola\Field\Repository\RepositoryAbstract;

use WilliamEspindola\Field\Storage\ORM\StorageORMInterface;

class RepositoryAbstractTest extends PHPUnit_Framework_TestCase
{
public function testSetAndGetStorageWithValidDataShouldWork()
Expand All @@ -28,7 +30,6 @@ public function testSetAndGetStorageWithValidDataShouldWork()
$repository->getStorage()
);
}

public function testFindAllShouldReturnAnArrayObject()
{
$storageAbstract = $this->getMock('sdtClass', ['findAll']);
Expand Down Expand Up @@ -56,5 +57,36 @@ public function testFindAllShouldReturnAnArrayObject()
}
}

class MockRepository extends RepositoryAbstract {}
class MockRepository extends RepositoryAbstract {
/**
* @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;
}
}
Loading

0 comments on commit 07bfa71

Please sign in to comment.