From 2b2f311aebd2b11e8fff42ebeaa6fcb8c2c697f0 Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Tue, 26 Jul 2022 07:32:26 +0200 Subject: [PATCH 01/16] Implemented LtiDeepLinkResourceIcon and added the missing fields to the LtiDeepLinkResource --- src/LtiDeepLinkResource.php | 112 +++++++++++++++++++++++++- src/LtiDeepLinkResourceIcon.php | 90 +++++++++++++++++++++ tests/LtiDeepLinkResourceIconTest.php | 90 +++++++++++++++++++++ 3 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 src/LtiDeepLinkResourceIcon.php create mode 100644 tests/LtiDeepLinkResourceIconTest.php diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index ee646e50..16348b39 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -9,19 +9,32 @@ class LtiDeepLinkResource private $text; private $url; private $lineitem; + private $icon; + private $thumbnail; private $custom_params = []; private $target = 'iframe'; + /** + * @return LtiDeepLinkResource + */ public static function new() { return new LtiDeepLinkResource(); } + /** + * @return string + */ public function getType() { return $this->type; } + /** + * @param $value string + * + * @return $this + */ public function setType($value) { $this->type = $value; @@ -29,11 +42,19 @@ public function setType($value) return $this; } + /** + * @return string + */ public function getTitle() { return $this->title; } + /** + * @param $value string + * + * @return $this + */ public function setTitle($value) { $this->title = $value; @@ -41,11 +62,19 @@ public function setTitle($value) return $this; } + /** + * @return string + */ public function getText() { return $this->text; } + /** + * @param $value string + * + * @return $this + */ public function setText($value) { $this->text = $value; @@ -53,11 +82,19 @@ public function setText($value) return $this; } + /** + * @return string + */ public function getUrl() { return $this->url; } + /** + * @param $value string + * + * @return $this + */ public function setUrl($value) { $this->url = $value; @@ -65,23 +102,79 @@ public function setUrl($value) return $this; } + /** + * @return LtiLineitem + */ public function getLineitem() { return $this->lineitem; } - public function setLineitem(LtiLineitem $value) + /** + * @param $value LtiLineitem + * + * @return $this + */ + public function setLineitem($value) { $this->lineitem = $value; return $this; } + /** + * @param $icon LtiDeepLinkResourceIcon + * + * @return $this + */ + public function setIcon($icon) + { + $this->icon = $icon; + + return $this; + } + + /** + * @return LtiDeepLinkResourceIcon + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @param $thumbnail LtiDeepLinkResourceIcon + * + * @return $this + */ + public function setThumbnail($thumbnail) + { + $this->thumbnail = $thumbnail; + + return $this; + } + + /** + * @return LtiDeepLinkResourceIcon + */ + public function getThumbnail() + { + return $this->thumbnail; + } + + /** + * @return array + */ public function getCustomParams() { return $this->custom_params; } + /** + * @param $value array + * + * @return $this + */ public function setCustomParams($value) { $this->custom_params = $value; @@ -89,11 +182,19 @@ public function setCustomParams($value) return $this; } + /** + * @return string + */ public function getTarget() { return $this->target; } + /** + * @param $value string + * + * @return $this + */ public function setTarget($value) { $this->target = $value; @@ -101,6 +202,9 @@ public function setTarget($value) return $this; } + /** + * @return array + */ public function toArray() { $resource = [ @@ -115,6 +219,12 @@ public function toArray() if (!empty($this->custom_params)) { $resource['custom'] = $this->custom_params; } + if (isset($this->icon)) { + $resource['icon'] = $this->icon->toArray(); + } + if (isset($this->thumbnail)) { + $resource['thumbnail'] = $this->thumbnail->toArray(); + } if ($this->lineitem !== null) { $resource['lineItem'] = [ 'scoreMaximum' => $this->lineitem->getScoreMaximum(), diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php new file mode 100644 index 00000000..48812c71 --- /dev/null +++ b/src/LtiDeepLinkResourceIcon.php @@ -0,0 +1,90 @@ +url = $url; + + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param $width int + * + * @return $this + */ + public function setWidth($width) + { + $this->width = $width; + + return $this; + } + + /** + * @return int + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param $height int + * + * @return $this + */ + public function setHeight($height) + { + $this->height = $height; + + return $this; + } + + /** + * @return int + */ + public function getHeight() + { + return $this->height; + } + + /** + * @return array + */ + public function toArray() + { + return [ + 'url' => $this->url, + 'width' => $this->width, + 'height' => $this->height, + ]; + } +} diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php new file mode 100644 index 00000000..0e92dcea --- /dev/null +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -0,0 +1,90 @@ +deepLinkResourceIcon = new LtiDeepLinkResourceIcon(); + } + + public function testItInstantiates() + { + $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $this->deepLinkResourceIcon); + } + + public function testItCreatesANewInstance() + { + $deepLinkResource = LtiDeepLinkResourceIcon::new(); + + $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $deepLinkResource); + } + + public function testItGetsUrl() + { + $result = $this->deepLinkResourceIcon->getUrl(); + + $this->assertEquals(null, $result); + } + + public function testItSetsUrl() + { + $expected = 'expected'; + + $this->deepLinkResourceIcon->setUrl($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getUrl()); + } + + public function testItGetsWidth() + { + $result = $this->deepLinkResourceIcon->getWidth(); + + $this->assertEquals(null, $result); + } + + public function testItSetsWidth() + { + $expected = 300; + + $this->deepLinkResourceIcon->setWidth($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getWidth()); + } + + public function testItGetsHeight() + { + $result = $this->deepLinkResourceIcon->getHeight(); + + $this->assertEquals(null, $result); + } + + public function testItSetsHeight() + { + $expected = 400; + + $this->deepLinkResourceIcon->setHeight($expected); + + $this->assertEquals($expected, $this->deepLinkResourceIcon->getHeight()); + } + + public function testItCastsToArray() + { + $expected = [ + 'url' => 'https://example.com/icon.png', + 'width' => 100, + 'height' => 200, + ]; + + $this->deepLinkResourceIcon->setUrl($expected['url']); + $this->deepLinkResourceIcon->setWidth($expected['width']); + $this->deepLinkResourceIcon->setHeight($expected['height']); + + $result = $this->deepLinkResourceIcon->toArray(); + + $this->assertEquals($expected, $result); + } +} From fe0b581e9124d152573cecd6d87d74680a9c1219 Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Tue, 26 Jul 2022 07:54:33 +0200 Subject: [PATCH 02/16] Added icon and thumbnail to toArray test --- tests/LtiDeepLinkResourceTest.php | 53 ++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index f2f39f61..9d6075d5 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -4,6 +4,7 @@ use Mockery; use Packback\Lti1p3\LtiDeepLinkResource; +use Packback\Lti1p3\LtiDeepLinkResourceIcon; use Packback\Lti1p3\LtiLineitem; class LtiDeepLinkResourceTest extends TestCase @@ -105,6 +106,38 @@ public function testItSetsLineitem() $this->assertEquals($expected, $this->deepLinkResource->getLineitem()); } + public function testItGetsIcon() + { + $result = $this->deepLinkResource->getIcon(); + + $this->assertNull($result); + } + + public function testItSetsIcon() + { + $expected = Mockery::mock(LtiDeepLinkResourceIcon::class); + + $this->deepLinkResource->setIcon($expected); + + $this->assertEquals($expected, $this->deepLinkResource->getIcon()); + } + + public function testItGetsThumbnail() + { + $result = $this->deepLinkResource->getThumbnail(); + + $this->assertNull($result); + } + + public function testItSetsThumbnail() + { + $expected = Mockery::mock(LtiDeepLinkResourceIcon::class); + + $this->deepLinkResource->setThumbnail($expected); + + $this->assertEquals($expected, $this->deepLinkResource->getThumbnail()); + } + public function testItGetsCustomParams() { $result = $this->deepLinkResource->getCustomParams(); @@ -139,19 +172,35 @@ public function testItSetsTarget() public function testItCastsToArray() { + $icon = (new LtiDeepLinkResourceIcon()) + ->setUrl('a_url') + ->setWidth(100) + ->setHeight(200); + $expected = [ 'type' => 'ltiResourceLink', 'title' => 'a_title', 'text' => 'a_text', 'url' => 'a_url', + 'icon' => [ + 'url' => $icon->getUrl(), + 'width' => $icon->getWidth(), + 'height' => $icon->getHeight() + ], + 'thumbnail' => [ + 'url' => $icon->getUrl(), + 'width' => $icon->getWidth(), + 'height' => $icon->getHeight() + ], 'presentation' => [ 'documentTarget' => 'iframe', ], 'lineItem' => [ 'scoreMaximum' => 80, 'label' => 'lineitem_label', - ], + ] ]; + $lineitem = Mockery::mock(LtiLineitem::class); $lineitem->shouldReceive('getScoreMaximum') ->twice()->andReturn($expected['lineItem']['scoreMaximum']); @@ -161,6 +210,8 @@ public function testItCastsToArray() $this->deepLinkResource->setTitle($expected['title']); $this->deepLinkResource->setText($expected['text']); $this->deepLinkResource->setUrl($expected['url']); + $this->deepLinkResource->setIcon($icon); + $this->deepLinkResource->setThumbnail($icon); $this->deepLinkResource->setLineitem($lineitem); $result = $this->deepLinkResource->toArray(); From dc08d8b7c241961d976310aa92d66d98f6d965e5 Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Tue, 26 Jul 2022 08:01:56 +0200 Subject: [PATCH 03/16] Linting --- tests/LtiDeepLinkResourceTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index 9d6075d5..aeac45b2 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -185,12 +185,12 @@ public function testItCastsToArray() 'icon' => [ 'url' => $icon->getUrl(), 'width' => $icon->getWidth(), - 'height' => $icon->getHeight() + 'height' => $icon->getHeight(), ], 'thumbnail' => [ 'url' => $icon->getUrl(), 'width' => $icon->getWidth(), - 'height' => $icon->getHeight() + 'height' => $icon->getHeight(), ], 'presentation' => [ 'documentTarget' => 'iframe', @@ -198,7 +198,7 @@ public function testItCastsToArray() 'lineItem' => [ 'scoreMaximum' => 80, 'label' => 'lineitem_label', - ] + ], ]; $lineitem = Mockery::mock(LtiLineitem::class); From aa26da454aab0837d17423eb90daff443835bb83 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:09 +0200 Subject: [PATCH 04/16] Update tests/LtiDeepLinkResourceTest.php Co-authored-by: Davo --- tests/LtiDeepLinkResourceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index aeac45b2..cd5b2126 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -172,7 +172,7 @@ public function testItSetsTarget() public function testItCastsToArray() { - $icon = (new LtiDeepLinkResourceIcon()) + $icon = LtiDeepLinkResourceIcon::new() ->setUrl('a_url') ->setWidth(100) ->setHeight(200); From 552f2d653f7a3a2a132a427571930e6859576ba0 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:21 +0200 Subject: [PATCH 05/16] Update tests/LtiDeepLinkResourceIconTest.php Co-authored-by: Davo --- tests/LtiDeepLinkResourceIconTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index 0e92dcea..bd37360f 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -59,7 +59,7 @@ public function testItGetsHeight() { $result = $this->deepLinkResourceIcon->getHeight(); - $this->assertEquals(null, $result); + $this->assertNull($result); } public function testItSetsHeight() From befd00b7e75354fb35544c3f3cbd50eda2fa8268 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:26 +0200 Subject: [PATCH 06/16] Update tests/LtiDeepLinkResourceIconTest.php Co-authored-by: Davo --- tests/LtiDeepLinkResourceIconTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index bd37360f..47b8f164 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -43,7 +43,7 @@ public function testItGetsWidth() { $result = $this->deepLinkResourceIcon->getWidth(); - $this->assertEquals(null, $result); + $this->assertNull($result); } public function testItSetsWidth() From 79804aed75043a2851d2b62e118b26ababd76e86 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:35 +0200 Subject: [PATCH 07/16] Update tests/LtiDeepLinkResourceIconTest.php Co-authored-by: Davo --- tests/LtiDeepLinkResourceIconTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index 47b8f164..ddf172dd 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -27,7 +27,7 @@ public function testItGetsUrl() { $result = $this->deepLinkResourceIcon->getUrl(); - $this->assertEquals(null, $result); + $this->assertNull($result); } public function testItSetsUrl() From 805b70d371c44ee964ea32ba856a24efa43c81d5 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:43 +0200 Subject: [PATCH 08/16] Update src/LtiDeepLinkResourceIcon.php Co-authored-by: Davo --- src/LtiDeepLinkResourceIcon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php index 48812c71..3be2ca79 100644 --- a/src/LtiDeepLinkResourceIcon.php +++ b/src/LtiDeepLinkResourceIcon.php @@ -79,7 +79,7 @@ public function getHeight() /** * @return array */ - public function toArray() + public function toArray(): array { return [ 'url' => $this->url, From 2172d733993368bc567dc1b8f332c1b370df6e10 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:52 +0200 Subject: [PATCH 09/16] Update src/LtiDeepLinkResource.php Co-authored-by: Davo --- src/LtiDeepLinkResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index 16348b39..7bddaae0 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -157,7 +157,7 @@ public function setThumbnail($thumbnail) /** * @return LtiDeepLinkResourceIcon */ - public function getThumbnail() + public function getThumbnail(): LtiDeepLinkResourceIcon { return $this->thumbnail; } From cbee79827639f60db1b816d884c6786b948624ee Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:33:56 +0200 Subject: [PATCH 10/16] Update src/LtiDeepLinkResource.php Co-authored-by: Davo --- src/LtiDeepLinkResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index 7bddaae0..18798a52 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -147,7 +147,7 @@ public function getIcon() * * @return $this */ - public function setThumbnail($thumbnail) + public function setThumbnail(LtiDeepLinkResourceIcon $thumbnail) { $this->thumbnail = $thumbnail; From ca94723d4defbc98473016f59377c046be05bd81 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:34:02 +0200 Subject: [PATCH 11/16] Update src/LtiDeepLinkResource.php Co-authored-by: Davo --- src/LtiDeepLinkResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index 18798a52..878d87eb 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -137,7 +137,7 @@ public function setIcon($icon) /** * @return LtiDeepLinkResourceIcon */ - public function getIcon() + public function getIcon(): LtiDeepLinkResourceIcon { return $this->icon; } From 400cb60e528f4f0f2cc45341b1031371ccf2d4c6 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:34:42 +0200 Subject: [PATCH 12/16] Update src/LtiDeepLinkResource.php Co-authored-by: Davo --- src/LtiDeepLinkResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index 878d87eb..d6e41296 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -115,7 +115,7 @@ public function getLineitem() * * @return $this */ - public function setLineitem($value) + public function setLineitem(LtiLineitem $value) { $this->lineitem = $value; From 890fb874413868c0e56e0eccc898ddfe390807a1 Mon Sep 17 00:00:00 2001 From: Jan Bebendorf Date: Fri, 29 Jul 2022 14:34:47 +0200 Subject: [PATCH 13/16] Update src/LtiDeepLinkResource.php Co-authored-by: Davo --- src/LtiDeepLinkResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index d6e41296..f5a3ce90 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -127,7 +127,7 @@ public function setLineitem(LtiLineitem $value) * * @return $this */ - public function setIcon($icon) + public function setIcon(LtiDeepLinkResourceIcon $icon) { $this->icon = $icon; From a77256a1089838722db0940096b96774d42f7f83 Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Fri, 29 Jul 2022 15:42:54 +0200 Subject: [PATCH 14/16] Added more explicit typing --- src/LtiDeepLinkResource.php | 130 ++++++-------------------- src/LtiDeepLinkResourceIcon.php | 53 +++-------- tests/LtiDeepLinkResourceIconTest.php | 4 +- tests/LtiDeepLinkResourceTest.php | 10 +- 4 files changed, 48 insertions(+), 149 deletions(-) diff --git a/src/LtiDeepLinkResource.php b/src/LtiDeepLinkResource.php index f5a3ce90..49e27b5a 100644 --- a/src/LtiDeepLinkResource.php +++ b/src/LtiDeepLinkResource.php @@ -8,204 +8,126 @@ class LtiDeepLinkResource private $title; private $text; private $url; - private $lineitem; + private $line_item; private $icon; private $thumbnail; private $custom_params = []; private $target = 'iframe'; - /** - * @return LtiDeepLinkResource - */ - public static function new() + public static function new(): LtiDeepLinkResource { return new LtiDeepLinkResource(); } - /** - * @return string - */ - public function getType() + public function getType(): string { return $this->type; } - /** - * @param $value string - * - * @return $this - */ - public function setType($value) + public function setType(string $value): LtiDeepLinkResource { $this->type = $value; return $this; } - /** - * @return string - */ - public function getTitle() + public function getTitle(): ?string { return $this->title; } - /** - * @param $value string - * - * @return $this - */ - public function setTitle($value) + public function setTitle(?string $value): LtiDeepLinkResource { $this->title = $value; return $this; } - /** - * @return string - */ - public function getText() + public function getText(): ?string { return $this->text; } - /** - * @param $value string - * - * @return $this - */ - public function setText($value) + public function setText(?string $value): LtiDeepLinkResource { $this->text = $value; return $this; } - /** - * @return string - */ - public function getUrl() + public function getUrl(): ?string { return $this->url; } - /** - * @param $value string - * - * @return $this - */ - public function setUrl($value) + public function setUrl(?string $value): LtiDeepLinkResource { $this->url = $value; return $this; } - /** - * @return LtiLineitem - */ - public function getLineitem() + public function getLineItem(): ?LtiLineitem { - return $this->lineitem; + return $this->line_item; } - /** - * @param $value LtiLineitem - * - * @return $this - */ - public function setLineitem(LtiLineitem $value) + public function setLineItem(?LtiLineitem $value): LtiDeepLinkResource { - $this->lineitem = $value; + $this->line_item = $value; return $this; } - /** - * @param $icon LtiDeepLinkResourceIcon - * - * @return $this - */ - public function setIcon(LtiDeepLinkResourceIcon $icon) + public function setIcon(?LtiDeepLinkResourceIcon $icon): LtiDeepLinkResource { $this->icon = $icon; return $this; } - /** - * @return LtiDeepLinkResourceIcon - */ - public function getIcon(): LtiDeepLinkResourceIcon + public function getIcon(): ?LtiDeepLinkResourceIcon { return $this->icon; } - /** - * @param $thumbnail LtiDeepLinkResourceIcon - * - * @return $this - */ - public function setThumbnail(LtiDeepLinkResourceIcon $thumbnail) + public function setThumbnail(?LtiDeepLinkResourceIcon $thumbnail): LtiDeepLinkResource { $this->thumbnail = $thumbnail; return $this; } - /** - * @return LtiDeepLinkResourceIcon - */ - public function getThumbnail(): LtiDeepLinkResourceIcon + public function getThumbnail(): ?LtiDeepLinkResourceIcon { return $this->thumbnail; } - /** - * @return array - */ - public function getCustomParams() + public function getCustomParams(): array { return $this->custom_params; } - /** - * @param $value array - * - * @return $this - */ - public function setCustomParams($value) + public function setCustomParams(array $value): LtiDeepLinkResource { $this->custom_params = $value; return $this; } - /** - * @return string - */ - public function getTarget() + public function getTarget(): string { return $this->target; } - /** - * @param $value string - * - * @return $this - */ - public function setTarget($value) + public function setTarget(string $value): LtiDeepLinkResource { $this->target = $value; return $this; } - /** - * @return array - */ - public function toArray() + public function toArray(): array { $resource = [ 'type' => $this->type, @@ -225,10 +147,10 @@ public function toArray() if (isset($this->thumbnail)) { $resource['thumbnail'] = $this->thumbnail->toArray(); } - if ($this->lineitem !== null) { + if ($this->line_item !== null) { $resource['lineItem'] = [ - 'scoreMaximum' => $this->lineitem->getScoreMaximum(), - 'label' => $this->lineitem->getLabel(), + 'scoreMaximum' => $this->line_item->getScoreMaximum(), + 'label' => $this->line_item->getLabel(), ]; } diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php index 3be2ca79..9f5d8436 100644 --- a/src/LtiDeepLinkResourceIcon.php +++ b/src/LtiDeepLinkResourceIcon.php @@ -8,77 +8,54 @@ class LtiDeepLinkResourceIcon private $width; private $height; - /** - * @return LtiDeepLinkResourceIcon - */ - public static function new() + public function __construct(string $url, ?int $width = null, ?int $height = null) { - return new LtiDeepLinkResourceIcon(); + $this->url = $url; + $this->width = $width; + $this->height = $height; + } + + public static function new(): LtiDeepLinkResourceIcon + { + return new LtiDeepLinkResourceIcon(''); } - /** - * @param $url string - * - * @return $this - */ - public function setUrl($url) + public function setUrl(string $url): LtiDeepLinkResourceIcon { $this->url = $url; return $this; } - /** - * @return string - */ - public function getUrl() + public function getUrl(): string { return $this->url; } - /** - * @param $width int - * - * @return $this - */ - public function setWidth($width) + public function setWidth(?int $width): LtiDeepLinkResourceIcon { $this->width = $width; return $this; } - /** - * @return int - */ - public function getWidth() + public function getWidth(): ?int { return $this->width; } - /** - * @param $height int - * - * @return $this - */ - public function setHeight($height) + public function setHeight(?int $height): LtiDeepLinkResourceIcon { $this->height = $height; return $this; } - /** - * @return int - */ - public function getHeight() + public function getHeight(): ?int { return $this->height; } - /** - * @return array - */ public function toArray(): array { return [ diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index ddf172dd..da7b4778 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -8,7 +8,7 @@ class LtiDeepLinkResourceIconTest extends TestCase { public function setUp(): void { - $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon(); + $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon('https://example.com'); } public function testItInstantiates() @@ -27,7 +27,7 @@ public function testItGetsUrl() { $result = $this->deepLinkResourceIcon->getUrl(); - $this->assertNull($result); + $this->assertEquals('https://example.com', $result); } public function testItSetsUrl() diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index cd5b2126..4440b0c9 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -92,7 +92,7 @@ public function testItSetsUrl() public function testItGetsLineitem() { - $result = $this->deepLinkResource->getLineitem(); + $result = $this->deepLinkResource->getLineItem(); $this->assertNull($result); } @@ -101,9 +101,9 @@ public function testItSetsLineitem() { $expected = Mockery::mock(LtiLineitem::class); - $this->deepLinkResource->setLineitem($expected); + $this->deepLinkResource->setLineItem($expected); - $this->assertEquals($expected, $this->deepLinkResource->getLineitem()); + $this->assertEquals($expected, $this->deepLinkResource->getLineItem()); } public function testItGetsIcon() @@ -147,7 +147,7 @@ public function testItGetsCustomParams() public function testItSetsCustomParams() { - $expected = 'expected'; + $expected = ['a_key' => 'a_value']; $this->deepLinkResource->setCustomParams($expected); @@ -212,7 +212,7 @@ public function testItCastsToArray() $this->deepLinkResource->setUrl($expected['url']); $this->deepLinkResource->setIcon($icon); $this->deepLinkResource->setThumbnail($icon); - $this->deepLinkResource->setLineitem($lineitem); + $this->deepLinkResource->setLineItem($lineitem); $result = $this->deepLinkResource->toArray(); From 738f9d66198debc2512b71a82f3b77fc7ba5f1ae Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Fri, 29 Jul 2022 16:22:05 +0200 Subject: [PATCH 15/16] Added parameters to the static new method --- src/LtiDeepLinkResourceIcon.php | 4 ++-- tests/LtiDeepLinkResourceIconTest.php | 9 +++++---- tests/LtiDeepLinkResourceTest.php | 6 ++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php index 9f5d8436..b907a9c8 100644 --- a/src/LtiDeepLinkResourceIcon.php +++ b/src/LtiDeepLinkResourceIcon.php @@ -15,9 +15,9 @@ public function __construct(string $url, ?int $width = null, ?int $height = null $this->height = $height; } - public static function new(): LtiDeepLinkResourceIcon + public static function new(string $url, ?int $width = null, ?int $height = null): LtiDeepLinkResourceIcon { - return new LtiDeepLinkResourceIcon(''); + return new LtiDeepLinkResourceIcon($url, $width, $height); } public function setUrl(string $url): LtiDeepLinkResourceIcon diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index da7b4778..118a4e45 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -8,7 +8,8 @@ class LtiDeepLinkResourceIconTest extends TestCase { public function setUp(): void { - $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon('https://example.com'); + $this->imageUrl = 'https://example.com/image.png'; + $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon($this->imageUrl); } public function testItInstantiates() @@ -18,7 +19,7 @@ public function testItInstantiates() public function testItCreatesANewInstance() { - $deepLinkResource = LtiDeepLinkResourceIcon::new(); + $deepLinkResource = LtiDeepLinkResourceIcon::new($this->imageUrl); $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $deepLinkResource); } @@ -27,7 +28,7 @@ public function testItGetsUrl() { $result = $this->deepLinkResourceIcon->getUrl(); - $this->assertEquals('https://example.com', $result); + $this->assertEquals($this->imageUrl, $result); } public function testItSetsUrl() @@ -74,7 +75,7 @@ public function testItSetsHeight() public function testItCastsToArray() { $expected = [ - 'url' => 'https://example.com/icon.png', + 'url' => $this->imageUrl, 'width' => 100, 'height' => 200, ]; diff --git a/tests/LtiDeepLinkResourceTest.php b/tests/LtiDeepLinkResourceTest.php index 4440b0c9..d82cc608 100644 --- a/tests/LtiDeepLinkResourceTest.php +++ b/tests/LtiDeepLinkResourceTest.php @@ -11,6 +11,7 @@ class LtiDeepLinkResourceTest extends TestCase { public function setUp(): void { + $this->imageUrl = 'https://example.com/image.png'; $this->deepLinkResource = new LtiDeepLinkResource(); } @@ -172,10 +173,7 @@ public function testItSetsTarget() public function testItCastsToArray() { - $icon = LtiDeepLinkResourceIcon::new() - ->setUrl('a_url') - ->setWidth(100) - ->setHeight(200); + $icon = LtiDeepLinkResourceIcon::new($this->imageUrl, 100, 200); $expected = [ 'type' => 'ltiResourceLink', From 5f7904c8b70564624bf47c0d5665618ea03e2243 Mon Sep 17 00:00:00 2001 From: "j.bebendorf" Date: Mon, 1 Aug 2022 09:35:36 +0200 Subject: [PATCH 16/16] Made width and height required --- src/LtiDeepLinkResourceIcon.php | 12 ++++++------ tests/LtiDeepLinkResourceIconTest.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/LtiDeepLinkResourceIcon.php b/src/LtiDeepLinkResourceIcon.php index b907a9c8..f037910b 100644 --- a/src/LtiDeepLinkResourceIcon.php +++ b/src/LtiDeepLinkResourceIcon.php @@ -8,14 +8,14 @@ class LtiDeepLinkResourceIcon private $width; private $height; - public function __construct(string $url, ?int $width = null, ?int $height = null) + public function __construct(string $url, int $width, int $height) { $this->url = $url; $this->width = $width; $this->height = $height; } - public static function new(string $url, ?int $width = null, ?int $height = null): LtiDeepLinkResourceIcon + public static function new(string $url, int $width, int $height): LtiDeepLinkResourceIcon { return new LtiDeepLinkResourceIcon($url, $width, $height); } @@ -32,26 +32,26 @@ public function getUrl(): string return $this->url; } - public function setWidth(?int $width): LtiDeepLinkResourceIcon + public function setWidth(int $width): LtiDeepLinkResourceIcon { $this->width = $width; return $this; } - public function getWidth(): ?int + public function getWidth(): int { return $this->width; } - public function setHeight(?int $height): LtiDeepLinkResourceIcon + public function setHeight(int $height): LtiDeepLinkResourceIcon { $this->height = $height; return $this; } - public function getHeight(): ?int + public function getHeight(): int { return $this->height; } diff --git a/tests/LtiDeepLinkResourceIconTest.php b/tests/LtiDeepLinkResourceIconTest.php index 118a4e45..a538968b 100644 --- a/tests/LtiDeepLinkResourceIconTest.php +++ b/tests/LtiDeepLinkResourceIconTest.php @@ -9,7 +9,7 @@ class LtiDeepLinkResourceIconTest extends TestCase public function setUp(): void { $this->imageUrl = 'https://example.com/image.png'; - $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon($this->imageUrl); + $this->deepLinkResourceIcon = new LtiDeepLinkResourceIcon($this->imageUrl, 1, 2); } public function testItInstantiates() @@ -19,7 +19,7 @@ public function testItInstantiates() public function testItCreatesANewInstance() { - $deepLinkResource = LtiDeepLinkResourceIcon::new($this->imageUrl); + $deepLinkResource = LtiDeepLinkResourceIcon::new($this->imageUrl, 100, 200); $this->assertInstanceOf(LtiDeepLinkResourceIcon::class, $deepLinkResource); } @@ -44,7 +44,7 @@ public function testItGetsWidth() { $result = $this->deepLinkResourceIcon->getWidth(); - $this->assertNull($result); + $this->assertEquals(1, $result); } public function testItSetsWidth() @@ -60,7 +60,7 @@ public function testItGetsHeight() { $result = $this->deepLinkResourceIcon->getHeight(); - $this->assertNull($result); + $this->assertEquals(2, $result); } public function testItSetsHeight()