Skip to content

Commit 6767853

Browse files
committed
reusable domain object test fixtures
1 parent 9f57132 commit 6767853

35 files changed

+717
-257
lines changed

Test/Fixture/ActivityFixtures.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
use Xabbuh\XApi\Common\Model\Activity;
15+
use Xabbuh\XApi\Common\Model\Definition;
16+
17+
/**
18+
* Activity fixtures.
19+
*
20+
* @author Christian Flothmann <[email protected]>
21+
*/
22+
class ActivityFixtures
23+
{
24+
/**
25+
* Loads an activity.
26+
*
27+
* @return \Xabbuh\XApi\Common\Model\ActivityInterface
28+
*/
29+
public static function getActivity()
30+
{
31+
$definition = new Definition();
32+
$definition->setName(array(
33+
'en-GB' => 'example activity',
34+
'en-US' => 'example activity',
35+
));
36+
$definition->setDescription(array(
37+
'en-GB' => 'An example of an activity',
38+
'en-US' => 'An example of an activity',
39+
));
40+
$definition->setType('http://www.example.co.uk/types/exampleactivitytype');
41+
$activity = new Activity();
42+
$activity->setId('http://www.example.co.uk/exampleactivity');
43+
$activity->setDefinition($definition);
44+
45+
return $activity;
46+
}
47+
}

Test/Fixture/ActivityJsonFixtures.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
/**
15+
* JSON encoded activity fixtures.
16+
*
17+
* @author Christian Flothmann <[email protected]>
18+
*/
19+
class ActivityJsonFixtures extends JsonFixtures
20+
{
21+
/**
22+
* Loads an activity.
23+
*
24+
* @return \Xabbuh\XApi\Common\Model\ActivityInterface
25+
*/
26+
public static function getActivity()
27+
{
28+
return static::load('activity');
29+
}
30+
}

Test/Fixture/ActorFixtures.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
use Xabbuh\XApi\Common\Model\Account;
15+
use Xabbuh\XApi\Common\Model\Agent;
16+
use Xabbuh\XApi\Common\Model\Group;
17+
18+
/**
19+
* Actor fixtures.
20+
*
21+
* @author Christian Flothmann <[email protected]>
22+
*/
23+
class ActorFixtures
24+
{
25+
/**
26+
* Loads an agent.
27+
*
28+
* @return \Xabbuh\XApi\Common\Model\AgentInterface
29+
*/
30+
public static function getAgent()
31+
{
32+
$agent = new Agent();
33+
$agent->setName('Christian');
34+
$agent->setMbox('mailto:[email protected]');
35+
36+
return $agent;
37+
}
38+
39+
/**
40+
* Loads a group.
41+
*
42+
* @return \Xabbuh\XApi\Common\Model\GroupInterface
43+
*/
44+
public static function getGroup()
45+
{
46+
$group = static::getAnonymousGroup();
47+
$group->setName('Example Group');
48+
$account = new Account();
49+
$account->setHomePage('http://example.com/homePage');
50+
$account->setName('GroupAccount');
51+
$group->setAccount($account);
52+
53+
return $group;
54+
}
55+
56+
/**
57+
* Loads an anonymous group.
58+
*
59+
* @return \Xabbuh\XApi\Common\Model\GroupInterface
60+
*/
61+
public static function getAnonymousGroup()
62+
{
63+
$group = new Group();
64+
$group->setName('Anonymous Group');
65+
66+
$agent1 = new Agent();
67+
$agent1->setName('Andrew Downes');
68+
$agent1->setMbox('mailto:[email protected]');
69+
$agent2 = new Agent();
70+
$agent2->setName('Aaron Silvers');
71+
$agent2->setOpenId('aaron.openid.example.org');
72+
$group->setMembers(array($agent1, $agent2));
73+
74+
return $group;
75+
}
76+
}

