From cd23d840aa4eff244659ffca72314c4aeff70c99 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 4 Mar 2020 22:46:00 +0000 Subject: [PATCH 01/45] Remove that newline. --- tests/QueuedWebhookFunctionTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/QueuedWebhookFunctionTest.php b/tests/QueuedWebhookFunctionTest.php index 406cf4a..e838fe1 100644 --- a/tests/QueuedWebhookFunctionTest.php +++ b/tests/QueuedWebhookFunctionTest.php @@ -7,7 +7,6 @@ class QueuedWebhookFunctionTest extends TestCase { protected $webhook; - public function setUp(): void{ $this->webhook = new QueuedWebhook($_SERVER['WEBHOOK_URL']); } From ea50c9f4f2602a50e5ccf37dcb47d2ef45da3f17 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 4 Mar 2020 23:04:23 +0000 Subject: [PATCH 02/45] Merged all the stuff together and added an empty send to error. --- tests/WebhookTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 4be3ec1..22a83a0 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -4,10 +4,16 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\Webhook; +use GuzzleHttp\Exception\RequestException; -final class WebhookSetupTest extends TestCase { +class WebhookTest extends TestCase { + protected $webhook; + protected $url; + protected $id; + protected $token; protected function setUp(): void{ parent::setUp(); + $this->webhook = new Webhook($_SERVER['WEBHOOK_URL']); ['WEBHOOK_URL' => $this->url, 'WEBHOOK_ID' => $this->id, 'WEBHOOK_TOKEN' => $this->token] = $_SERVER; } @@ -25,4 +31,9 @@ public function testCreationFromReverseTokenPair(): void { $this->expectException(InvalidArgumentException::class); $webhook = new Webhook($this->token, $this->id); } + + public function testEmptyException(): void { + $this->expectException(RequestException::class); + $this->webhook->execute(''); + } } \ No newline at end of file From d4fe1963de644cfd3ba56815a60aea20f51950e7 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 4 Mar 2020 23:25:12 +0000 Subject: [PATCH 03/45] Try it this way? --- tests/WebhookTest.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 22a83a0..46ef980 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\Webhook; +use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\RequestException; class WebhookTest extends TestCase { @@ -33,7 +34,11 @@ public function testCreationFromReverseTokenPair(): void { } public function testEmptyException(): void { - $this->expectException(RequestException::class); - $this->webhook->execute(''); + try { + $this->webhook->execute(''); + $this->fail('Executed successfully'); + } catch (Exception $ex){ + $this->assertInstanceOf(ClientException::class, $ex); + } } } \ No newline at end of file From 0e4a8d30604c1e88a8346fb2510f9ed9f8d2997e Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 5 Mar 2020 10:17:17 +0000 Subject: [PATCH 04/45] Move that over to a queued webhook. --- tests/WebhookTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 46ef980..ad2a7dd 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\Webhook; +use Internet\InterCord\QueuedWebhook; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\RequestException; @@ -14,7 +15,7 @@ class WebhookTest extends TestCase { protected $token; protected function setUp(): void{ parent::setUp(); - $this->webhook = new Webhook($_SERVER['WEBHOOK_URL']); + $this->webhook = new QueuedWebhook($_SERVER['WEBHOOK_URL']); ['WEBHOOK_URL' => $this->url, 'WEBHOOK_ID' => $this->id, 'WEBHOOK_TOKEN' => $this->token] = $_SERVER; } @@ -34,11 +35,7 @@ public function testCreationFromReverseTokenPair(): void { } public function testEmptyException(): void { - try { - $this->webhook->execute(''); - $this->fail('Executed successfully'); - } catch (Exception $ex){ - $this->assertInstanceOf(ClientException::class, $ex); - } + $this->expectException(ClientException::class); + $this->webhook->execute(''); } -} \ No newline at end of file +} From accc9fdedc2091e41c7c43cd96a942dfad76a731 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 10:26:59 +0000 Subject: [PATCH 05/45] That becomes just queued webhook test, since we're testing all aspects of the queued webhook. --- .../{QueuedWebhookFunctionTest.php => QueuedWebhookTest.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{QueuedWebhookFunctionTest.php => QueuedWebhookTest.php} (94%) diff --git a/tests/QueuedWebhookFunctionTest.php b/tests/QueuedWebhookTest.php similarity index 94% rename from tests/QueuedWebhookFunctionTest.php rename to tests/QueuedWebhookTest.php index e838fe1..387a85b 100644 --- a/tests/QueuedWebhookFunctionTest.php +++ b/tests/QueuedWebhookTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\QueuedWebhook; -class QueuedWebhookFunctionTest extends TestCase { +class QueuedWebhookTest extends TestCase { protected $webhook; public function setUp(): void{ $this->webhook = new QueuedWebhook($_SERVER['WEBHOOK_URL']); @@ -31,4 +31,4 @@ public function testExecution(){ $this->webhook->run(); $this->addToAssertionCount(1); } -} \ No newline at end of file +} From 634928cda8aaf2f416d68908880d62c4b534c603 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:16:05 +0000 Subject: [PATCH 06/45] Add scripts from interdb, increase range on phpunit bounds. --- composer.json | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 74582c1..f6622e2 100644 --- a/composer.json +++ b/composer.json @@ -10,17 +10,27 @@ "email": "jonjon1234.github@gmail.com", "role": "Developer" }], - "autoload": { - "psr-4": { - "Internet\\InterCord\\": "src/" - } + + "scripts": { + "test": "phpunit --debug -vvv --bootstrap vendor/autoload.php --colors=never --whitelist src/ --coverage-html coverage --testdox-html test.html tests", + "pcov-polyfill": [ + "@composer require --dev pcov/clobber", + "pcov clobber" + ] }, + "require": { "php": ">=7.2", "ext-json": "*", "guzzlehttp/guzzle": "^6.4" - }, + }, + "autoload": { + "psr-4": { + "Internet\\InterCord\\": "src/" + } + }, + "require-dev": { - "phpunit/phpunit": "^9" + "phpunit/phpunit": ">=7 <10" } } From d1a4fe0c4aa85f0e5ac2679f4504966dd53a1a8a Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:22:18 +0000 Subject: [PATCH 07/45] Remove old tests, grab new tests based on InterDB's workflow. --- .github/workflows/phpunit.yml | 107 ---------------------------------- .github/workflows/tests.yml | 63 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 107 deletions(-) delete mode 100644 .github/workflows/phpunit.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index bc83b6d..0000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: PHPUnit Tests -on: push - -env: - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - WEBHOOK_ID: ${{ secrets.WEBHOOK_ID }} - WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }} - -jobs: - test7: - name: PHP ${{ matrix.version }} on ${{ matrix.os }} with PHPUnit 7 - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - version: [7.2, 7.3] -# os: [ubuntu-latest, windows-latest] - os: [ubuntu-latest] - - steps: - - name: Checkout - uses: actions/checkout@master - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.version }} - extensions: mbstring, intl - coverage: pocv - tools: composer -# ini-values: memory_limit=4096M - - name: Setup PHPUnit Matcher - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Install PHPUnit - run: composer global require --no-ansi phpunit/phpunit:7 - - name: Add Composer Binary to Path - run: echo "::add-path::$(composer global config bin-dir --absolute)" - - name: Install Composer Dependencies - run: composer install --no-ansi --no-dev -oa - - name: Run Tests (Unix) - if: matrix.os == 'ubuntu-latest' - run: phpunit --debug -vvv --bootstrap vendor/autoload.php --coverage-text --coverage-html coverage --testdox-html test.html --colors=never --whitelist src/ tests - continue-on-error: true - - name: Run Tests (Win) - if: matrix.os == 'windows-latest' - run: phpunit --debug -vvv --bootstrap vendor/autoload.php --coverage-text --coverage-html coverage --testdox-html test.html --colors=never --whitelist src/ tests - continue-on-error: true - - name: Upload Coverage - uses: actions/upload-artifact@v1 - with: - name: Coverage Report - path: coverage/ - - name: Upload Test Report - uses: actions/upload-artifact@v1 - with: - name: Test Report - path: test.html - - - test: - name: PHP ${{ matrix.version }} on ${{ matrix.os }} with PHPUnit 9 - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - version: [7.3, 7.4] -# os: [ubuntu-latest, windows-latest] - os: [ubuntu-latest] - - steps: - - name: Checkout - uses: actions/checkout@master - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.version }} - extensions: mbstring, intl - coverage: pocv - tools: composer -# ini-values: memory_limit=4096M - - name: Setup PHPUnit Matcher - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Install PHPUnit - run: composer global require --no-ansi phpunit/phpunit:9 - - name: Add Composer Binary to Path - run: echo "::add-path::$(composer global config bin-dir --absolute)" - - name: Install Composer Dependencies - run: composer install --no-ansi --no-dev -oa - - name: Run Tests (Unix) - if: matrix.os == 'ubuntu-latest' - run: phpunit --debug -vvv --bootstrap vendor/autoload.php --coverage-text --coverage-html coverage --testdox-html test.html --colors=never --whitelist src/ tests - continue-on-error: true - - name: Run Tests (Win) - if: matrix.os == 'windows-latest' - run: phpunit --debug -vvv --bootstrap vendor/autoload.php --coverage-text --coverage-html coverage --testdox-html test.html --colors=never --whitelist src/ tests - continue-on-error: true - - name: Upload Coverage - uses: actions/upload-artifact@v1 - with: - name: Coverage Report - path: coverage/ - - name: Upload Test Report - uses: actions/upload-artifact@v1 - with: - name: Test Report - path: test.html diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5903d91 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,63 @@ +name: Unit Testing +on: push + +env: + COMPOSER_ALLOW_SUPERUSER: 1 + +jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [7.1, 7.2, 7.3, 7.4] + container: php:${{ matrix.php }}-alpine + steps: + - name: Install php.ini + run: mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + - name: Install APK Dependencies + run: apk update && apk add --no-cache -q git unzip mysql-client autoconf gcc g++ make perl + - name: Install PECL Extensions + run: pear config-set php_ini "$PHP_INI_DIR/php.ini" && pecl install pcov && docker-php-ext-enable pcov + - name: Install Composer + id: composer-install + run: | + wget -O installer https://getcomposer.org/installer + php installer --install-dir=/usr/local/bin --filename=composer + echo "::set-output name=cache-dir::$(composer global config cache-files-dir)" + - name: Checkout + uses: actions/checkout@v1 + - name: Restore Composer Cache + uses: actions/cache@v1 + with: + key: composer-${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + path: ${{ steps.composer-install.outputs.cache-dir }} + restore-keys: composer-${{ runner.os }}- composer-- + - name: Install Dependencies & Update PHPUnit + run: composer update --no-ansi --with-dependencies phpunit/phpunit + - name: Check PHPUnit Version + id: phpunit-check + run: | + info=$(composer show phpunit/phpunit) + version=$(echo "$info" | perl -ne 'print "$&\n" if /(?<=versions : \* )[\d\w.-_]+/s') + major=$(echo "$version" | perl -ne 'print "$&\n" if /\d/s') + echo "::set-output name=major::$major" + - name: Install Legacy POCV Polyfill + run: composer pcov-polyfill + if: steps.phpunit-check.outputs.major < 8 + - name: Run Tests + run: composer test + env: + WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} + WEBHOOK_ID: ${{ secrets.WEBHOOK_ID }} + WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }} + - name: Upload Coverage + uses: actions/upload-artifact@v1 + with: + name: Coverage Report (${{ matrix.php }}) + path: coverage/ + - name: Upload Test Report + uses: actions/upload-artifact@v1 + with: + name: Test Report (${{ matrix.php }}) + path: test.html From 14e9b3c4037ab1afb78b40160607d1827e52544c Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:26:30 +0000 Subject: [PATCH 08/45] Push our version to 7.2 minimum, since we fail below that. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5903d91..3d84f29 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.1, 7.2, 7.3, 7.4] + php: [7.2, 7.3, 7.4] container: php:${{ matrix.php }}-alpine steps: - name: Install php.ini From 2416b3b13d658cc0107b22eb7399f2bd0d0ad85d Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:29:18 +0000 Subject: [PATCH 09/45] Empty messages should rethrow. --- tests/QueuedWebhookTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/QueuedWebhookTest.php b/tests/QueuedWebhookTest.php index 387a85b..c01beb4 100644 --- a/tests/QueuedWebhookTest.php +++ b/tests/QueuedWebhookTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\QueuedWebhook; +use const GuzzleHttp\Exception\ClientException; class QueuedWebhookTest extends TestCase { protected $webhook; @@ -31,4 +32,10 @@ public function testExecution(){ $this->webhook->run(); $this->addToAssertionCount(1); } + + public function testEmptyMessageException(){ + $this->expectException(ClientException::class); + $this->webhook->prepend(''); + $this->webhook->run(1); + } } From 2dbac4c82d3d2a75810477022e98e207d83ad64f Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:32:18 +0000 Subject: [PATCH 10/45] We need to import our class, not a const. --- tests/QueuedWebhookTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/QueuedWebhookTest.php b/tests/QueuedWebhookTest.php index c01beb4..35a20c9 100644 --- a/tests/QueuedWebhookTest.php +++ b/tests/QueuedWebhookTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\QueuedWebhook; -use const GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Exception\ClientException; class QueuedWebhookTest extends TestCase { protected $webhook; From 648567e6528c19569421dcc2ea4bc3d73e66bc87 Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:50:08 +0000 Subject: [PATCH 11/45] Removed deliver method, since we now have the queued endpoint. --- src/Webhook.php | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/Webhook.php b/src/Webhook.php index 409e157..31e7a48 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -102,36 +102,4 @@ public function execute($content, string $username = '', string $avatar = '', bo return json_decode($response->getBody()->getContents()); } } - - public function deliver(Payload $payload){ - $delivered = false; - while (!$delivered){ - try { - $response = $this->post('', [ - 'body' => json_encode($payload), - 'query' => ['wait' => true] - ]); - $left = min(array_map('intval', $response->getHeader('X-RateLimit-Remaining'))); - if ($left == 0){ - $time = max(array_map('intval', $response->getHeader('X-RateLimit-Reset-After'))); - sleep($time); - } - $delivered = true; - } catch (ClientException $client_exception){ - $code = $client_exception->getCode(); - if ($code == 429){ - $response = $client_exception->getResponse(); - $left = min(array_map('intval', $response->getHeader('X-RateLimit-Remaining'))); - if ($left == 0){ - $time = max(array_map('intval', $response->getHeader('X-RateLimit-Reset-After'))); - sleep($time); - } - } elseif ($code == 502){ - sleep(2); - } else { - throw $client_exception; - } - } - } - } } From d3492fc06796622e1fe5099f01e152f71fcf0f6a Mon Sep 17 00:00:00 2001 From: John Internet Date: Wed, 11 Mar 2020 23:58:08 +0000 Subject: [PATCH 12/45] Add tests for sending / throwing while awaiting. --- tests/WebhookTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index ad2a7dd..047c1b2 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -38,4 +38,14 @@ public function testEmptyException(): void { $this->expectException(ClientException::class); $this->webhook->execute(''); } + + public function testEmptyAwaitingException(): void { + $this->expectException(Exception::class); + $this->webhook->execute('', 'test', '', true); + } + + public function testAwaitingSend(): void { + $data = $this->webhook->execute('this is a string', 'test', '', true); + $this->assertIsArray($data); + } } From c46b1aac400894c9e5c0bb0c4bf160656f1b8f43 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 00:22:35 +0000 Subject: [PATCH 13/45] Retry and catch rate limiting. --- tests/WebhookTest.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 047c1b2..c74c94e 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -45,7 +45,22 @@ public function testEmptyAwaitingException(): void { } public function testAwaitingSend(): void { - $data = $this->webhook->execute('this is a string', 'test', '', true); - $this->assertIsArray($data); + $ran = false; + while (!$ran){ + try { + $data = $this->webhook->execute('this is a string', 'test', '', true); + $ran = true; + $this->assertIsArray($data); + } catch (ClientException $ex){ + if ($ex->getCode() == 429){ + $err = json_decode($ex->getResponse()->getBody()->getContents()); + usleep($err->retry_after * 2); + } else { + throw $ex; + } + } + } + + } } From 9644d9187d9254f9f018728da8671be83034c2c4 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 00:25:04 +0000 Subject: [PATCH 14/45] that returns a stdobj, not an array. --- tests/WebhookTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index c74c94e..ffc34a7 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -50,7 +50,7 @@ public function testAwaitingSend(): void { try { $data = $this->webhook->execute('this is a string', 'test', '', true); $ran = true; - $this->assertIsArray($data); + $this->assertIsObject($data); } catch (ClientException $ex){ if ($ex->getCode() == 429){ $err = json_decode($ex->getResponse()->getBody()->getContents()); From bc867fcb451fcdb85f2cf1cf2cef3cb2ebce24b7 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 00:26:26 +0000 Subject: [PATCH 15/45] Continue for uploads even if the test fails. --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3d84f29..1313867 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,6 +47,7 @@ jobs: if: steps.phpunit-check.outputs.major < 8 - name: Run Tests run: composer test + continue-on-error: true env: WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} WEBHOOK_ID: ${{ secrets.WEBHOOK_ID }} From 964c4b877a9f259b06382b61c3358e8a3ecc670a Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 00:57:23 +0000 Subject: [PATCH 16/45] That will throw before. --- src/Webhook.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Webhook.php b/src/Webhook.php index 31e7a48..061e594 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -93,11 +93,7 @@ public function execute($content, string $username = '', string $avatar = '', bo } if (!$await){ - if ($response->getStatusCode() == 204){ - return null; - } else { - throw new Exception("Message failed to send."); - } + return null; } else { return json_decode($response->getBody()->getContents()); } From 6752b97e219fd1d519797209c9dc396fff014fc1 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:18:23 +0000 Subject: [PATCH 17/45] I forgot to bit-shift. --- src/Internal/Color.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Internal/Color.php b/src/Internal/Color.php index 64144f5..9ede02d 100644 --- a/src/Internal/Color.php +++ b/src/Internal/Color.php @@ -51,7 +51,7 @@ public static function fromHex(string $code): Color{ * @return Color */ public static function fromDecimal(int $number): Color{ - return new static($number & 0xFF0000, $number & 0x00FF00, $number & 0x0000FF); + return new static(($number & 0xFF0000) >> 16, ($number & 0x00FF00) >> 8, $number & 0x0000FF); } /** From 75312b433d3a3db3ebf17f49229b0bc7103d2bfc Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:34:06 +0000 Subject: [PATCH 18/45] Add testing for embeds. --- tests/EmbedTest.php | 99 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/EmbedTest.php diff --git a/tests/EmbedTest.php b/tests/EmbedTest.php new file mode 100644 index 0000000..66127b4 --- /dev/null +++ b/tests/EmbedTest.php @@ -0,0 +1,99 @@ +setColor($color); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('color', $data); + $this->assertEquals($expected, $data['color']); + } + + /** + * @dataProvider @emptyColors + * @param int|string|Color $color + */ + public function testEmptyColoursAreEmpty($color){ + $embed = new RichEmbed(); + $embed->setColor($color); + + $data = $embed->jsonSerialize(); + $this->assertArrayNotHasKey('color', $data); + } + + /** + * @dataProvider @badColors + * @param int|string|Color $color + */ + public function testBadColoursThrowExceptions($color){ + $this->expectException(Exception::class); // TODO: Change this to a proper exception class. + $embed = new RichEmbed(); + $embed->setColor($color); + } +} From 7c4ef4a40af92d1c47055fd68c2acf06160d1f53 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:35:00 +0000 Subject: [PATCH 19/45] We test colours, not embeds here. --- tests/{EmbedTest.php => ColorTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{EmbedTest.php => ColorTest.php} (98%) diff --git a/tests/EmbedTest.php b/tests/ColorTest.php similarity index 98% rename from tests/EmbedTest.php rename to tests/ColorTest.php index 66127b4..144d4e9 100644 --- a/tests/EmbedTest.php +++ b/tests/ColorTest.php @@ -7,7 +7,7 @@ use Internet\InterCord\RichEmbed; use Internet\InterCord\Internal\Color; -class EmbedTest extends TestCase { +class ColorTest extends TestCase { /** Data provider for colours, and their corresponding decimal colour. * @return array */ From 4062f3bde8a5f1d8da15df6e1b8ab3563ed090d6 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:43:41 +0000 Subject: [PATCH 20/45] add clover-style coverage report. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6622e2..e5de4a7 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }], "scripts": { - "test": "phpunit --debug -vvv --bootstrap vendor/autoload.php --colors=never --whitelist src/ --coverage-html coverage --testdox-html test.html tests", + "test": "phpunit --debug -vvv --bootstrap vendor/autoload.php --colors=never --whitelist src/ --coverage-html coverage --testdox-html test.html --coverage-clover=coverage.xml tests", "pcov-polyfill": [ "@composer require --dev pcov/clobber", "pcov clobber" From cedbc59d49d4c01a203bd8fa3944d9e8b85b8208 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:44:29 +0000 Subject: [PATCH 21/45] Upload coverage reports. --- .github/workflows/tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1313867..40fba11 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,7 @@ jobs: - name: Install php.ini run: mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" - name: Install APK Dependencies - run: apk update && apk add --no-cache -q git unzip mysql-client autoconf gcc g++ make perl + run: apk update && apk add --no-cache -q git unzip mysql-client autoconf gcc g++ make perl bash - name: Install PECL Extensions run: pear config-set php_ini "$PHP_INI_DIR/php.ini" && pecl install pcov && docker-php-ext-enable pcov - name: Install Composer @@ -62,3 +62,7 @@ jobs: with: name: Test Report (${{ matrix.php }}) path: test.html + - name: Upload CodeCov Report + run: bash <(curl -s https://codecov.io/bash) + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 5026b9fd748ce339f6a4cf1130212a2498f70fb1 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:47:23 +0000 Subject: [PATCH 22/45] ok. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 40fba11..c2854d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -63,6 +63,6 @@ jobs: name: Test Report (${{ matrix.php }}) path: test.html - name: Upload CodeCov Report - run: bash <(curl -s https://codecov.io/bash) + run: wget -o uploader https://codecov.io/bash && bash uploader env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 2a5be98965a3c66f30dfaab7333feed21ae94f93 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 01:51:19 +0000 Subject: [PATCH 23/45] try that and pipe it to bash --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c2854d8..1a92da1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -63,6 +63,6 @@ jobs: name: Test Report (${{ matrix.php }}) path: test.html - name: Upload CodeCov Report - run: wget -o uploader https://codecov.io/bash && bash uploader + run: wget -qO- https://codecov.io/bash | bash env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 78be67e1a33f22943258c5b7af08c73a7fe45970 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 02:09:17 +0000 Subject: [PATCH 24/45] Add tests for handling embed times. --- tests/EmbedTimeTest.php | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/EmbedTimeTest.php diff --git a/tests/EmbedTimeTest.php b/tests/EmbedTimeTest.php new file mode 100644 index 0000000..a5c4d07 --- /dev/null +++ b/tests/EmbedTimeTest.php @@ -0,0 +1,68 @@ +setTimestamp($stamp); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('timestamp', $data); + $this->assertEquals($expected, $data['timestamp']); + } + + public function datetimes(){ + return [ + [DateTime::createFromFormat('U', 0), '1970-01-01T00:00:00+0000'], + [DateTime::createFromFormat('U', 1), '1970-01-01T00:00:01+0000'], + [DateTime::createFromFormat('U', 86400), '1970-01-02T00:00:00+0000'], + ]; + } + + /** + * @dataProvider datetimes + */ + public function testDateTimeObject($time, $expected){ + $embed = new RichEmbed(); + $embed->setTimestamp($time); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('timestamp', $data); + $this->assertEquals($expected, $data['timestamp']); + } + + public function formatpairs(){ + return [ + ['0', 'U', '1970-01-01T00:00:00+0000'], + ['15-Feb-2009', 'j-M-Y', '2009-02-15T00:00:00+0000'] + ]; + } + + /** + * @dataProvider formatpairs + */ + public function testTimeFromFormat($time, $format, $expected){ + $embed = new RichEmbed(); + $embed->setTimestamp($time, $format); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('timestamp', $data); + $this->assertEquals($expected, $data['timestamp']); + } +} From a886c10dcffed9570903b4a601824d5daabc760d Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 02:09:34 +0000 Subject: [PATCH 25/45] Add tests for titles, descriptions and urls. --- tests/EmbedElementsTest.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/EmbedElementsTest.php diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php new file mode 100644 index 0000000..42f75b0 --- /dev/null +++ b/tests/EmbedElementsTest.php @@ -0,0 +1,36 @@ +setTitle('hello'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('title', $data); + $this->assertEquals('hello', $data['title']); + } + + public function testDescription(){ + $embed = new RichEmbed(); + $embed->setDescription('hello'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('description', $data); + $this->assertEquals('hello', $data['description']); + } + + public function testURL(){ + $embed = new RichEmbed(); + $embed->setURL('hello'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('url', $data); + $this->assertEquals('hello', $data['url']); + } +} From 845adee147dfcca5b2a1d5abf3b07360b5065a3c Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 02:11:34 +0000 Subject: [PATCH 26/45] Added badges for unit test pipeline and code coverage. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4d639fe..a69a740 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +![Unit Testing](https://github.com/JoshPiper/PHP-InterCord/workflows/Unit%20Testing/badge.svg) +[![codecov](https://codecov.io/gh/JoshPiper/PHP-InterCord/branch/master/graph/badge.svg)](https://codecov.io/gh/JoshPiper/PHP-InterCord) + ## InterCord InterCord is a simple PHP Discord Webhooks & Rich Embed library. From 77087fa3c14c587ba1c3e835e2b583681ca07f84 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 02:13:59 +0000 Subject: [PATCH 27/45] Fix colourtest's data providers. --- tests/ColorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ColorTest.php b/tests/ColorTest.php index 144d4e9..3f2f1ae 100644 --- a/tests/ColorTest.php +++ b/tests/ColorTest.php @@ -76,7 +76,7 @@ public function testColorsWork($color, $expected){ } /** - * @dataProvider @emptyColors + * @dataProvider emptyColors * @param int|string|Color $color */ public function testEmptyColoursAreEmpty($color){ @@ -88,7 +88,7 @@ public function testEmptyColoursAreEmpty($color){ } /** - * @dataProvider @badColors + * @dataProvider badColors * @param int|string|Color $color */ public function testBadColoursThrowExceptions($color){ From b3c94b8bb2ccb772f569915b86aebc9ca314cf73 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 02:14:26 +0000 Subject: [PATCH 28/45] why do i turn strict types on? --- tests/EmbedTimeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/EmbedTimeTest.php b/tests/EmbedTimeTest.php index a5c4d07..c6514ed 100644 --- a/tests/EmbedTimeTest.php +++ b/tests/EmbedTimeTest.php @@ -29,9 +29,9 @@ public function testTimestampUnix($stamp, $expected){ public function datetimes(){ return [ - [DateTime::createFromFormat('U', 0), '1970-01-01T00:00:00+0000'], - [DateTime::createFromFormat('U', 1), '1970-01-01T00:00:01+0000'], - [DateTime::createFromFormat('U', 86400), '1970-01-02T00:00:00+0000'], + [DateTime::createFromFormat('U', '0'), '1970-01-01T00:00:00+0000'], + [DateTime::createFromFormat('U', '1'), '1970-01-01T00:00:01+0000'], + [DateTime::createFromFormat('U', '86400'), '1970-01-02T00:00:00+0000'], ]; } From 18039c55d50085d36f23b5b4f80919eb1ecb2fdb Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 11:52:35 +0000 Subject: [PATCH 29/45] Added test for EmbedAuthor (and by extension, EmbedProvider) --- tests/EmbedElementsTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index 42f75b0..df30b18 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -33,4 +33,18 @@ public function testURL(){ $this->assertArrayHasKey('url', $data); $this->assertEquals('hello', $data['url']); } + + public function testAuthor(){ + $embed = new RichEmbed(); + $embed->setAuthor('hello', 'google.com', 'imgur.com', 'proxy.imgur.com'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('author', $data); + + $author = $data['author']; + $this->assertEquals('hello', $author['name']); + $this->assertEquals('google.com', $author['url']); + $this->assertEquals('imgur.com', $author['icon_url']); + $this->assertEquals('proxy.imgur.com', $author['proxy_icon_url']); + } } From 07668519e6a7cb984d9a1ac8524893015802e65f Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:09:16 +0000 Subject: [PATCH 30/45] Width comes first. --- src/Internal/EmbedVideo.php | 4 ++-- src/RichEmbed.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Internal/EmbedVideo.php b/src/Internal/EmbedVideo.php index cfa0ba4..fd8e4aa 100644 --- a/src/Internal/EmbedVideo.php +++ b/src/Internal/EmbedVideo.php @@ -19,10 +19,10 @@ class EmbedVideo implements JsonSerializable { /** * EmbedVideo constructor. * @param string $url Video URL - * @param int $height Height of the video. * @param int $width Width of the video. + * @param int $height Height of the video. */ - public function __construct(string $url = '', int $height = 0, int $width = 0){ + public function __construct(string $url = '', int $width = 0, int $height = 0){ $this->url = $url; $this->height = $height; $this->width = $width; diff --git a/src/RichEmbed.php b/src/RichEmbed.php index 020d4d4..e86bfc7 100644 --- a/src/RichEmbed.php +++ b/src/RichEmbed.php @@ -165,8 +165,8 @@ public function setThumbnail(string $url = '', string $proxy = '', int $height = * @param int $width * @return $this */ - public function setVideo(string $url = '', int $height = 0, int $width = 0): self{ - $this->video = new EmbedVideo($url, $height, $width); + public function setVideo(string $url = '', int $width = 0, int $height = 0): self{ + $this->video = new EmbedVideo($url, $width, $height); return $this; } From 74ea3898e0dbeea489b3ffa607f07d0dc6fce026 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:10:37 +0000 Subject: [PATCH 31/45] Add test for videos. --- tests/EmbedElementsTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index df30b18..3ac51bb 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -47,4 +47,17 @@ public function testAuthor(){ $this->assertEquals('imgur.com', $author['icon_url']); $this->assertEquals('proxy.imgur.com', $author['proxy_icon_url']); } + + public function testVideos(){ + $embed = new RichEmbed(); + $embed->setVideo('youtube.com', 1920, 1080); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('video', $data); + + $author = $data['video']; + $this->assertEquals('youtube.com', $author['url']); + $this->assertEquals(1920, $author['width']); + $this->assertEquals(1080, $author['height']); + } } From 8d8eb81690050b1be880491e760efc210985a7f3 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:12:35 +0000 Subject: [PATCH 32/45] And finally a test for embed providers. --- tests/EmbedElementsTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index 3ac51bb..75c14a9 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -60,4 +60,16 @@ public function testVideos(){ $this->assertEquals(1920, $author['width']); $this->assertEquals(1080, $author['height']); } + + public function testProvider(){ + $embed = new RichEmbed(); + $embed->setProvider('provider', 'provider.com'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('provider', $data); + + $author = $data['video']; + $this->assertEquals('provider', $author['name']); + $this->assertEquals('provider.com', $author['url']); + } } From 093fe64e27f9a14addd9a9b5d637b1feec219376 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:18:40 +0000 Subject: [PATCH 33/45] Swapped arguments. --- src/Internal/EmbedImage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Internal/EmbedImage.php b/src/Internal/EmbedImage.php index 832fae2..7c265bc 100644 --- a/src/Internal/EmbedImage.php +++ b/src/Internal/EmbedImage.php @@ -18,8 +18,8 @@ class EmbedImage extends EmbedVideo { * @param int $height The height of the image. * @param int $width The width of the image. */ - public function __construct(string $url = '', string $proxy_url = '', int $height = 0, int $width = 0){ - parent::__construct($url, $height, $width); + public function __construct(string $url = '', string $proxy_url = '', int $width = 0, int $height = 0){ + parent::__construct($url, $width, $height); $this->proxy_url = $proxy_url; } From 1c81397bd8961de5aaa5a69a454356c97daeb870 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:19:00 +0000 Subject: [PATCH 34/45] Fixed setImage, setThumbnail arg order. --- src/RichEmbed.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RichEmbed.php b/src/RichEmbed.php index e86bfc7..5ed5124 100644 --- a/src/RichEmbed.php +++ b/src/RichEmbed.php @@ -140,8 +140,8 @@ public function setAuthor(string $name = '', string $url = '', string $icon = '' * @param int $width * @return $this */ - public function setImage(string $url = '', string $proxy = '', int $height = 0, int $width = 0): self{ - $this->image = new EmbedImage($url, $proxy, $height, $width); + public function setImage(string $url = '', string $proxy = '', int $width = 0, int $height = 0): self{ + $this->image = new EmbedImage($url, $proxy, $width, $height); return $this; } @@ -153,8 +153,8 @@ public function setImage(string $url = '', string $proxy = '', int $height = 0, * @param int $width * @return $this */ - public function setThumbnail(string $url = '', string $proxy = '', int $height = 0, int $width = 0): self{ - $this->thumbnail = new EmbedImage($url, $proxy, $height, $width); + public function setThumbnail(string $url = '', string $proxy = '', int $width = 0, int $height = 0): self{ + $this->thumbnail = new EmbedImage($url, $proxy, $width, $height); return $this; } From e81bacdb52e8679676f3cf53eba1f9089e4bf816 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:21:00 +0000 Subject: [PATCH 35/45] Add test for images and thumbnails. --- tests/EmbedElementsTest.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index 75c14a9..c87f894 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -55,10 +55,31 @@ public function testVideos(){ $data = $embed->jsonSerialize(); $this->assertArrayHasKey('video', $data); - $author = $data['video']; - $this->assertEquals('youtube.com', $author['url']); - $this->assertEquals(1920, $author['width']); - $this->assertEquals(1080, $author['height']); + $video = $data['video']; + $this->assertEquals('youtube.com', $video['url']); + $this->assertEquals(1920, $video['width']); + $this->assertEquals(1080, $video['height']); + } + + public function testImages(){ + $embed = new RichEmbed(); + $embed->setImage('imgur.com', 'proxy.imgur.com', 1920, 1080); + $embed->setThumbnail('imgur.com', 'proxy.imgur.com', 1920, 1080); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('image', $data); + + $image = $data['image']; + $this->assertEquals('imgur.com', $image['url']); + $this->assertEquals('proxy.imgur.com', $image['url']); + $this->assertEquals(1920, $image['width']); + $this->assertEquals(1080, $image['height']); + + $thumb = $data['thumbnail']; + $this->assertEquals('imgur.com', $thumb['proxy_url']); + $this->assertEquals('proxy.imgur.com', $image['proxy_url']); + $this->assertEquals(1920, $thumb['width']); + $this->assertEquals(1080, $thumb['height']); } public function testProvider(){ From e5b88872baada1bfb4f508b6192c13fc9cf096e0 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:23:45 +0000 Subject: [PATCH 36/45] Provider, not author. --- tests/EmbedElementsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index c87f894..0d949e7 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -89,8 +89,8 @@ public function testProvider(){ $data = $embed->jsonSerialize(); $this->assertArrayHasKey('provider', $data); - $author = $data['video']; - $this->assertEquals('provider', $author['name']); - $this->assertEquals('provider.com', $author['url']); + $provider = $data['video']; + $this->assertEquals('provider', $provider['name']); + $this->assertEquals('provider.com', $provider['url']); } } From b2065c1d093ba5ef3727feea36c74a4e202c653a Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:24:51 +0000 Subject: [PATCH 37/45] Add test for footers. --- tests/EmbedElementsTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index 0d949e7..a97bd07 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -93,4 +93,17 @@ public function testProvider(){ $this->assertEquals('provider', $provider['name']); $this->assertEquals('provider.com', $provider['url']); } + + public function testFooter(){ + $embed = new RichEmbed(); + $embed->setFooter('footer text', 'imgur.com', 'proxy.imgur.com'); + + $data = $embed->jsonSerialize(); + $this->assertArrayHasKey('footer', $data); + + $footer = $data['footer']; + $this->assertEquals('footer text', $footer['text']); + $this->assertEquals('imgur.com', $footer['icon_url']); + $this->assertEquals('proxy.imgur.com', $footer['proxy_icon_url']); + } } From 3261d23e41b2b784530c7ea6ac481e7bab6a8833 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 12:29:35 +0000 Subject: [PATCH 38/45] Add a test for sending tts messages. --- tests/QueuedWebhookTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/QueuedWebhookTest.php b/tests/QueuedWebhookTest.php index 35a20c9..c5e31b7 100644 --- a/tests/QueuedWebhookTest.php +++ b/tests/QueuedWebhookTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Internet\InterCord\QueuedWebhook; +use Internet\InterCord\Internal\Payload; use GuzzleHttp\Exception\ClientException; class QueuedWebhookTest extends TestCase { @@ -38,4 +39,9 @@ public function testEmptyMessageException(){ $this->webhook->prepend(''); $this->webhook->run(1); } + + public function testSendingTTSMessage(){ + $this->webhook->prepend((new Payload())->setTTS(true)->setContent('hello')); + $this->webhook->run(1); + } } From df96e5a11200c8905777ddb610c214ef67da41dd Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:31:19 +0000 Subject: [PATCH 39/45] Allow continuing even if reports don't exist. --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a92da1..8883c3e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,15 +54,18 @@ jobs: WEBHOOK_TOKEN: ${{ secrets.WEBHOOK_TOKEN }} - name: Upload Coverage uses: actions/upload-artifact@v1 + continue-on-error: true with: name: Coverage Report (${{ matrix.php }}) path: coverage/ - name: Upload Test Report uses: actions/upload-artifact@v1 + continue-on-error: true with: name: Test Report (${{ matrix.php }}) path: test.html - name: Upload CodeCov Report + continue-on-error: true run: wget -qO- https://codecov.io/bash | bash env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 1e09e2f1f27484fc1cb22e31547305393243c263 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:31:33 +0000 Subject: [PATCH 40/45] Disable verbose debug mode. Disable html based coverage reports. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5de4a7..a0cd9d1 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }], "scripts": { - "test": "phpunit --debug -vvv --bootstrap vendor/autoload.php --colors=never --whitelist src/ --coverage-html coverage --testdox-html test.html --coverage-clover=coverage.xml tests", + "test": "phpunit --bootstrap vendor/autoload.php --colors=never --whitelist src/ --testdox-html test.html --coverage-clover=coverage.xml tests", "pcov-polyfill": [ "@composer require --dev pcov/clobber", "pcov clobber" From 7960c157225b402eadcb239eacd4b220796464db Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:32:04 +0000 Subject: [PATCH 41/45] That should be provider, not video. --- tests/EmbedElementsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index a97bd07..1d1e405 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -89,7 +89,7 @@ public function testProvider(){ $data = $embed->jsonSerialize(); $this->assertArrayHasKey('provider', $data); - $provider = $data['video']; + $provider = $data['provider']; $this->assertEquals('provider', $provider['name']); $this->assertEquals('provider.com', $provider['url']); } From 69ea42210d2b443b0655b88a1cd01016ce1e9712 Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:32:22 +0000 Subject: [PATCH 42/45] That should be proxy. --- tests/EmbedElementsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EmbedElementsTest.php b/tests/EmbedElementsTest.php index 1d1e405..fa763f5 100644 --- a/tests/EmbedElementsTest.php +++ b/tests/EmbedElementsTest.php @@ -71,7 +71,7 @@ public function testImages(){ $image = $data['image']; $this->assertEquals('imgur.com', $image['url']); - $this->assertEquals('proxy.imgur.com', $image['url']); + $this->assertEquals('proxy.imgur.com', $image['proxy_url']); $this->assertEquals(1920, $image['width']); $this->assertEquals(1080, $image['height']); From f82d0cf96b354fad44e70c2a130dd3136ff4729c Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:32:58 +0000 Subject: [PATCH 43/45] Make sure we assert. --- tests/QueuedWebhookTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/QueuedWebhookTest.php b/tests/QueuedWebhookTest.php index c5e31b7..d9b8deb 100644 --- a/tests/QueuedWebhookTest.php +++ b/tests/QueuedWebhookTest.php @@ -42,6 +42,8 @@ public function testEmptyMessageException(){ public function testSendingTTSMessage(){ $this->webhook->prepend((new Payload())->setTTS(true)->setContent('hello')); + $this->addToAssertionCount(1); $this->webhook->run(1); + $this->addToAssertionCount(1); } } From aed8686cb7d514641ddfb8a21474d803bb3b96ae Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:35:00 +0000 Subject: [PATCH 44/45] add time. --- tests/EmbedTimeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EmbedTimeTest.php b/tests/EmbedTimeTest.php index c6514ed..1fa3948 100644 --- a/tests/EmbedTimeTest.php +++ b/tests/EmbedTimeTest.php @@ -50,7 +50,7 @@ public function testDateTimeObject($time, $expected){ public function formatpairs(){ return [ ['0', 'U', '1970-01-01T00:00:00+0000'], - ['15-Feb-2009', 'j-M-Y', '2009-02-15T00:00:00+0000'] + ['15-Feb-2009 00:00', 'j-M-Y H:i', '2009-02-15T00:00:00+0000'] ]; } From 334b6e6edbdea73ff0c770c1e45c89f3a6b52b1f Mon Sep 17 00:00:00 2001 From: John Internet Date: Thu, 12 Mar 2020 14:35:57 +0000 Subject: [PATCH 45/45] Add more tests. --- tests/ColorTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/ColorTest.php b/tests/ColorTest.php index 3f2f1ae..a54158b 100644 --- a/tests/ColorTest.php +++ b/tests/ColorTest.php @@ -41,11 +41,11 @@ public function colours(){ */ public function emptyColors(){ return [ - 0, - '0', - '#000', - '#000000', - new Color(0, 0, 0) + [0], + ['0'], + ['#000'], + ['#000000'], + [new Color(0, 0, 0)] ]; } @@ -54,10 +54,10 @@ public function emptyColors(){ */ public function badColors(){ return [ - 16777216, // Above the largest value. - -1, // Below 0. - '#00', // Not a hex triplet. - '#00000000' // Not a hex triplet either. + [16777216], // Above the largest value. + [-1], // Below 0. + ['#00'], // Not a hex triplet. + ['#00000000'] // Not a hex triplet either. ]; }