Skip to content

Commit

Permalink
Fix tests + update to static dataProvider (#80)
Browse files Browse the repository at this point in the history
* Fix tests + update to static dataProvider

* Remove backup file
  • Loading branch information
Exanlv authored Feb 28, 2024
1 parent eb21419 commit 484807c
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 79 deletions.
45 changes: 15 additions & 30 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
stopOnError="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/Parts</directory>
<directory>src/Exceptions</directory>
</exclude>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" stopOnError="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="false">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/Parts</directory>
<directory>src/Exceptions</directory>
</exclude>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Component/SelectMenu/MentionableSelectMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MentionableSelectMenu extends SelectMenu
public function get(): array
{
return [
parent::get(),
...parent::get(),
'default_values' => $this->defaultValues,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component/SelectMenu/RoleSelectMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RoleSelectMenu extends SelectMenu
public function get(): array
{
return [
parent::get(),
...parent::get(),
'default_values' => $this->defaultValues,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Component/SelectMenu/UserSelectMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserSelectMenu extends SelectMenu
public function get(): array
{
return [
parent::get(),
...parent::get(),
'default_values' => $this->defaultValues,
];
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Command/CommandExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Tests\Ragnarok\Fenrir\Command;

use Fakes\Ragnarok\Fenrir\DiscordFake;
use PHPUnit\Framework\TestCase;
use Ragnarok\Fenrir\Discord;

class CommandExtensionTest extends TestCase
{
private Discord $discord;

protected function setUp(): void
{
$this->discord = DiscordFake::get();
}
}
30 changes: 15 additions & 15 deletions tests/Component/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class ButtonTest extends TestCase
{
private function getEmoji(): EmojiBuilder
private static function getEmoji(): EmojiBuilder
{
$emoji = new Emoji();
$emoji->id = '::emoji id::';
Expand Down Expand Up @@ -47,35 +47,35 @@ public function testCorrectlyConverted(array $args, array $expected): void
}
}

public function convertionExpectationProvider(): array
public static function convertionExpectationProvider(): array
{
return [
'Completely filled out' => [
'args' => [
'::custom id::',
'::label::',
$this->getEmoji(),
self::getEmoji(),
true,
],
'expected' => [
'type' => 2,
'custom_id' => '::custom id::',
'label' => '::label::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => true
],
],
'Missing label' => [
'args' => [
'::custom id::',
null,
$this->getEmoji(),
self::getEmoji(),
true,
],
'expected' => [
'type' => 2,
'custom_id' => '::custom id::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => true
],
],
Expand All @@ -97,13 +97,13 @@ public function convertionExpectationProvider(): array
'args' => [
'::custom id::',
'::label::',
$this->getEmoji(),
self::getEmoji(),
],
'expected' => [
'type' => 2,
'custom_id' => '::custom id::',
'label' => '::label::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => false
],
],
Expand All @@ -120,37 +120,37 @@ public function testCorrectlyConvertedLinkButton(array $args, array $expected):
$this->assertEquals($expected, $button->get());
}

public function convertionExpectationProviderLinkButton(): array
public static function convertionExpectationProviderLinkButton(): array
{
return [
'Completely filled out' => [
'args' => [
'::url::',
'::label::',
$this->getEmoji(),
self::getEmoji(),
true,
],
'expected' => [
'type' => 2,
'style' => ButtonStyle::Link,
'url' => '::url::',
'label' => '::label::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => true
],
],
'Missing label' => [
'args' => [
'::url::',
null,
$this->getEmoji(),
self::getEmoji(),
true,
],
'expected' => [
'type' => 2,
'style' => ButtonStyle::Link,
'url' => '::url::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => true
],
],
Expand All @@ -173,14 +173,14 @@ public function convertionExpectationProviderLinkButton(): array
'args' => [
'::url::',
'::label::',
$this->getEmoji(),
self::getEmoji(),
],
'expected' => [
'type' => 2,
'style' => ButtonStyle::Link,
'url' => '::url::',
'label' => '::label::',
'emoji' => $this->getEmoji()->get(),
'emoji' => self::getEmoji()->get(),
'disabled' => false
],
],
Expand Down
10 changes: 8 additions & 2 deletions tests/Component/ChannelSelectMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testCorrectlyConverted(array $args, array $expected): void
$this->assertEquals($expected, $select->get());
}

public function convertionExpectationProvider(): array
public static function convertionExpectationProvider(): array
{
return [
'Completely filled out' => [
Expand All @@ -31,7 +31,7 @@ public function convertionExpectationProvider(): array
[ChannelType::ANNOUNCEMENT_THREAD, ChannelType::PUBLIC_THREAD],
5,
10,
true
true,
],
'expected' => [
'type' => SelectMenuType::Channel,
Expand All @@ -41,6 +41,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing placeholder' => [
Expand All @@ -59,6 +60,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing channel types' => [
Expand All @@ -77,6 +79,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing min values' => [
Expand All @@ -96,6 +99,7 @@ public function convertionExpectationProvider(): array
'min_values' => 1,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing max values' => [
Expand All @@ -115,6 +119,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 25,
'disabled' => true,
'default_values' => [],
],
],
'Missing disabled' => [
Expand All @@ -133,6 +138,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => false,
'default_values' => [],
],
],
];
Expand Down
9 changes: 7 additions & 2 deletions tests/Component/GeneralSelectMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function testCorrectlyConverted(array $args, array $expected): void

$select = new $selectClass(...$args);

$this->assertEquals($expected, $select->get());
$this->assertEquals($expected, $select->get(), 'Failed on ' . $selectClass);
}
}

public function convertionExpectationProvider(): array
public static function convertionExpectationProvider(): array
{
return [
'Completely filled out' => [
Expand All @@ -49,6 +49,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing placeholder' => [
Expand All @@ -64,6 +65,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing min values' => [
Expand All @@ -80,6 +82,7 @@ public function convertionExpectationProvider(): array
'min_values' => 1,
'max_values' => 10,
'disabled' => true,
'default_values' => [],
],
],
'Missing max values' => [
Expand All @@ -96,6 +99,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 25,
'disabled' => true,
'default_values' => [],
],
],
'Missing disabled' => [
Expand All @@ -111,6 +115,7 @@ public function convertionExpectationProvider(): array
'min_values' => 5,
'max_values' => 10,
'disabled' => false,
'default_values' => [],
],
],
];
Expand Down
Loading

0 comments on commit 484807c

Please sign in to comment.