Skip to content

Commit 504a2cb

Browse files
committed
expanded the persistence API
1 parent a4323df commit 504a2cb

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

Manager/StatementManager.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
namespace Xabbuh\XApi\Storage\Doctrine\Manager;
1313

1414
use Xabbuh\XApi\Model\Statement;
15-
use Xabbuh\XApi\Storage\Api\StatementManager as BaseStatementManager;
15+
use Xabbuh\XApi\Model\StatementsFilter;
16+
use Xabbuh\XApi\Storage\Api\Exception\NotFoundException;
17+
use Xabbuh\XApi\Storage\Api\StatementManagerInterface;
1618
use Xabbuh\XApi\Storage\Doctrine\Repository\StatementRepositoryInterface;
1719

1820
/**
1921
* Doctrine based {@link Statement} manager.
2022
*
2123
* @author Christian Flothmann <[email protected]>
2224
*/
23-
class StatementManager extends BaseStatementManager
25+
class StatementManager implements StatementManagerInterface
2426
{
2527
/**
2628
* @var StatementRepositoryInterface The statement repository
@@ -35,17 +37,39 @@ public function __construct(StatementRepositoryInterface $repository)
3537
/**
3638
* {@inheritDoc}
3739
*/
38-
public function findStatementBy(array $criteria)
40+
public function findStatementById($statementId)
3941
{
40-
return $this->repository->findOneBy($criteria);
42+
/** @var Statement $statement */
43+
$statement = $this->repository->findOneBy(array('id' => $statementId));
44+
45+
if (null === $statement) {
46+
throw new NotFoundException();
47+
}
48+
49+
return $statement;
50+
}
51+
52+
/**
53+
* {@inheritDoc}
54+
*/
55+
public function findVoidedStatementById($statementId)
56+
{
57+
/** @var Statement $statement */
58+
$statement = $this->repository->findOneBy(array('id' => $statementId));
59+
60+
if (null === $statement) {
61+
throw new NotFoundException();
62+
}
63+
64+
return $statement;
4165
}
4266

4367
/**
4468
* {@inheritDoc}
4569
*/
46-
public function findStatementsBy(array $criteria)
70+
public function findStatementsBy(StatementsFilter $filter)
4771
{
48-
return $this->repository->findBy($criteria);
72+
return $this->repository->findBy($filter->getFilter());
4973
}
5074

5175
/**

Tests/Manager/StatementManagerTest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Xabbuh\XApi\Storage\Doctrine\Tests\Manager;
1313

1414
use Xabbuh\XApi\DataFixtures\StatementFixtures;
15+
use Xabbuh\XApi\DataFixtures\VerbFixtures;
16+
use Xabbuh\XApi\Model\StatementsFilter;
1517
use Xabbuh\XApi\Storage\Doctrine\Manager\StatementManager;
1618

1719
/**
@@ -42,37 +44,25 @@ public function testFindStatementById()
4244
->repository
4345
->expects($this->once())
4446
->method('findOneBy')
45-
->with(array('id' => $statementId));
47+
->with(array('id' => $statementId))
48+
->will($this->returnValue(StatementFixtures::getMinimalStatement()));
4649

4750
$this->statementManager->findStatementById($statementId);
4851
}
4952

50-
public function testFindStatementByCriteria()
51-
{
52-
$this
53-
->repository
54-
->expects($this->once())
55-
->method('findOneBy')
56-
->with($this->equalTo(array('foo' => 'bar', 'baz' => 'foobar')));
57-
58-
$this->statementManager->findStatementBy(array(
59-
'foo' => 'bar',
60-
'baz' => 'foobar',
61-
));
62-
}
63-
6453
public function testFindStatementsByCriteria()
6554
{
55+
$verb = VerbFixtures::getVerb();
56+
6657
$this
6758
->repository
6859
->expects($this->once())
6960
->method('findBy')
70-
->with($this->equalTo(array('foo' => 'bar', 'baz' => 'foobar')));
61+
->with($this->equalTo(array('verb' => $verb->getId())));
7162

72-
$this->statementManager->findStatementsBy(array(
73-
'foo' => 'bar',
74-
'baz' => 'foobar',
75-
));
63+
$filter = new StatementsFilter();
64+
$filter->byVerb($verb);
65+
$this->statementManager->findStatementsBy($filter);
7666
}
7767

7868
public function testSave()

0 commit comments

Comments
 (0)