diff --git a/README.md b/README.md index aa2fa31..7d425c8 100644 --- a/README.md +++ b/README.md @@ -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'); diff --git a/src/Factory.php b/src/Factory.php index 318b4f7..7a56fe5 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -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()); diff --git a/src/Firebase.php b/src/Firebase.php deleted file mode 100644 index 460ba34..0000000 --- a/src/Firebase.php +++ /dev/null @@ -1,33 +0,0 @@ -database = $database; - $this->firestore = $firestore; - $this->auth = $auth; - $this->storage = $storage; - $this->remoteConfig = $remoteConfig; - $this->messaging = $messaging; - } - - public function getFirestore(): Firestore - { - return $this->firestore; - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 402df99..f7a317a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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 { @@ -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'], @@ -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(); } }