【问题标题】:How to test Api Restful on Laravel with phpspec如何使用 phpspec 在 Laravel 上测试 Api Restful
【发布时间】:2016-02-22 09:19:03
【问题描述】:

我正在使用 PhpSpec 来测试应用程序 Laravel 框架。 如何在文件路由上测试 Api Restful 并像使用 PHPUnit 一样发布数据。

例子:

$res = $this->call('POST', '/articles', [
        'alias'       => 'This is invalid alias',
        'order'       => 'invalid',
    ],[],[], []);

【问题讨论】:

    标签: php laravel phpspec


    【解决方案1】:

    你没有。 PhpSpec 用于单元测试,而您要编写的是集成测试。

    来自introduction to PhpSpec

    [...] 该技术是首先使用 phpspec 之类的工具来描述您将要编写的对象的行为。接下来,您编写刚好满足该规范的代码,最后重构此代码。

    使用其他工具进行集成测试。 PHPUnit 非常适合这种测试(尽管它的名称中有“单元”)。

    【讨论】:

      【解决方案2】:

      定义路由宁静

          route::resource('articles', 'ArticleController');
      

      并定义控制器

       `php artisan make:controller ArticleController`
      

      终于可以看到自己的路线了

      php artisan route:list
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-25
        • 2023-03-24
        • 2021-06-08
        • 2015-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-10
        相关资源
        最近更新 更多