diff --git a/ActivityRepositoryInterface.php b/ActivityRepositoryInterface.php new file mode 100644 index 0000000..07bd0ab --- /dev/null +++ b/ActivityRepositoryInterface.php @@ -0,0 +1,26 @@ + + */ +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); +} diff --git a/CHANGELOG.md b/CHANGELOG.md index f6ebb1a..6af2eb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/Test/Functional/ActivityRepositoryTest.php b/Test/Functional/ActivityRepositoryTest.php new file mode 100644 index 0000000..ed25581 --- /dev/null +++ b/Test/Functional/ActivityRepositoryTest.php @@ -0,0 +1,75 @@ + + * + * 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 + */ +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(); +}