微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 laravel-lighthouse 中进行 phpunit 订阅?

如何解决如何在 laravel-lighthouse 中进行 phpunit 订阅?

如何仅使用 PHP/PHPunit/Laravel 和 laravel-lighthouse GraphQL 库进行 PHPunit 订阅

我正在尝试为我的应用程序创建一个单元测试,该单元测试将订阅“hello world”订阅。此类测试的目的是断言订阅功能功能测试应该监听一个频道并断言接收到的消息包含相同的发布消息(发布在同一个 PHPunit 文件中)。

这是我目前所拥有的:

public function test_hello_world_build_subscription()
{

    $config = config('broadcasting.connections.pusher');
    $graphql = app(\Nuwave\Lighthouse\GraphQL::class);
    $context = app(\Nuwave\Lighthouse\Schema\Context::class);

    $result = $graphql->executeQuery('
        subscription BuildEvent($input: BuildEventInput!) {
          buildEvent (input: $input) {
            message
          }
        }
        ',$context,[
            'input' => [
                "uuid" => "0a53b12e-7ae0-4db1-a030-26a7ffdb1902",]
        ],);

    $channel = data_get($result,'extensions.lighthouse_subscriptions.channel');
    
    $pusher = new Pusher($config['key'],$config['secret'],$config['app_id'],[
        'host' => 'localhost','port' => 6001,'debug' => true,]);

    $pusher->trigger($channel,'App\Events\ExampleEvent','a hello world message');
    
}

我很高兴它有效并返回如下内容

GraphQL\Executor\ExecutionResult^ {#2045
  +data: array:1 [
    "buildEvent" => null
  ]
  +errors: []
  +extensions: array:1 [
    "lighthouse_subscriptions" => array:2 [
      "version" => 2
      "channel" => "private-lighthouse-0IIVzatBhabTtfEe33vp9ARBHGa1iP1y-1626402747"
    ]
  ]
  -errorFormatter: null
  -errorsHandler: null
}

但我不知道接下来要做什么。

文档没有谈论它。有人能指点我一个方向吗? 任何博客、git repo、教程等的链接将不胜感激。谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。