Skip to content

Commit

Permalink
Merge branch 'main' into feature/alias-middleware-and-group-webhooks-…
Browse files Browse the repository at this point in the history
…by-name
  • Loading branch information
semihkeskindev committed Feb 25, 2024
2 parents db395e2 + 7392b8f commit f62a048
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 21 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
}
],
"require": {
"php": ">8.0",
"spatie/laravel-package-tools": "^1.12.0",
"illuminate/contracts": ">8.0"
"php": "^8.1",
"guzzlehttp/guzzle": "^7.8",
"spatie/laravel-package-tools": "^1.14.0",
"illuminate/contracts": "^10.0"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/Providers/DefaultProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Moneo\RequestForwarder\Providers;

use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\Response;

class DefaultProvider implements ProviderInterface
{
Expand All @@ -11,7 +12,10 @@ public function __construct(
) {
}

public function send($url, $params, $webhook)
/**
* @throws \Exception
*/
public function send(string $url, array $params, array $webhook): Response
{
return $this->client
->send($webhook['method'] ?? 'POST', $webhook['url']);
Expand Down
6 changes: 5 additions & 1 deletion src/Providers/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Moneo\RequestForwarder\Providers;

use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\Response;

class Discord implements ProviderInterface
{
Expand All @@ -11,7 +12,10 @@ public function __construct(
) {
}

public function send($url, $params, $webhook)
/**
* @throws \Exception
*/
public function send(string $url, array $params, array $webhook): Response
{
$content = $url.PHP_EOL;
$content .= json_encode($params);
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Moneo\RequestForwarder\Providers;

use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\Response;

interface ProviderInterface
{
public function __construct(Factory $client);

/** @return \Illuminate\Http\Client\Response */
public function send($url, $params, $webhook);
public function send(string $url, array $params, array $webhook): Response;
}
2 changes: 1 addition & 1 deletion src/RequestForwarderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function configurePackage(Package $package): void
->hasConfigFile();
}

public function registeringPackage()
public function registeringPackage(): void
{
$this->app->bind('laravel_request_forwarder.client', function ($app): Factory {
return $app[Factory::class];
Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

21 changes: 21 additions & 0 deletions tests/RequestForwarderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Http;

use function Pest\Laravel\get;
use function Pest\Laravel\post;

it('must not call any http request', function () {
Http::fake();
get('/')->assertStatus(200);
post('/')->assertStatus(200);
Http::assertNothingSent();
});

it('must send hooks', function () {
Http::fake();
get('/middleware')->assertStatus(200);
Http::assertSentCount(2);
get('/middleware')->assertStatus(200);
Http::assertSentCount(4);
});
22 changes: 14 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Moneo\RequestForwarder\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Route;
use Moneo\RequestForwarder\RequestForwarderMiddleware;
use Moneo\RequestForwarder\RequestForwarderServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;

Expand All @@ -12,9 +13,7 @@ protected function setUp(): void
{
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Moneo\\RequestForwarder\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
$this->registerTestRoutes();
}

protected function getPackageProviders($app)
Expand All @@ -27,10 +26,17 @@ protected function getPackageProviders($app)
public function getEnvironmentSetUp($app)
{
config()->set('database.default', 'testing');
}

protected function registerTestRoutes(): void
{
Route::middleware('api')->group(function () {
Route::any('/', fn () => 'No Middleware')
->name('no-middleware');

/*
$migration = include __DIR__.'/../database/migrations/create_laravel-request-forwarder_table.php.stub';
$migration->up();
*/
Route::middleware(RequestForwarderMiddleware::class)
->any('/middleware', fn () => 'With Middleware')
->name('middleware');
});
}
}

0 comments on commit f62a048

Please sign in to comment.