TestUserCommand.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Classes\Pterodactyl;
  4. use Illuminate\Foundation\Testing\DatabaseTransactions;
  5. use Tests\TestCase;
  6. class TestUserCommand extends TestCase
  7. {
  8. use DatabaseTransactions;
  9. /**
  10. * A basic feature test example.
  11. * @dataProvider invalidPteroIdDataProvider
  12. * @param array $apiResponse
  13. * @param int $expectedExitCode
  14. * @return void
  15. */
  16. public function testMakeUserCommand(array $apiResponse, int $expectedExitCode): void
  17. {
  18. $pterodactyl = $this->getMockBuilder(Pterodactyl::class)->getMock();
  19. $pterodactyl->expects(self::once())->method('getUser')->willReturn($apiResponse);
  20. $this->app->instance(Pterodactyl::class, $pterodactyl);
  21. $this->artisan('make:user')
  22. ->expectsQuestion('Please specify your Pterodactyl ID.', 0)
  23. ->expectsQuestion('Please specify your password.', 'password')
  24. ->assertExitCode($expectedExitCode);
  25. }
  26. public function invalidPteroIdDataProvider(): array
  27. {
  28. return [
  29. 'Good Response' => [
  30. 'apiResponse' => [
  31. 'id' => 12345,
  32. 'first_name' => 'Test',
  33. 'email' => 'test@test.test'
  34. ],
  35. 'expectedExitCode' => 1
  36. ],
  37. 'Bad Response' => [
  38. 'apiResponse' => [],
  39. 'expectedExitCode' => 0
  40. ]
  41. ];
  42. }
  43. }