Skip to content

Commit

Permalink
Merge branch '3.0' of github.com:dystcz/laravel-fakturoid into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
repl6669 committed Feb 14, 2025
2 parents 71d9e25 + 850aa41 commit 89ab84e
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fakturoid/fakturoid-php": "^3.0"
},
"require-dev": {
"dg/bypass-finals": "^1.9",
"larastan/larastan": "^3.0",
"laravel/pint": "^1.7",
"mockery/mockery": "^1.5",
Expand Down
55 changes: 54 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
colors="true" processIsolation="false" stopOnFailure="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<extensions>
<bootstrap class="DG\BypassFinals\PHPUnitExtension">
<parameter name="bypassFinal" value="true"/>
<parameter name="bypassReadOnly" value="false"/>
<parameter name="cacheDirectory" value=".phpunit.cache"/>
</bootstrap>
</extensions>
<coverage/>
<testsuites>
<testsuite name="Tests">
Expand Down
15 changes: 1 addition & 14 deletions src/Fakturoid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Dystcz\Fakturoid\Contracts\Fakturoid as FakturoidContract;
use Fakturoid\Exception\AuthorizationFailedException;
use Fakturoid\FakturoidManager;
use GuzzleHttp\Client as Guzzle;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;

/**
* @method void setAccountSlug(string $companySlug)
Expand Down Expand Up @@ -40,21 +37,11 @@
*/
class Fakturoid implements FakturoidContract
{
protected FakturoidManager $fakturoid;

/**
* @throws AuthorizationFailedException
*/
public function __construct()
public function __construct(protected FakturoidManager $fakturoid)
{
$this->fakturoid = App::make(FakturoidManager::class, [
'client' => new Guzzle,
'clientId' => Config::get('fakturoid.client_id'),
'clientSecret' => Config::get('fakturoid.client_secret'),
'userAgent' => Config::get('fakturoid.user_agent'),
'accountSlug' => Config::get('fakturoid.account_slug'),
]);

$this->fakturoid->authClientCredentials();
}

Expand Down
18 changes: 17 additions & 1 deletion src/FakturoidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
namespace Dystcz\Fakturoid;

use Dystcz\Fakturoid\Contracts\Fakturoid as FakturoidContract;
use Fakturoid\FakturoidManager;
use GuzzleHttp\Client as Guzzle;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;

class FakturoidServiceProvider extends ServiceProvider
Expand All @@ -28,6 +32,18 @@ public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/fakturoid.php', 'fakturoid');

$this->app->singleton(FakturoidContract::class, fn () => new Fakturoid);
$this->app->bind('fakturoid', fn (Application $app) => $app->make(FakturoidManager::class, [
'client' => new Guzzle,
'clientId' => Config::get('fakturoid.client_id'),
'clientSecret' => Config::get('fakturoid.client_secret'),
'userAgent' => Config::get('fakturoid.user_agent'),
'accountSlug' => Config::get('fakturoid.account_slug'),
]));

$this->app->singleton(
FakturoidContract::class,
fn (Application $app) => $app->make(Fakturoid::class, [
'fakturoid' => $app->make('fakturoid'),
]));
}
}
2 changes: 1 addition & 1 deletion tests/Feature/FakturoidFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

uses(TestCase::class);

it('can call Fakturoid', function (string $method) {
it('forwards calls from facade', function (string $method) {
/** @var TestCase $this */
$fakturoid = $this->mock(FakturoidContract::class);

Expand Down
61 changes: 61 additions & 0 deletions tests/Feature/FakturoidTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Dystcz\Fakturoid\Contracts\Fakturoid as FakturoidContract;
use Dystcz\Fakturoid\Facades\Fakturoid as FakturoidFacade;
use Dystcz\Fakturoid\Fakturoid;
use Dystcz\Fakturoid\Tests\TestCase;
use Fakturoid\Auth\CredentialCallback;
use Fakturoid\Auth\Credentials;
use Fakturoid\Enum\AuthTypeEnum;
use Fakturoid\FakturoidManager;

uses(TestCase::class);

it('forwards calls to FakturoidManager', function (string $method, array $params = []) {
/** @var TestCase $this */
$fakturoidManager = Mockery::mock(FakturoidManager::class);

$this->app->instance('fakturoid', $fakturoidManager);

$fakturoid = Mockery::mock(Fakturoid::class, FakturoidContract::class);

$fakturoidManager->shouldReceive('authClientCredentials')->once();
$fakturoidManager->shouldReceive($method)->once()->with(...$params);

FakturoidFacade::{$method}(...$params);
})->with([
['setAccountSlug', ['test']],
['getAuthProvider'],
['getAuthenticationUrl'],
['requestCredentials', ['code']],
['getCredentials'],
['setCredentials', [new Credentials(
'refresh_token',
'access_token',
DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM, '2021-01-01T00:00:00+00:00'),
AuthTypeEnum::AUTHORIZATION_CODE_FLOW
)]],
['setCredentialsCallback', [
new class implements CredentialCallback
{
public function __invoke(?Credentials $credentials = null): void {}
},
]],
['authClientCredentials'],
['getDispatcher'],
['getAccountProvider'],
['getBankAccountsProvider'],
['getEventsProvider'],
['getExpensesProvider'],
['getGeneratorsProvider'],
['getInboxFilesProvider'],
['getInventoryItemsProvider'],
['getInventoryMovesProvider'],
['getInvoicesProvider'],
['getNumberFormatsProvider'],
['getRecurringGeneratorsProvider'],
['getSubjectsProvider'],
['getTodosProvider'],
['getUsersProvider'],
['getWebhooksProvider'],
]);

0 comments on commit 89ab84e

Please sign in to comment.