Skip to content

Commit

Permalink
Updating test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
RTippin committed Jul 16, 2021
1 parent 1c458a3 commit 66801e1
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Facades/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @method static array getAllSearchableProviders()
* @method static array getAllFriendableProviders()
* @method static array getAllProviders(bool $returnFullClass = false)
* @method static array getRawProviders()
* @method static array getAllProvidersWithDevices()
* @method static int getMessageSizeLimit()
* @method static \RTippin\Messenger\Messenger setMessageSizeLimit(int $messageSizeLimit)
Expand Down
10 changes: 10 additions & 0 deletions src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public function getAllProviders(bool $returnFullClass = false): array
->toArray();
}

/**
* Return the raw array of our registered providers.
*
* @return array
*/
public function getRawProviders(): array
{
return $this->providers->toArray();
}

/**
* Determine if the provider is searchable.
*
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/CompanyModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public static function getProviderSettings(): array

public static function reset(): void
{
self::$alias = 'company';
self::$searchable = true;
self::$friendable = true;
self::$devices = true;
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static function getProviderSettings(): array

public static function reset(): void
{
self::$alias = 'user';
self::$searchable = true;
self::$friendable = true;
self::$devices = true;
Expand Down
118 changes: 118 additions & 0 deletions tests/Messenger/MessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use RTippin\Messenger\Exceptions\InvalidProviderException;
use RTippin\Messenger\Facades\Messenger as MessengerFacade;
use RTippin\Messenger\Messenger;
use RTippin\Messenger\Models\Bot;
use RTippin\Messenger\Models\GhostUser;
use RTippin\Messenger\Models\Participant;
use RTippin\Messenger\Services\Janus\VideoRoomService;
Expand Down Expand Up @@ -60,6 +61,122 @@ public function it_throws_exception_if_provider_doesnt_implement_our_interface()
$this->messenger->registerProviders([$invalid]);
}

/** @test */
public function it_sets_providers_including_bot()
{
// Providers already set from our master test case.
$this->assertCount(3, $this->messenger->getRawProviders());
$this->assertArrayHasKey(UserModel::class, $this->messenger->getRawProviders());
$this->assertArrayHasKey(CompanyModel::class, $this->messenger->getRawProviders());
$this->assertArrayHasKey(Bot::class, $this->messenger->getRawProviders());
}

/** @test */
public function it_overwrites_providers_and_resets_bot()
{
$this->messenger->registerProviders([UserModel::class], true);

$this->assertCount(2, $this->messenger->getRawProviders());
$this->assertArrayHasKey(UserModel::class, $this->messenger->getRawProviders());
$this->assertArrayHasKey(Bot::class, $this->messenger->getRawProviders());
}

/** @test */
public function it_overwrites_provider_aliases()
{
UserModel::$alias = 'test_user';
CompanyModel::$alias = 'test_company';
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertSame('test_user', $providers[UserModel::class]['alias']);
$this->assertSame('test_company', $providers[CompanyModel::class]['alias']);
}

/** @test */
public function it_sets_provider_morph_map_class()
{
$providers = $this->messenger->getRawProviders();

$this->assertSame((new UserModel)->getMorphClass(), $providers[UserModel::class]['morph_class']);
$this->assertSame((new CompanyModel)->getMorphClass(), $providers[CompanyModel::class]['morph_class']);
}

/** @test */
public function it_sets_providers_searchable()
{
CompanyModel::$searchable = false;
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertTrue($providers[UserModel::class]['searchable']);
$this->assertFalse($providers[CompanyModel::class]['searchable']);
}

/** @test */
public function it_sets_providers_friendable()
{
CompanyModel::$friendable = false;
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertTrue($providers[UserModel::class]['friendable']);
$this->assertFalse($providers[CompanyModel::class]['friendable']);
}

/** @test */
public function it_sets_providers_devices()
{
CompanyModel::$devices = false;
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertTrue($providers[UserModel::class]['devices']);
$this->assertFalse($providers[CompanyModel::class]['devices']);
}

/** @test */
public function it_sets_providers_default_avatars()
{
$providers = $this->messenger->getRawProviders();

$this->assertSame('/path/to/user.png', $providers[UserModel::class]['default_avatar']);
$this->assertSame('/path/to/company.png', $providers[CompanyModel::class]['default_avatar']);
}

/** @test */
public function it_sets_providers_cant_message_first()
{
CompanyModel::$cantMessage = [UserModel::class];
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertSame([], $providers[UserModel::class]['cant_message_first']);
$this->assertSame([UserModel::class], $providers[CompanyModel::class]['cant_message_first']);
}

/** @test */
public function it_sets_providers_cant_search()
{
CompanyModel::$cantSearch = [UserModel::class];
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertSame([], $providers[UserModel::class]['cant_search']);
$this->assertSame([UserModel::class], $providers[CompanyModel::class]['cant_search']);
}

/** @test */
public function it_sets_providers_cant_friend()
{
CompanyModel::$cantFriend = [UserModel::class];
$this->messenger->registerProviders([UserModel::class, CompanyModel::class]);
$providers = $this->messenger->getRawProviders();

$this->assertSame([], $providers[UserModel::class]['cant_friend']);
$this->assertSame([UserModel::class], $providers[CompanyModel::class]['cant_friend']);
}

/** @test */
public function it_checks_objects_and_class_strings_for_valid_provider()
{
Expand Down Expand Up @@ -313,6 +430,7 @@ public function it_returns_default_provider_avatar_path_using_provider_alias()
{
$this->assertSame('/path/to/user.png', $this->messenger->getProviderDefaultAvatarPath('user'));
$this->assertSame('/path/to/company.png', $this->messenger->getProviderDefaultAvatarPath('company'));
$this->assertNotNull($this->messenger->getProviderDefaultAvatarPath('bot'));
$this->assertNull($this->messenger->getProviderDefaultAvatarPath('undefined'));
}

Expand Down

0 comments on commit 66801e1

Please sign in to comment.