Skip to content

Commit

Permalink
Merge pull request #21 from aon4o/master
Browse files Browse the repository at this point in the history
Laravel 10 & 11 support + PHPUnit 11 migration.
  • Loading branch information
Funfare committed Apr 15, 2024
2 parents e498994 + dcb5367 commit 75a07a9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/vendor
/build
/.idea
.phpunit.cache
.phpunit.result.cache
composer.phar
composer.lock
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"require": {
"php": "^7.2.0|^8.0",
"guzzlehttp/guzzle": "^6.3|^7.0",
"illuminate/notifications": "^5.6|^6.0|^7.0|^8.0|^9.0",
"illuminate/queue": "^5.6|^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0"
"illuminate/notifications": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/queue": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0|^9.0"
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": {
Expand Down
49 changes: 26 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="RocketChat Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="RocketChat Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
72 changes: 24 additions & 48 deletions tests/RocketChatAttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,52 @@

final class RocketChatAttachmentTest extends TestCase
{
/** @test */
public function it_can_accept_a_config_when_constructing_an_attachment(): void
public function test_it_can_accept_a_config_when_constructing_an_attachment(): void
{
$attachment = new RocketChatAttachment(['title' => 'test123']);

$this->assertEquals(['title' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_accept_a_config_when_creating_an_attachment(): void
public function test_it_can_accept_a_config_when_creating_an_attachment(): void
{
$attachment = RocketChatAttachment::create(['title' => 'test123']);

$this->assertEquals(['title' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_returns_an_empty_array_if_not_configured(): void
public function test_it_returns_an_empty_array_if_not_configured(): void
{
$attachment = new RocketChatAttachment();

$this->assertEquals([], $attachment->toArray());
}

/** @test */
public function it_can_set_the_color(): void
public function test_it_can_set_the_color(): void
{
$attachment = new RocketChatAttachment();
$attachment->color('#FFFFFF');

$this->assertEquals(['color' => '#FFFFFF'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_text(): void
public function test_it_can_set_the_text(): void
{
$attachment = new RocketChatAttachment();
$attachment->text('test123');

$this->assertEquals(['text' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_timestamp(): void
public function test_it_can_set_the_timestamp(): void
{
$attachment = new RocketChatAttachment();
$attachment->timestamp('2020-02-19T19:00:00.000Z');

$this->assertEquals(['ts' => '2020-02-19T19:00:00.000Z'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_timestamp_as_datetime(): void
public function test_it_can_set_the_timestamp_as_datetime(): void
{
$date = DateTime::createFromFormat('Y-m-d H:i:s.u', '2020-02-19 19:00:00.000');
$attachment = new RocketChatAttachment();
Expand All @@ -74,8 +67,7 @@ public function it_can_set_the_timestamp_as_datetime(): void
$this->assertEquals(['ts' => $date->format(DateTimeInterface::ATOM)], $attachment->toArray());
}

/** @test */
public function it_can_set_the_timestamp_as_immutable_datetime(): void
public function test_it_can_set_the_timestamp_as_immutable_datetime(): void
{
$date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', '2020-02-19 19:00:00.000');
$attachment = new RocketChatAttachment();
Expand All @@ -84,8 +76,7 @@ public function it_can_set_the_timestamp_as_immutable_datetime(): void
$this->assertSame(['ts' => $date->format(DateTimeInterface::ATOM)], $attachment->toArray());
}

/** @test */
public function it_cannot_set_the_timestamp_as_integer(): void
public function test_it_cannot_set_the_timestamp_as_integer(): void
{
$this->expectException(InvalidArgumentException::class);

Expand All @@ -94,62 +85,55 @@ public function it_cannot_set_the_timestamp_as_integer(): void
$attachment->timestamp($date);
}

/** @test */
public function it_can_set_the_thumb_url(): void
public function test_it_can_set_the_thumb_url(): void
{
$attachment = new RocketChatAttachment();
$attachment->thumbnailUrl('test123');

$this->assertEquals(['thumb_url' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_message_link(): void
public function test_it_can_set_the_message_link(): void
{
$attachment = new RocketChatAttachment();
$attachment->messageLink('test123');

$this->assertEquals(['message_link' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_collapsed(): void
public function test_it_can_set_the_collapsed(): void
{
$attachment = new RocketChatAttachment();
$attachment->collapsed(true);

$this->assertEquals(['collapsed' => true], $attachment->toArray());
}

/** @test */
public function it_can_set_the_author_name(): void
public function test_it_can_set_the_author_name(): void
{
$attachment = new RocketChatAttachment();
$attachment->authorName('author');

$this->assertEquals(['author_name' => 'author'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_author_link(): void
public function test_it_can_set_the_author_link(): void
{
$attachment = new RocketChatAttachment();
$attachment->authorLink('test123');

$this->assertEquals(['author_link' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_author_icon(): void
public function test_it_can_set_the_author_icon(): void
{
$attachment = new RocketChatAttachment();
$attachment->authorIcon('test123');

$this->assertEquals(['author_icon' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_author(): void
public function test_it_can_set_the_author(): void
{
$attachment = new RocketChatAttachment();
$attachment->author('aname', 'alink', 'aicon');
Expand All @@ -161,62 +145,55 @@ public function it_can_set_the_author(): void
], $attachment->toArray());
}

/** @test */
public function it_can_set_the_title(): void
public function test_it_can_set_the_title(): void
{
$attachment = new RocketChatAttachment();
$attachment->title('test123');

$this->assertEquals(['title' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_title_link(): void
public function test_it_can_set_the_title_link(): void
{
$attachment = new RocketChatAttachment();
$attachment->titleLink('test123');

$this->assertEquals(['title_link' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_title_link_download(): void
public function test_it_can_set_the_title_link_download(): void
{
$attachment = new RocketChatAttachment();
$attachment->titleLinkDownload(true);

$this->assertEquals(['title_link_download' => true], $attachment->toArray());
}

/** @test */
public function it_can_set_the_image_url(): void
public function test_it_can_set_the_image_url(): void
{
$attachment = new RocketChatAttachment();
$attachment->imageUrl('test123');

$this->assertEquals(['image_url' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_audio_url(): void
public function test_it_can_set_the_audio_url(): void
{
$attachment = new RocketChatAttachment();
$attachment->audioUrl('test123');

$this->assertEquals(['audio_url' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_video_url(): void
public function test_it_can_set_the_video_url(): void
{
$attachment = new RocketChatAttachment();
$attachment->videoUrl('test123');

$this->assertEquals(['video_url' => 'test123'], $attachment->toArray());
}

/** @test */
public function it_can_set_the_fields(): void
public function test_it_can_set_the_fields(): void
{
$fields = [
[
Expand All @@ -236,8 +213,7 @@ public function it_can_set_the_fields(): void
$this->assertEquals(['fields' => $fields], $attachment->toArray());
}

/** @test */
public function it_cannot_set_unknown_field(): void
public function test_it_cannot_set_unknown_field(): void
{
$attachment = new RocketChatAttachment(['notExisting']);
$this->assertEquals([], $attachment->toArray());
Expand Down
Loading

0 comments on commit 75a07a9

Please sign in to comment.