Skip to content
Closed
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
26 changes: 26 additions & 0 deletions ActivityRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace XApi\Repository\Api;

use Xabbuh\XApi\Common\Exception\NotFoundException;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;

/**
* Public API of an Experience API (xAPI) {@link Activity} repository.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
interface ActivityRepositoryInterface
{
/**
* Finds a {@link Activity} by id.
*
* @param IRI $activityId The activity id to filter by
*
* @return Activity The activity
*
* @throws NotFoundException if no Activity with the given IRI does exist
*/
public function findActivityById(IRI $activityId);
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG

* made the package compatible with `3.x` releases of `ramsey/uuid`
* allow `2.x` releases of the `php-xapi/model` package too
* Added a `ActivityRepositoryInterface` that defines the public API of a
activity repository.

0.3.0
-----
Expand Down
75 changes: 75 additions & 0 deletions Test/Functional/ActivityRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace XApi\Repository\Api\Test\Functional;

use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;
use XApi\Repository\Api\ActivityRepositoryInterface;

/**
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
abstract class ActivityRepositoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ActivityRepositoryInterface
*/
private $activityRepository;

protected function setUp()
{
$this->activityRepository = $this->createActivityRepository();
$this->cleanDatabase();
}

protected function tearDown()
{
$this->cleanDatabase();
}

/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingNonExistingActivityThrowsException()
{
$this->activityRepository->findActivityById(IRI::fromString('not-existing'));
}

/**
* @dataProvider getStatementsWithId
*/
public function testActivitiesCanBeRetrievedById(Activity $activity)
{
$fetchedActivity = $this->activityRepository->findActivityById($activity->getId());

$this->assertTrue($activity->equals($fetchedActivity));
}

public function getActivitiesWithId()
{
$fixtures = array();

foreach (get_class_methods('Xabbuh\XApi\DataFixtures\ActivityFixtures') as $method) {
$activity = call_user_func(array('Xabbuh\XApi\DataFixtures\ActivityFixtures', $method));

if ($activity instanceof Activity) {
$fixtures[$method] = array($activity);
}
}

return $fixtures;
}

abstract protected function createActivityRepository();

abstract protected function cleanDatabase();
}