Skip to content

Commit f5f45aa

Browse files
committed
Add a component factory
1 parent 6e0dd31 commit f5f45aa

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

src/Component.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace NotificationChannels\WhatsApp;
4+
5+
class Component
6+
{
7+
/**
8+
* Currency code as defined in ISO 4217.
9+
*/
10+
public static function currency(float $amount, string $code = 'EUR'): Component\Currency
11+
{
12+
return new Component\Currency($amount, $code);
13+
}
14+
15+
public static function dateTime(\DateTimeImmutable $dateTime, string $format = 'Y-m-d H:i:s'): Component\DateTime
16+
{
17+
return new Component\DateTime($dateTime, $format);
18+
}
19+
20+
public static function document(string $link): Component\Document
21+
{
22+
return new Component\Document($link);
23+
}
24+
25+
public static function image(string $link): Component\Image
26+
{
27+
return new Component\Image($link);
28+
}
29+
30+
public static function text(string $text): Component\Text
31+
{
32+
return new Component\Text($text);
33+
}
34+
35+
public static function video(string $link): Component\Video
36+
{
37+
return new Component\Video($link);
38+
}
39+
}

tests/ComponentTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace NotificationChannels\WhatsApp\Test;
4+
5+
use NotificationChannels\WhatsApp\Component;
6+
use PHPUnit\Framework\TestCase;
7+
8+
final class ComponentTest extends TestCase
9+
{
10+
/** @test */
11+
public function it_can_return_a_currency_component()
12+
{
13+
$component = Component::currency(10, 'EUR');
14+
15+
$this->assertInstanceOf(Component\Currency::class, $component);
16+
}
17+
18+
/** @test */
19+
public function it_can_return_a_datetime_component()
20+
{
21+
$component = Component::dateTime(new \DateTimeImmutable());
22+
23+
$this->assertInstanceOf(Component\DateTime::class, $component);
24+
}
25+
26+
/** @test */
27+
public function it_can_return_a_document_component()
28+
{
29+
$component = Component::document('https://www.netflie.es/my_document.pdf');
30+
31+
$this->assertInstanceOf(Component\Document::class, $component);
32+
}
33+
34+
/** @test */
35+
public function it_can_return_an_image_component()
36+
{
37+
$component = Component::image('https://www.netflie.es/my_image.png');
38+
39+
$this->assertInstanceOf(Component\Image::class, $component);
40+
}
41+
42+
/** @test */
43+
public function it_can_return_a_text_component()
44+
{
45+
$component = Component::text('Hey there!');
46+
47+
$this->assertInstanceOf(Component\Text::class, $component);
48+
}
49+
50+
/** @test */
51+
public function it_can_return_a_vide_component()
52+
{
53+
$component = Component::video('https://www.netflie.es/my_image.webm');
54+
55+
$this->assertInstanceOf(Component\Video::class, $component);
56+
}
57+
}

0 commit comments

Comments
 (0)