-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73dd1d2
commit 7c6a386
Showing
2 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Playground | ||
*/ | ||
namespace Tests\Unit\Playground\ServiceProvider; | ||
|
||
use Playground\ServiceProvider; | ||
use Tests\Unit\Playground\TestCase; | ||
use TiMacDonald\Log\LogEntry; | ||
use TiMacDonald\Log\LogFake; | ||
|
||
/** | ||
* \Tests\Unit\Playground\ServiceProvider\InstanceTest | ||
*/ | ||
class InstanceTest extends TestCase | ||
{ | ||
public function test_version_matches(): void | ||
{ | ||
$instance = (new \ReflectionClass(ServiceProvider::class))->newInstanceWithoutConstructor(); | ||
|
||
$this->assertNotEmpty(ServiceProvider::VERSION); | ||
$this->assertIsString(ServiceProvider::VERSION); | ||
$this->assertSame(ServiceProvider::VERSION, $instance->version()); | ||
} | ||
|
||
public function test_userPrimaryKeyType_with_empty_model(): void | ||
{ | ||
$instance = (new \ReflectionClass(ServiceProvider::class))->newInstanceWithoutConstructor(); | ||
|
||
$auth_providers_users_model = null; | ||
|
||
$expected = '<fg=yellow;options=bold>invalid</>'; | ||
|
||
$this->assertSame( | ||
$expected, | ||
$instance->userPrimaryKeyType($auth_providers_users_model) | ||
); | ||
} | ||
|
||
public function test_userPrimaryKeyType_with_incrementing_model(): void | ||
{ | ||
$instance = (new \ReflectionClass(ServiceProvider::class))->newInstanceWithoutConstructor(); | ||
|
||
$auth_providers_users_model = \Playground\Test\Models\User::class; | ||
|
||
$expected = '<fg=green;options=bold>increments</>'; | ||
|
||
$this->assertSame( | ||
$expected, | ||
$instance->userPrimaryKeyType($auth_providers_users_model) | ||
); | ||
} | ||
|
||
public function test_userPrimaryKeyType_with_uuid_model(): void | ||
{ | ||
$instance = (new \ReflectionClass(ServiceProvider::class))->newInstanceWithoutConstructor(); | ||
|
||
$auth_providers_users_model = \Playground\Models\User::class; | ||
|
||
$expected = '<fg=green;options=bold>UUID</>'; | ||
|
||
$this->assertSame( | ||
$expected, | ||
$instance->userPrimaryKeyType($auth_providers_users_model) | ||
); | ||
} | ||
|
||
public function test_userPrimaryKeyType_with_exception(): void | ||
{ | ||
$log = LogFake::bind(); | ||
|
||
$instance = (new \ReflectionClass(ServiceProvider::class))->newInstanceWithoutConstructor(); | ||
|
||
$auth_providers_users_model = \Exception::class; | ||
|
||
$expected = '<fg=red;options=bold>error</>'; | ||
|
||
$this->assertSame( | ||
$expected, | ||
$instance->userPrimaryKeyType($auth_providers_users_model) | ||
); | ||
|
||
// $log->dump(); | ||
|
||
$log->assertLogged( | ||
fn (LogEntry $log) => $log->level === 'debug' | ||
); | ||
$log->assertLogged( | ||
fn (LogEntry $log) => str_contains( | ||
$log->message, | ||
'Error: Call to undefined method Exception::getIncrementing()' | ||
) | ||
); | ||
} | ||
} |