Skip to content

Commit

Permalink
Chore/maintenance (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Exanlv authored Jul 6, 2023
1 parent 87da97e commit 116106d
Show file tree
Hide file tree
Showing 27 changed files with 168 additions and 225 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ jobs:
php-version: 8.1
- name: Verify namespaces
run: bash util/verify-namespacing.sh
- name: Ensure no missing scrict types
run: bash util/missing-strict-types.sh
52 changes: 18 additions & 34 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,25 @@ on:
branches: master

jobs:
test-8_1:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install PHP 8.1
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- name: Install packages
run: composer install --no-progress
- name: Run tests
run: composer test
tests:

test-8_2:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install packages
run: composer install --no-progress
- name: Run tests
run: composer test

test-8_3:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]

steps:
- uses: actions/checkout@v3
- name: Install PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- name: Install packages
run: composer install --no-progress
- name: Run tests
run: composer test
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Install packages
run: composer install --prefer-dist --no-progress

- name: Run tests
run: composer test
37 changes: 37 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->in(__DIR__ . '/fakes')
;

$config = new PhpCsFixer\Config();

$config->setRules([
'@PER-CS1.0' => true,

'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,

'explicit_indirect_variable' => true,

'clean_namespace' => true,

'assign_null_coalescing_to_coalesce_equal' => true,

'concat_space' => [
'spacing' => 'one'
],

'no_useless_nullsafe_operator' => true,

'declare_strict_types' => true,
'strict_comparison' => true,

'single_blank_line_at_eof' => true,
])->setFinder($finder);

