TestUserCommand.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. *
  12. * @dataProvider invalidPteroIdDataProvider
  13. *
  14. * @param array $apiResponse
  15. * @param int $expectedExitCode
  16. * @return void
  17. */
  18. public function testMakeUserCommand(array $apiResponse, int $expectedExitCode): void
  19. {
  20. $pterodactyl = $this->getMockBuilder(Pterodactyl::class)->getMock();
  21. $pterodactyl->expects(self::once())->method('getUser')->willReturn($apiResponse);
  22. $this->app->instance(Pterodactyl::class, $pterodactyl);
  23. $this->artisan('make:user')
  24. ->expectsQuestion('Please specify your Pterodactyl ID.', 0)
  25. ->expectsQuestion('Please specify your password.', 'password')
  26. ->assertExitCode($expectedExitCode);
  27. }
  28. public function invalidPteroIdDataProvider(): array
  29. {
  30. return [
  31. 'Good Response' => [
  32. 'apiResponse' => [
  33. 'id' => 12345,
  34. 'first_name' => 'Test',
  35. 'email' => 'test@test.test',
  36. ],
  37. 'expectedExitCode' => 1,
  38. ],
  39. 'Bad Response' => [
  40. 'apiResponse' => [],
  41. 'expectedExitCode' => 0,
  42. ],
  43. ];
  44. }
  45. }