Skip to content

Commit

Permalink
fix: Remove need for Firebase class
Browse files Browse the repository at this point in the history
Breaks `Factory::create()` and `Firebase::getFirestore()` use `Factory::createFirestore()` instead
  • Loading branch information
morrislaptop committed May 24, 2018
1 parent e1c0563 commit ac256f2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 60 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ use Kreait\Firebase\ServiceAccount;
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . '/google-service-account.json');

$firebase = (new Factory)
$firestore = (new Factory)
->withServiceAccount($serviceAccount)
->create();

$firestore = $firebase->getFirestore();
->createFirestore();

$collection = self::$firestore->getCollection('users');
$user = $collection->getDocument('123456');
Expand Down
14 changes: 1 addition & 13 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,7 @@ class Factory extends BaseFactory

private static $firestoreUriPattern = 'https://firestore.googleapis.com/v1beta1/projects/%s/databases/(default)/documents/';

public function create() : BaseFirebase
{
$database = $this->createDatabase();
$firestore = $this->createFirestore();
$auth = $this->createAuth();
$storage = $this->createStorage();
$remoteConfig = $this->createRemoteConfig();
$messaging = $this->createMessaging();

return new Firebase($database, $firestore, $auth, $storage, $remoteConfig, $messaging);
}

private function createFirestore() : Firestore
public function createFirestore() : Firestore
{
$http = $this->createApiClient($this->getServiceAccount());

Expand Down
33 changes: 0 additions & 33 deletions src/Firebase.php

This file was deleted.

15 changes: 5 additions & 10 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ abstract class TestCase extends BaseTestCase

public static function setUpBeforeClass()
{
self::setUpFirebase();

self::$firestore = self::$firebase->getFirestore();
self::setUpFirestore();
self::$testCollection = 'tests';

try {
Expand All @@ -45,10 +43,8 @@ public static function setUpBeforeClass()
}
}

public static function setUpFirebase()
public static function setUpFirestore()
{
$credentialsPath = self::$fixturesDir.'/test_credentials.json';

try {
self::$serviceAccount = ServiceAccount::fromArray([
'project_id' => $_ENV['FIREBASE_PROJECT_ID'],
Expand All @@ -57,14 +53,13 @@ public static function setUpFirebase()
'private_key' => str_replace('\n', "\n", $_ENV['FIREBASE_PRIVATE_KEY'])
]);
} catch (\Throwable $e) {
dump($e);
self::markTestSkipped('The integration tests require a credentials file at "'.$credentialsPath.'"."');
self::markTestSkipped('The integration tests require FIREBASE_PROJECT_ID, FIREBASE_CLIENT_ID, FIREBASE_CLIENT_EMAIL and FIREBASE_PRIVATE_KEY env variables');

return;
}

self::$firebase = (new Factory())
self::$firestore = (new Factory())
->withServiceAccount(self::$serviceAccount)
->create();
->createFirestore();
}
}

0 comments on commit ac256f2

Please sign in to comment.