return $config;
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"license": "MIT",
"autoload": {
"psr-4": {
"Ragnarok\\Fenrir\\": "src/",
"Ragnarok\\Fenrir\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Ragnarok\\Fenrir\\": "tests/",
"Fakes\\Ragnarok\\Fenrir\\": "fakes/"
}
Expand All @@ -29,18 +33,17 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"seregazhuk/react-promise-testing": "^0.6.1",
"squizlabs/php_codesniffer": "^3.7",
"cboden/ratchet": "^0.4.4",
"phpmd/phpmd": "^2.13",
"symfony/var-dumper": "^6.2",
"mockery/mockery": "^1.6"
"mockery/mockery": "^1.6",
"friendsofphp/php-cs-fixer": "^3.20"
},
"scripts": {
"md": "phpmd src text ruleset.xml",

"cs": "phpcs --standard=phpcs src tests fakes phpcs",
"csf": "phpcbf --standard=phpcs src tests fakes phpcs",
"cs": "php-cs-fixer fix --using-cache=no --diff --dry-run --allow-risky=yes",
"csf": "php-cs-fixer fix --using-cache=no --allow-risky=yes",

"phpunit": "phpunit",
"phpunit-coverage": "@php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-html .phpunit.cache/cov-html",
Expand Down
46 changes: 0 additions & 46 deletions phpcs/Sniffs/custom/RequireReturnTypesSniff.php

This file was deleted.

6 changes: 0 additions & 6 deletions phpcs/ruleset.xml

This file was deleted.

12 changes: 9 additions & 3 deletions tests/BucketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
use PHPUnit\Framework\TestCase;
use React\EventLoop\Loop;

use function Clue\React\Block\await;
use function Clue\React\Block\awaitAll;
use function React\Async\await;

class BucketTest extends TestCase
{
use MockeryPHPUnitIntegration;

private function awaitAll(array $promises)
{
foreach ($promises as $promise) {
await($promise);
}
}

public function testLimit(): void
{
$bucket = new Bucket(Loop::get(), 2, 1);
Expand All @@ -26,7 +32,7 @@ public function testLimit(): void

$start = microtime(true);

awaitAll([$bucket->run($spy), $bucket->run($spy)]);
$this->awaitAll([$bucket->run($spy), $bucket->run($spy)]);

$mid = microtime(true);
$spy->shouldHaveBeenCalled()->twice();
Expand Down
6 changes: 3 additions & 3 deletions tests/DiscordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testItCanInitializeExtensions(): void

public function testItTellsYouWhetherExtensionsAreInstalled(): void
{
$extension = new class implements Extension {
$extension = new class () implements Extension {
public function initialize(Discord $discord): void
{
}
Expand All @@ -89,7 +89,7 @@ public function initialize(Discord $discord): void

public function testItReturnsTheExtension(): void
{
$extension = new class implements Extension {
$extension = new class () implements Extension {
public function initialize(Discord $discord): void
{
}
Expand All @@ -104,7 +104,7 @@ public function initialize(Discord $discord): void

public function testItYellsWhenYouTryToReturnANonRegisteredExtension(): void
{
$extension = new class implements Extension {
$extension = new class () implements Extension {
public function initialize(Discord $discord): void
{
}
Expand Down
42 changes: 17 additions & 25 deletions tests/EventHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
use Ragnarok\Fenrir\EventHandler;
use Ragnarok\Fenrir\Gateway\Objects\Payload;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use React\Promise\Promise;
use seregazhuk\React\PromiseTesting\AssertsPromise;
use stdClass;

final class EventHandlerTest extends TestCase
{
use AssertsPromise;

private DataMapper $dataMapper;

protected function setUp(): void
Expand All @@ -28,27 +23,21 @@ protected function setUp(): void
$this->dataMapper = DataMapperFake::get();
}

private function awaitResponse(EventHandler $eventHandler, string $event, Payload $payload): Promise
{
return new Promise(static function ($resolve) use ($eventHandler, $event, $payload) {
$eventHandler->on($event, static function (mixed $eventResponse) use ($resolve) {
$resolve($eventResponse);
});

$eventHandler->handle($payload);
});
}

public function testDoesNotEmitIfUnknownEvent(): void
{
$eventHandler = new EventHandler($this->dataMapper, false);

$payload = new Payload();
$payload->t = '::unknown event::';

$response = $this->awaitResponse($eventHandler, '::unknown event::', $payload);
$hasRun = false;
$eventHandler->on('::unknown event::', function () use (&$hasRun) {
$hasRun = true;
});

$eventHandler->handle($payload);

$this->assertPromiseRejects($response, 1);
$this->assertFalse($hasRun, 'Unknown event should not be emitted.');
}

/**
Expand All @@ -60,15 +49,18 @@ public function testEmitEvent($event, $class): void

$payload = new Payload();
$payload->t = $event;
$payload->d = new stdClass();
$payload->d = (object) [];

$hasRun = false;
$eventHandler->on($event, function ($event) use (&$hasRun, $class) {
$this->assertInstanceOf($class, $event);

$hasRun = true;
});

$response = $this->awaitResponse(
$eventHandler,
$event,
$payload
);
$eventHandler->handle($payload);

$this->assertPromiseFulfillsWithInstanceOf($response, $class);
$this->assertTrue($hasRun, 'Known event should be emitted.');
}

public function eventProvider(): array
Expand Down
24 changes: 12 additions & 12 deletions tests/Gateway/Handlers/Meta/UnacknowledgedHeartbeatEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ public function testItOpensAFreshConnectionIfResumingFails(): void
->andReturns(PromiseFake::get())
->once();

/** @var Eventer&MockInterface */
$rawHandler = Mockery::mock(Eventer::class);
$rawHandler->expects()
->registerOnce()
->with(IdentifyHelloEvent::class)
->once();

$connection->expects()
->getRawHandler()
->andReturns($rawHandler)
->once();
/** @var Eventer&MockInterface */
$rawHandler = Mockery::mock(Eventer::class);
$rawHandler->expects()
->registerOnce()
->with(IdentifyHelloEvent::class)
->once();

$connection->expects()
->getRawHandler()
->andReturns($rawHandler)
->once();

$event = new UnacknowledgedHeartbeatEvent(
$connection,
new NullLogger(),
);

$event->execute();
$event->execute();
}
}
Loading

0 comments on commit 116106d

Please sign in to comment.