【问题标题】:How to show the exact line of code in Lumen where error occured?如何在 Lumen 中显示发生错误的确切代码行?
【发布时间】:2017-05-16 10:21:58
【问题描述】:

我的测试中有语法错误。例如:

  /** @test **/
public function show_should_return_a_valid_book()
{
    $this
        ->get('/books/1')
        ->seeStatusCode(200)
        ->seeJson([
            'id' => 1,
            'title' => 'War of the Worlds',
            'description' => 'A science fiction masterpiece about martians invading London',
            'author' => 'H. G. Wells'
        ]);
    $data = json_decode($this->response->getContent(), true);
    $this-> assertArrayHasKey('created_at'), $data);
    $this-> assertArrayHasKey('updated_at'), $data);
}

这里我忘了把左括号放在最后两行。

如果我在 Laravel 中这样做,我会收到以下消息:

C:\phpcode\shopcart>phpunit PHP 解析错误:语法错误,C:\phpcode\shopcart\tests\Test 中的意外 ',' 第 33 行的 Test.php

解析错误:语法错误,C:\phpcode\shopcart\tests\TestTest 中出现意外的 ','。 第33行的php

这很好,因为我可以看到错误发生在哪里。

但说到 Lumen,我看到的只是:

C:\phpcode\lumenbook>phpunit

[Symfony\Component\Debug\Exception\FatalThrowableError] 解析错误:语法错误,意外','

如何在 Lumen 中获得更详细的内容?

【问题讨论】:

  • 你试过phpunit -vvv 吗?
  • 是但无济于事。阅读 phpunit 文档是我尝试的第一件事。

标签: php laravel lumen


【解决方案1】:

我已经编辑了一行

%projname%\symphony\debug\Exception\FatalErrorException.php

// $message = 'Parse error: '.$e->getMessage();

成为

$message = 'Parse error; ' .$e->getMessage() .' in file ' .$e->getFile() 
.'at line ' .$e->getLine();

不知道它是否是优雅的解决方案,但它现在有效。

【讨论】:

  • 知道了。如果我需要在命令行中直接查看问题,上述解决方案会很有帮助。最简单的方法就是查看 storage\logs\lumen.log 中究竟发生了什么
猜你喜欢
  • 1970-01-01
  • 2019-11-17
  • 2016-07-30
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多