Comments (4)
Hi, I temporarily solved with a simple trait that creates a test user on my side, generates a uid using Str::random(28)
and authenticates with signInWithCustomToken
.
<?php
namespace Tests;
use App\Models\User\User;
use Kreait\Firebase\Auth\SignInResult;
use Kreait\Laravel\Firebase\Facades\FirebaseAuth;
trait InteractsWithFirebase
{
/**
* Crea un nuevo usuario de nuestro lado y lo intenta autenticar con firebase.
*
* @param array $attributes
* @return \Kreait\Firebase\Auth\SignInResult
*/
public function actingAsFirebaseUser(array $attributes = []): SignInResult
{
$user = factory(User::class)->create($attributes);
$customToken = FirebaseAuth::createCustomToken(
$user->getAttributeValue('firebase_uid')
);
$authenticated = FirebaseAuth::signInWithCustomToken($customToken);
if ($authenticated instanceof SignInResult) {
$this->withToken($authenticated->idToken());
}
return $authenticated;
}
}
I don't know if it's the best way, but my tests behave as I expect.
<?php
class MySuperTesting {
use InteractsWithFirebase;
/**
* @test Can update the authenticated user profile.
*/
public function can_update_user_profile()
{
$this->actingAsFirebaseUser();
$response = $this->putJson('/api/users', ['firstname' => 'Maria']);
$response->assertOk();
$response->assertJson([
'data' => ['firstname' => 'Maria']
]);
}
}
from laravel-firebase.
Unfortunately, it currently doesn't. What you could do is abstracting away the Firebase interactions in an application service.
It's planned for a future release to allow using the Firebase Emulator suite (which still would need spinning up a testing environment and which wouldn't really be unit tests anyway), but I can't give you an ETA 🙈
You can follow the progress (when it happens) at kreait/firebase-php#456
If you have another idea besides the abstraction, please let me know 🤞
from laravel-firebase.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from laravel-firebase.
@gregorip02 Yes, your tests may work as expected, but the drawback here is that you actually interact with the Firebase server when you need to run your test. An improved solution should make it possible for you to act as firebase user without actually hitting their endpoints to authenticate. There should be a way to sandbox their authentication...somehow....
from laravel-firebase.
Related Issues (20)
- Next release HOT 2
- No publishable resources for tag []. Publishing complete. HOT 5
- Callable functions
- SenderId mismatch HOT 7
- Laravel error HOT 2
- getting error HOT 1
- Incompatibility with Eloquent Resources? HOT 1
- Confirm email verification Support
- Its not supported php 8. Please fix this
- Push notifications are not getting displayed in IOS and Android randomly HOT 1
- Be able to override FirestoreClient::DEFAULT_DATABASE HOT 7
- Support PHP8.3 HOT 2
- Firestore insert or update problem when using laravel-octane HOT 3
- Auto discovery not working similar to v4.x HOT 5
- Cannot mock final class for phpunit tests as it's return type is other final class HOT 1
- Support symfony/cache version 7 HOT 3
- Make Support For Laravel 11 HOT 2
- Curl error on Laravel 11 HOT 9
- laravel publish issue HOT 1
- Unable to install kreait/laravel-firebase on Laravel 11 project HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-firebase.