From f1253b63d13b5ba5ba70e3a585728192623b722b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Mon, 6 Mar 2017 17:15:42 +0100 Subject: [PATCH 1/3] Introduce ActivityRepositoryInterface --- ActivityRepositoryInterface.php | 26 ++++++++ Test/Functional/ActivityRepositoryTest.php | 77 ++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 ActivityRepositoryInterface.php create mode 100644 Test/Functional/ActivityRepositoryTest.php 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/Test/Functional/ActivityRepositoryTest.php b/Test/Functional/ActivityRepositoryTest.php new file mode 100644 index 0000000..e62c5c9 --- /dev/null +++ b/Test/Functional/ActivityRepositoryTest.php @@ -0,0 +1,77 @@ + + * + * 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 +{ + const UUID_REGEXP = '/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i'; + + /** + * @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(); +} From ecc017f84ed4c913487fd4d0672df0d916d6844e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Mon, 6 Mar 2017 17:20:19 +0100 Subject: [PATCH 2/3] Remove useless constant --- Test/Functional/ActivityRepositoryTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Test/Functional/ActivityRepositoryTest.php b/Test/Functional/ActivityRepositoryTest.php index e62c5c9..ed25581 100644 --- a/Test/Functional/ActivityRepositoryTest.php +++ b/Test/Functional/ActivityRepositoryTest.php @@ -20,8 +20,6 @@ */ abstract class ActivityRepositoryTest extends \PHPUnit_Framework_TestCase { - const UUID_REGEXP = '/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i'; - /** * @var ActivityRepositoryInterface */ From 1f1c0a0d4da5c8bb301ff144e714f5f14fccceb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Parmentier?= Date: Mon, 20 Mar 2017 16:57:53 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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 -----