Test/Fixture/ActorJsonFixtures.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
/**
15+
* JSON encoded actor fixtures.
16+
*
17+
* @author Christian Flothmann <[email protected]>
18+
*/
19+
class ActorJsonFixtures extends JsonFixtures
20+
{
21+
/**
22+
* Loads an agent.
23+
*
24+
* @return string
25+
*/
26+
public static function getAgent()
27+
{
28+
return static::load('agent');
29+
}
30+
31+
/**
32+
* Loads an agent without an object type reference included.
33+
*
34+
* @return string
35+
*/
36+
public static function getAgentWithoutObjectType()
37+
{
38+
return static::load('agent_without_object_type');
39+
}
40+
41+
/**
42+
* Loads a group.
43+
*
44+
* @return string
45+
*/
46+
public static function getGroup()
47+
{
48+
return static::load('group');
49+
}
50+
51+
/**
52+
* Loads an anonymous group.
53+
*
54+
* @return string
55+
*/
56+
public static function getAnonymousGroup()
57+
{
58+
return static::load('anonymous_group');
59+
}
60+
}

Test/Fixture/DocumentFixtures.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
use Xabbuh\XApi\Common\Model\ActivityProfileDocument;
15+
use Xabbuh\XApi\Common\Model\AgentProfileDocument;
16+
use Xabbuh\XApi\Common\Model\Document;
17+
use Xabbuh\XApi\Common\Model\StateDocument;
18+
19+
/**
20+
* Document fixtures.
21+
*
22+
* @author Christian Flothmann <[email protected]>
23+
*/
24+
class DocumentFixtures
25+
{
26+
/**
27+
* Loads a document.
28+
*
29+
* @return \Xabbuh\XApi\Common\Model\DocumentInterface
30+
*/
31+
public static function getDocument()
32+
{
33+
$document = new Document();
34+
$document['x'] = 'foo';
35+
$document['y'] = 'bar';
36+
37+
return $document;
38+
}
39+
40+
/**
41+
* Loads an activity profile document.
42+
*
43+
* @return \Xabbuh\XApi\Common\Model\ActivityProfileDocumentInterface
44+
*/
45+
public static function getActivityProfileDocument()
46+
{
47+
$document = new ActivityProfileDocument();
48+
$document['x'] = 'foo';
49+
$document['y'] = 'bar';
50+
51+
return $document;
52+
}
53+
54+
/**
55+
* Loads an agent profile document.
56+
*
57+
* @return \Xabbuh\XApi\Common\Model\AgentProfileDocumentInterface
58+
*/
59+
public static function getAgentProfileDocument()
60+
{
61+
$document = new AgentProfileDocument();
62+
$document['x'] = 'foo';
63+
$document['y'] = 'bar';
64+
65+
return $document;
66+
}
67+
68+
/**
69+
* Loads a state document.
70+
*
71+
* @return \Xabbuh\XApi\Common\Model\StateDocumentInterface
72+
*/
73+
public static function getStateDocument()
74+
{
75+
$document = new StateDocument();
76+
$document['x'] = 'foo';
77+
$document['y'] = 'bar';
78+
79+
return $document;
80+
}
81+
}

Test/Fixture/DocumentJsonFixtures.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
/**
15+
* JSON encoded document fixtures.
16+
*
17+
* @author Christian Flothmann <[email protected]>
18+
*/
19+
class DocumentJsonFixtures extends JsonFixtures
20+
{
21+
/**
22+
* Loads a document.
23+
*
24+
* @return string
25+
*/
26+
public static function getDocument()
27+
{
28+
return static::load('document');
29+
}
30+
}

Test/Fixture/JsonFixtures.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Common\Test\Fixture;
13+
14+
/**
15+
* JSON encoded fixtures.
16+
*
17+
* @author Christian Flothmann <[email protected]>
18+
*/
19+
abstract class JsonFixtures
20+
{
21+
/**
22+
* Loads a JSON encoded fixture from the file system
23+
*
24+
* @param string $file The fixture to load
25+
*
26+
* @return string The JSON encoded fixture
27+
*/
28+
protected static function load($file)
29+
{
30+
return file_get_contents(__DIR__.'/fixtures/'.$file.'.json');
31+
}
32+
}

0 commit comments

Comments
 (0)