Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

2.0.1
-----

* Added missing `$version` attribute to the `Statement` class which defaults to
`1.0.0`.

2.0.0
-----

Expand Down
14 changes: 14 additions & 0 deletions spec/StatementSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ function let()
$this->beConstructedWith($id, $actor, $verb, $object);
}

function its_default_version_is_1_0_0()
{
$this->getVersion()->shouldReturn('1.0.0');
}

function it_creates_reference_to_itself()
{
$reference = $this->getStatementReference();
Expand Down Expand Up @@ -231,6 +236,15 @@ public function it_returns_a_new_instance_with_attachments()
$statement->getAttachments()->shouldReturn($attachments);
}

function it_returns_a_new_instance_with_version()
{
$statement = $this->withVersion('1.0.1');

$statement->shouldNotBe($this);
$statement->shouldBeAnInstanceOf('\Xabbuh\XApi\Model\Statement');
$statement->getVersion()->shouldReturn('1.0.1');
}

function it_ignores_array_keys_in_attachment_lists()
{
$textAttachment = new Attachment(
Expand Down
24 changes: 23 additions & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ final class Statement

private $attachments;

private $version;

/**
* @param StatementId|null $id
* @param Actor $actor
Expand All @@ -76,8 +78,9 @@ final class Statement
* @param \DateTime|null $stored
* @param Context|null $context
* @param Attachment[]|null $attachments
* @param string $version
*/
public function __construct(StatementId $id = null, Actor $actor, Verb $verb, Object $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null, Context $context = null, array $attachments = null)
public function __construct(StatementId $id = null, Actor $actor, Verb $verb, Object $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null, Context $context = null, array $attachments = null, $version = '1.0.0')
{
$this->id = $id;
$this->actor = $actor;
Expand All @@ -89,6 +92,7 @@ public function __construct(StatementId $id = null, Actor $actor, Verb $verb, Ob
$this->stored = $stored;
$this->context = $context;
$this->attachments = null !== $attachments ? array_values($attachments) : null;
$this->version = $version;
}

public function withId(StatementId $id = null)
Expand Down Expand Up @@ -184,6 +188,19 @@ public function withAttachments(array $attachments = null)
return $statement;
}

/**
* @param string $version
*
* @return self
*/
public function withVersion($version)
{
$statement = clone $this;
$statement->version = $version;

return $statement;
}

/**
* Returns the Statement's unique identifier.
*
Expand Down Expand Up @@ -291,6 +308,11 @@ public function getAttachments()
return $this->attachments;
}

public function getVersion()
{
return $this->version;
}

/**
* Tests whether or not this Statement is a void Statement (i.e. it voids
* another Statement).
Expand Down