Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $hook = new Webhook();
     $hook->url = $this->argument('url');
     $hook->event = $this->argument('event');
     try {
         $hook->save();
         $this->info('The webhook was saved successfully.');
         $this->info('Event: ' . $hook->event);
         $this->info('URL: ' . $hook->url);
     } catch (Exception $e) {
         $this->error("The webhook couldn't be added to the database " . $e->getMessage());
     }
 }
 public function testCanFilterWebhooks()
 {
     $webhook = new Webhook();
     $webhook->tenant_id = 1;
     $webhook->url = "http://test.foo/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 2;
     $webhook->url = "http://test.bar/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 3;
     $webhook->url = "http://test.baz/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $client = m::mock("GuzzleHttp\\Client");
     $client->shouldReceive("postAsync")->once();
     $client->shouldReceive("postAsync")->with("http://test.bar/saved", m::any());
     $config = m::mock("stdClass");
     $config->shouldReceive("get")->with("captain_hook.filter", null)->andReturn(function ($item) {
         return $item->tenant_id == 2;
     });
     $provider = $this->app->getProvider("Mpociot\\CaptainHook\\CaptainHookServiceProvider");
     $provider->setClient($client);
     $provider->setConfig($config);
     $obj = new TestModel();
     $obj->name = "Test";
     $obj->save();
 }