duandu5846 2014-03-10 14:38
浏览 40
已采纳

Laravel路线和控制器测试

so I am trying to test some routes and controller functions that I have created. The other routes that return views work fine, and I was told by my professor that I could test the routes by just putting a vardump in the controller function they are pointing to.

Now, this doesn't really make sense to me, because the functions never return any view or ui data, they just return JSON responses.

Am I correct that there is no way to test routes like that using vardumps? Just confused here.

  • 写回答

1条回答 默认 最新

  • dqy0707 2014-03-10 15:57
    关注

    When developing REST API's with Laravel (which I tend to return JSON from by default), I use the Postman client for testing. A var_dump() is pretty ugly when looking at the response if you have xdebug installed (which I do), so I tend to use print_r instead.

    For example, just this morning testing something out, I added this line in my controller:

    print_r($files); exit;
    

    And this is what postman showed me:

    enter image description here

    You can also use var_dump if you choose to. If you don't include an exit() statement, the application will continue to run and depending and how you have things setup, you may get more than you were looking for. For me, it is just easier to dump what I need and stop the application so I can quickly see what I need to.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计