public function testStoreWithReplyAndStatusClosed()
 {
     $this->ticket_model = factory(App\Ticket::class)->make(['id' => $this->faker->randomNumber]);
     $request = new TicketStoreRequest(['user_id' => 12, 'title' => $this->faker->sentence, 'body' => $this->faker->paragraph, 'reply_body' => $this->faker->sentence, 'status' => 'closed']);
     $dispatch_request = $request->instance();
     $dispatch_request->merge(['auth_id' => auth()->user()->id]);
     $dispatcher = m::mock('Illuminate\\Bus\\Dispatcher[dispatchFrom]', [$this->app]);
     $dispatcher->shouldReceive('dispatchFrom')->once()->with('App\\Jobs\\TicketCreateJob', $dispatch_request, [])->andReturn($this->ticket_model);
     $dispatcher->shouldReceive('dispatchFrom')->once()->with('App\\Jobs\\ActionCreateJob', m::on(function ($param) {
         return empty(array_diff($param->toArray(), ['ticket_id' => $this->ticket_model->id, 'user_id' => $this->user_model->id, 'hours' => null, 'time_at' => null, 'status' => 'closed', 'defer_event' => true]));
     }), m::on(function ($param) use($request) {
         return empty(array_diff($param, ['type' => 'closed', 'body' => $request->get('reply_body')]));
     }));
     $this->app->instance('Illuminate\\Contracts\\Bus\\Dispatcher', $dispatcher);
     $controller = new TicketsController($this->ticket, $this->user);
     $controller->store($request);
 }
Пример #2
0
 public function store(TicketStoreRequest $request)
 {
     if (!$request->has('user_id')) {
         $user = $this->user->create(['display_name' => $request->input('display_name'), 'email' => $request->input('email'), 'username' => preg_replace("/[^a-zA-Z0-9]/", "", $request->input('display_name')) . rand(10000, 99990)]);
         $request->merge(['user_id' => $user->id]);
     }
     $request->merge(['auth_id' => auth()->user()->id]);
     $ticket = $this->dispatchFrom('App\\Jobs\\TicketCreateJob', $request);
     $action = collect(['ticket_id' => $ticket->id, 'user_id' => auth()->user()->id, 'hours' => $request->get('hours'), 'time_at' => $request->has('time_at') ? Carbon::createFromFormat('m/d/Y', $request->get('time_at'), auth()->user()->tz)->timezone('utc') : null, 'status' => $request->has('status') ? $request->get('status') : 'open', 'defer_event' => true]);
     if ($request->has('reply_body')) {
         $this->dispatchFrom('App\\Jobs\\ActionCreateJob', $action, ['type' => in_array($request->get('status'), ['closed', 'resolved']) ? $request->get('status') : 'reply', 'body' => $request->get('reply_body')]);
         $action->put('hours', 0);
     }
     if ($request->has('comment_body')) {
         $this->dispatchFrom('App\\Jobs\\ActionCreateJob', $action, ['type' => 'comment', 'body' => $request->get('comment_body')]);
     }
     return redirect()->route('tickets.show', [$ticket['id']])->with('message', 'Ticket #' . $ticket['id'] . ' sucessfully created.');
 }