Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 26ca73b

Browse files
committed
Added the ability to mock BeeAuth::generateToken with Laravel
1 parent 47aef9a commit 26ca73b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,23 @@ Client Secret: `config('services.bee.client_secret')`
120120

121121
If you don't want to use this config, you can always pass the values manually.
122122

123+
### Caching with Laravel
124+
123125
Laravel service provider will also automatically inject Laravel's cache implementation on `BeeAuth`, so your auth tokens will be cached for as long as possible.
124126

125-
### Testing
127+
### Testing with Laravel
128+
129+
If you are writing integration tests, but don't want your tests making requests to Bee to get credentials, we have a little helper that can help you. Just run the following code:
130+
131+
```php
132+
use KirschbaumDevelopment\Bee\Laravel\BeeAuthMock;
133+
134+
BeeAuthMock::init();
135+
```
136+
137+
With this, any time you call `BeeAuth::generateToken()` in your code you will receive the same response you would receive, but with some fake tokens and without making any HTTP requests.
138+
139+
## Testing
126140

127141
``` bash
128142
composer test

src/Laravel/BeeAuthMock.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\Bee\Laravel;
4+
5+
use Mockery;
6+
use KirschbaumDevelopment\Bee\BeeAuth;
7+
use KirschbaumDevelopment\Bee\Resources\AuthorizationToken;
8+
9+
class BeeAuthMock
10+
{
11+
public static function init()
12+
{
13+
$token = new AuthorizationToken([
14+
'access_token' => 'isufgisufdhguisdfhuisdf.oasihuifghsdif79s87f9sd8f7sd98f7sd98f7dsu89f.owTLmGhqv6ZJSikUhGeLBv-JANoXEAVvMZomivT2o-g',
15+
'token_type' => 'bearer',
16+
'expires_in' => 300,
17+
'refresh_token' => '09a7sd98as7f98ds6f79sd8f.09a8s7da98sd7as98d7as9d8a7s9d8as6d9as86das98d67as.owTLmGhqv6ZJSikUhGeLBv-JANoXEAVvMZomivT2o-g',
18+
'as:client_id' => 'da91fe57-1ca6-4dba-b557-61edb96f4149',
19+
'userName' => 'Tn3KV7JYavWn',
20+
'as:region' => 'eu-west-1',
21+
'.issued' => 'Sat, 17 Aug 2019 00:08:50 GMT',
22+
'.expires' => 'Sat, 17 Aug 2019 00:13:50 GMT',
23+
]);
24+
25+
$beeAuth = Mockery::mock(BeeAuth::class);
26+
$beeAuth->shouldReceive('generateToken')->andReturn($token);
27+
28+
app()->instance(BeeAuth::class, $beeAuth);
29+
}
30+
}

0 commit comments

Comments
 (0)