SmsControllerTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of ibrand/laravel-sms.
  4. *
  5. * (c) iBrand <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace iBrand\Sms\Test;
  11. class SmsControllerTest extends \Orchestra\Testbench\TestCase
  12. {
  13. /**
  14. * @param \Illuminate\Foundation\Application $app
  15. *
  16. * @return array
  17. */
  18. protected function getPackageProviders($app)
  19. {
  20. return ['iBrand\Sms\ServiceProvider'];
  21. }
  22. /**
  23. * @param \Illuminate\Foundation\Application $app
  24. *
  25. * @return array
  26. */
  27. protected function getPackageAliases($app)
  28. {
  29. return [
  30. 'Sms' => "iBrand\Sms\Facade",
  31. ];
  32. }
  33. public function testPostSendCode()
  34. {
  35. //1. test success mobile.
  36. $response = $this->post('sms/verify-code', ['mobile' => '18973305743']);
  37. $response
  38. ->assertStatus(200)
  39. ->assertJson(['success' => true, 'message' => '短信发送成功']);
  40. //2. test repeat in 60 seconds.
  41. $response = $this->post('sms/verify-code', ['mobile' => '18973305743']);
  42. $response
  43. ->assertStatus(200)
  44. ->assertJson(['success' => false, 'message' => '每60秒发送一次']);
  45. //3. test invalid mobile.
  46. $response = $this->post('sms/verify-code', ['mobile' => '10000000000']);
  47. $response
  48. ->assertStatus(200)
  49. ->assertJson(['success' => false, 'message' => '无效手机号码']);
  50. }
  51. public function testInfo()
  52. {
  53. $response = $this->get('sms/info?mobile=18988885555');
  54. $response
  55. ->assertStatus(200);
  56. }
  57. public function testDebug()
  58. {
  59. $this->app['config']->set('app.debug', true);
  60. $response = $this->get('sms/info?mobile=18988885555');
  61. $response
  62. ->assertStatus(200);
  63. }
  64. }