From 33f7e087023e1348007892b0c3323cf6b1f35ed5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 Mar 2017 08:55:54 +0100 Subject: [PATCH] add missing statement version attribute --- CHANGELOG.md | 6 ++++++ spec/StatementSpec.php | 14 ++++++++++++++ src/Statement.php | 24 +++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7cddff..e42c9d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/spec/StatementSpec.php b/spec/StatementSpec.php index de0cd77..a30cfbf 100644 --- a/spec/StatementSpec.php +++ b/spec/StatementSpec.php @@ -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(); @@ -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( diff --git a/src/Statement.php b/src/Statement.php index 5410ba6..d191254 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -65,6 +65,8 @@ final class Statement private $attachments; + private $version; + /** * @param StatementId|null $id * @param Actor $actor @@ -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; @@ -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) @@ -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. * @@ -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).