Google\Cloud\PubSub\Subscription::exists PHP Method

exists() public method

Service errors will NOT bubble up from this method. It will always return a boolean value. If you want to check for errors, use {@see \Google\Cloud\PubSub\Subscription::info()}. If you need to re-check the existence of a subscription that is already downloaded, call {@see \Google\Cloud\PubSub\Subscription::reload()} first to refresh the cached information. Example: if ($subscription->exists()) { echo 'Subscription exists!'; }
public exists ( array $options = [] ) : boolean
$options array [optional] Configuration Options
return boolean
    public function exists(array $options = [])
    {
        try {
            $this->info($options);
            return true;
        } catch (NotFoundException $e) {
            return false;
        }
    }

Usage Example

 public function testExistsNotFound()
 {
     $this->connection->getSubscription(Argument::any())->willThrow(new NotFoundException('bad'))->shouldBeCalledTimes(1);
     $subscription = new Subscription($this->connection->reveal(), 'subscription-name', 'topic-name', 'project-id');
     $this->assertFalse($subscription->exists());
 }