How to use Task class

Best Atoum code snippet using Task

TasksController.php

Source:TasksController.php Github

copy

Full Screen

1<?php2namespace App\Http\Controllers\Api\Supervisor;3use App\models\Task;4use App\models\Employee;5use Illuminate\Http\Request;6use App\Http\Traits\GeneralTrait;7use App\Http\Controllers\Controller;8use Illuminate\Support\Facades\Auth;9class TasksController extends Controller10{11 use GeneralTrait;12 public function checkGuard()13 {14 if(Auth::guard('apiEmployees')->check())15 {return Auth::guard('apiEmployees');}16 elseif(Auth::guard('apiSupervisors')->check())17 {return Auth::guard('apiSupervisors');}18 else {return 'false';}19 20 }21 public function index()22 {23 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {24 return $this->returnError(401, 'enter valid token');25 }26 else {27 $employees = Employee::where('supervisor_id', $this->checkGuard()->id())->get();28 $tasks = [];29 foreach($employees as $employee)30 {31 $taskk = Task::where('support_type', 0)->where('support_id', $employee->id)->get();32 foreach($taskk as $task)33 {34 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;35 unset(36 $task->support_type,37 $task->support_id,38 $task->branch_id,39 $task->created_at,40 $task->updated_at,41 );42 if ($task->type == "0") {43 $type = 'صيانة';44 }45 else {46 $type = 'نظافة';47 }48 $task->type = $type;49 $task->employee = $employee->name;50 switch ($task->state) {51 case '1':52 $task->state = 'انتظار من العامل';53 break;54 case '2':55 $task->state = 'انتظار من المشرف';56 break;57 case '3':58 $task->state = 'مرفوضة من المشرف و في انتظار العامل';59 break; 60 61 case '4':62 $task->state = 'انتظار من المدير';63 break;64 case '5':65 $task->state = 'مقبولة';66 break;67 case '6':68 $task->state = 'مرفوض من المدير';69 break;70 case '7':71 $task->state = 'طلب مد وقت';72 break;73 case '8':74 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';75 break;76 case '9':77 $task->state = 'المشرف رفض مد الوقت';78 break;79 80 default:81 # code...82 break;83 }84 }85 $tasks = array_merge( $tasks, $taskk->toArray());86 }87 return $this->returndata(['tasks'], [$tasks], "return all tasks success" );88 }89 }90 91 public function new()92 {93 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {94 return $this->returnError(401, 'enter valid token');95 }96 else {97 $employees = Employee::where('supervisor_id', $this->checkGuard()->id())->get();98 $tasks = [];99 foreach($employees as $employee)100 {101 $taskk = Task::whereIn('state', ['2'])->where('support_type', 0)->where('support_id', $employee->id)->get();102 foreach($taskk as $task)103 {104 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;105 unset(106 $task->support_type,107 $task->support_id,108 $task->branch_id,109 $task->created_at,110 $task->updated_at,111 );112 if ($task->type == "0") {113 $type = 'صيانة';114 }115 else {116 $type = 'نظافة';117 }118 $task->type = $type;119 $task->employee = $employee->name;120 switch ($task->state) {121 case '1':122 $task->state = 'انتظار من العامل';123 break;124 case '2':125 $task->state = 'انتظار من المشرف';126 break;127 case '3':128 $task->state = 'مرفوضة من المشرف و في انتظار العامل';129 break; 130 131 case '4':132 $task->state = 'انتظار من المدير';133 break;134 case '5':135 $task->state = 'مقبولة';136 break;137 case '6':138 $task->state = 'مرفوض من المدير';139 break;140 case '7':141 $task->state = 'طلب مد وقت';142 break;143 case '8':144 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';145 break;146 case '9':147 $task->state = 'المشرف رفض مد الوقت';148 break;149 150 default:151 # code...152 break;153 }154 }155 $tasks = array_merge( $tasks, $taskk->toArray());156 }157 return $this->returndata(['tasks'], [$tasks], "return all tasks success" );158 }159 }160 public function denay()161 {162 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {163 return $this->returnError(401, 'enter valid token');164 }165 else {166 $employees = Employee::where('supervisor_id', $this->checkGuard()->id())->get();167 $tasks = [];168 foreach($employees as $employee)169 {170 $taskk = Task::where('state', '7')->where('support_type', 0)->where('support_id', $employee->id)->get();171 foreach($taskk as $task)172 {173 unset(174 $task->attach,175 $task->note,176 $task->support_type,177 $task->support_id,178 $task->branch_id,179 $task->created_at,180 $task->updated_at,181 );182 if ($task->type == "0") {183 $type = 'صيانة';184 }185 else {186 $type = 'نظافة';187 }188 $task->type = $type;189 $task->employee = $employee->name;190 switch ($task->state) {191 case '1':192 $task->state = 'انتظار من العامل';193 break;194 case '2':195 $task->state = 'انتظار من المشرف';196 break;197 case '3':198 $task->state = 'مرفوضة من المشرف و في انتظار العامل';199 break; 200 201 case '4':202 $task->state = 'انتظار من المدير';203 break;204 case '5':205 $task->state = 'مقبولة';206 break;207 case '6':208 $task->state = 'مرفوض من المدير';209 break;210 case '7':211 $task->state = 'طلب مد وقت';212 break;213 case '8':214 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';215 break;216 case '9':217 $task->state = 'المشرف رفض مد الوقت';218 break;219 220 default:221 # code...222 break;223 }224 }225 $tasks = array_merge( $tasks, $taskk->toArray());226 }227 return $this->returndata(['tasks'], [$tasks], "return all tasks success" );228 }229 }230 public function waiting()231 {232 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {233 return $this->returnError(401, 'enter valid token');234 }235 else {236 $employees = Employee::where('supervisor_id', $this->checkGuard()->id())->get();237 $tasks = [];238 foreach($employees as $employee)239 {240 $taskk = Task::where('state', '4')->where('support_type', 0)->where('support_id', $employee->id)->get();241 foreach($taskk as $task)242 {243 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;244 unset(245 $task->support_type,246 $task->support_id,247 $task->branch_id,248 $task->created_at,249 $task->updated_at,250 );251 if ($task->type == "0") {252 $type = 'صيانة';253 }254 else {255 $type = 'نظافة';256 }257 $task->type = $type;258 $task->employee = $employee->name;259 switch ($task->state) {260 case '1':261 $task->state = 'انتظار من العامل';262 break;263 case '2':264 $task->state = 'انتظار من المشرف';265 break;266 case '3':267 $task->state = 'مرفوضة من المشرف و في انتظار العامل';268 break; 269 270 case '4':271 $task->state = 'انتظار من المدير';272 break;273 case '5':274 $task->state = 'مقبولة';275 break;276 case '6':277 $task->state = 'مرفوض من المدير';278 break;279 case '7':280 $task->state = 'طلب مد وقت';281 break;282 case '8':283 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';284 break;285 case '9':286 $task->state = 'المشرف رفض مد الوقت';287 break;288 289 default:290 # code...291 break;292 }293 }294 $tasks = array_merge( $tasks, $taskk->toArray());295 }296 return $this->returndata(['tasks'], [$tasks], "return all tasks success" );297 }298 }299 public function waitingEmp()300 {301 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {302 return $this->returnError(401, 'enter valid token');303 }304 else {305 $employees = Employee::where('supervisor_id', $this->checkGuard()->id())->get();306 $tasks = [];307 foreach($employees as $employee)308 {309 $taskk = Task::whereIn('state', ['1', '8'])->where('support_type', 0)->where('support_id', $employee->id)->get();310 foreach($taskk as $task)311 {312 unset(313 $task->attach,314 $task->note,315 $task->support_type,316 $task->support_id,317 $task->branch_id,318 $task->created_at,319 $task->updated_at,320 );321 if ($task->type == "0") {322 $type = 'صيانة';323 }324 else {325 $type = 'نظافة';326 }327 $task->type = $type;328 $task->employee = $employee->name;329 switch ($task->state) {330 case '1':331 $task->state = 'انتظار من العامل';332 break;333 case '2':334 $task->state = 'انتظار من المشرف';335 break;336 case '3':337 $task->state = 'مرفوضة من المشرف و في انتظار العامل';338 break; 339 340 case '4':341 $task->state = 'انتظار من المدير';342 break;343 case '5':344 $task->state = 'مقبولة';345 break;346 case '6':347 $task->state = 'مرفوض من المدير';348 break;349 case '7':350 $task->state = 'طلب مد وقت';351 break;352 case '8':353 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';354 break;355 case '9':356 $task->state = 'المشرف رفض مد الوقت';357 break;358 359 default:360 # code...361 break;362 }363 }364 $tasks = array_merge( $tasks, $taskk->toArray());365 }366 return $this->returndata(['tasks'], [$tasks], "return all tasks success" );367 }368 }369 public function show($id)370 {371 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {372 return $this->returnError(401, 'enter valid token');373 }374 else {375 $task = Task::find($id);376 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;377 unset(378 $task->support_type,379 $task->support_id,380 $task->branch_id,381 $task->created_at,382 $task->updated_at,383 );384 if ($task->type == "0") {385 $type = 'صيانة';386 }387 else {388 $type = 'نظافة';389 }390 $task->type = $type;391 // $task->employee = $task->employee->name;392 switch ($task->state) {393 case '1':394 $task->state = 'انتظار من العامل';395 break;396 case '2':397 $task->state = 'انتظار من المشرف';398 break;399 case '3':400 $task->state = 'مرفوضة من المشرف و في انتظار العامل';401 break; 402 403 case '4':404 $task->state = 'انتظار من المدير';405 break;406 case '5':407 $task->state = 'مقبولة';408 break;409 case '6':410 $task->state = 'مرفوض من المدير';411 break;412 case '7':413 $task->state = 'طلب مد وقت';414 break;415 case '8':416 $task->state = 'المشرف وافق مد الوقت و في انتظار العامل';417 break;418 case '9':419 $task->state = 'المشرف رفض مد الوقت';420 break;421 422 default:423 # code...424 break;425 }426 return $this->returndata(['task'], [$task], "return task success" );427 }428 }429 public function TaskAccept($id)430 {431 432 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {433 return $this->returnError(401, 'enter valid token');434 }435 else {436 $task = Task::find($id);437 $task->update([438 'state' => '4',439 ]);440 }441 return $this->returnSuccessMessage('Task Accepted successfuly', 200);442 }443 public function renewTask(Request $request)444 {445 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {446 return $this->returnError(401, 'enter valid token');447 }448 else {449 $task = Task::find($request->id);450 $task->update([451 'date' => $request->date,452 'time' => $request->time,453 'period' => $request->period,454 'state' => '3',455 ]);456 }457 return $this->returnSuccessMessage('Task Refused and Renew successfuly', 200);458 }459 public function TaskDelayRefused($id)460 {461 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {462 return $this->returnError(401, 'enter valid token');463 }464 else {465 $task = Task::find($id);466 $task->update([467 'state' => '9',468 ]);469 }470 return $this->returnSuccessMessage('Task Refuced Delay successfuly', 200);471 }472 public function renewDelayTask(Request $request)473 {474 475 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {476 return $this->returnError(401, 'enter valid token');477 }478 else {479 $task = Task::find($request->id);480 $task->update([481 'date' => $request->date,482 'time' => $request->time,483 'period' => $request->period,484 'state' => '8',485 ]);486 }487 return $this->returnSuccessMessage('Task Accepted Delay successfuly', 200);488 }489 490////////////////////////////////////////////////////////////////////////491 public function taskNowTeam()492 {493 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {494 return $this->returnError(401, 'enter valid token');495 }496 else {497 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 1)->where('state', '1')->with('team')->get();498 foreach($tasks as $task)499 {500 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;501 unset(502 $task->team->created_at,503 $task->team->updated_at,504 $task->team->clean_mantanance_manager_id,505 $task->support_type,506 $task->support_id,507 $task->branch_id,508 $task->created_at,509 $task->updated_at,510 );511 if ($task->type == "0") {512 $type = 'صيانة';513 }514 else {515 $type = 'نظافة';516 }517 $task->type = $type;518 switch ($task->state) {519 case '1':520 $task->state = 'انتظار من العامل';521 break;522 case '2':523 $task->state = 'انتظار من المشرف';524 break;525 case '3':526 $task->state = 'مرفوضة من المشرف و في انتظار العامل';527 break; 528 529 case '4':530 $task->state = 'انتظار من المدير';531 break;532 case '5':533 $task->state = 'مقبولة';534 break;535 case '6':536 $task->state = 'مرفوض من المدير';537 break;538 case '7':539 $task->state = 'انتظار العامل بعد الرفض';540 break;541 542 default:543 # code...544 break;545 }546 547 }548 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );549 }550 551 }552 public function taskStoreTeam(Request $request)553 {554 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {555 return $this->returnError(401, 'enter valid token');556 }557 else {558 //2=> المشرف بعت المهمة للمديربتاعة الفريق559 $task = Task::find($request->id);560 $request->validate([561 'file' => 'required',562 ]);563 564 $title = time().'.'.request()->file->getClientOriginalExtension();565 566 $request->file->move(public_path('assets/attach'), $title);567 $task->update([568 'note' => $request->note,569 'attach' => $title,570 'state' => '4'571 ]);572 573 return $this->returnSuccessMessage('Task sent successfuly', 200);574 }575 }576 public function taskDoneTeam()577 {578 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {579 return $this->returnError(401, 'enter valid token');580 }581 else {582 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 1)->whereIn('state', ['5','6'])->with('team')->get();583 foreach($tasks as $task)584 {585 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;586 unset(587 $task->team->created_at,588 $task->team->updated_at,589 $task->team->clean_mantanance_manager_id,590 $task->support_type,591 $task->support_id,592 $task->branch_id,593 $task->created_at,594 $task->updated_at,595 );596 if ($task->type == "0") {597 $type = 'صيانة';598 }599 else {600 $type = 'نظافة';601 }602 $task->type = $type;603 switch ($task->state) {604 case '1':605 $task->state = 'انتظار من العامل';606 break;607 case '2':608 $task->state = 'انتظار من المشرف';609 break;610 case '3':611 $task->state = 'مرفوضة من المشرف و في انتظار العامل';612 break; 613 614 case '4':615 $task->state = 'انتظار من المدير';616 break;617 case '5':618 $task->state = 'مقبولة';619 break;620 case '6':621 $task->state = 'مرفوض من المدير';622 break;623 case '7':624 $task->state = 'انتظار العامل بعد الرفض';625 break;626 627 default:628 # code...629 break;630 }631 632 }633 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );634 }635 636 }637 public function taskWaitingTeam()638 {639 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {640 return $this->returnError(401, 'enter valid token');641 }642 else {643 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 1)->where('state', '4')->with('team')->get();644 foreach($tasks as $task)645 {646 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;647 unset(648 $task->team->created_at,649 $task->team->updated_at,650 $task->team->clean_mantanance_manager_id,651 $task->support_type,652 $task->support_id,653 $task->branch_id,654 $task->created_at,655 $task->updated_at,656 );657 if ($task->type == "0") {658 $type = 'صيانة';659 }660 else {661 $type = 'نظافة';662 }663 $task->type = $type;664 switch ($task->state) {665 case '1':666 $task->state = 'انتظار من العامل';667 break;668 case '2':669 $task->state = 'انتظار من المشرف';670 break;671 case '3':672 $task->state = 'مرفوضة من المشرف و في انتظار العامل';673 break; 674 675 case '4':676 $task->state = 'انتظار من المدير';677 break;678 case '5':679 $task->state = 'مقبولة';680 break;681 case '6':682 $task->state = 'مرفوض من المدير';683 break;684 case '7':685 $task->state = 'انتظار العامل بعد الرفض';686 break;687 688 default:689 # code...690 break;691 }692 693 }694 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );695 }696 697 }698 public function taskNowCompany()699 {700 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {701 return $this->returnError(401, 'enter valid token');702 }703 else {704 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 2)->where('state', '1')->with('company')->get();705 foreach($tasks as $task)706 {707 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;708 unset(709 $task->company->created_at,710 $task->company->updated_at,711 $task->company->clean_mantanance_manager_id,712 $task->support_type,713 $task->support_id,714 $task->branch_id,715 $task->created_at,716 $task->updated_at,717 );718 if ($task->type == "0") {719 $type = 'صيانة';720 }721 else {722 $type = 'نظافة';723 }724 $task->type = $type;725 switch ($task->state) {726 case '1':727 $task->state = 'انتظار من العامل';728 break;729 case '2':730 $task->state = 'انتظار من المشرف';731 break;732 case '3':733 $task->state = 'مرفوضة من المشرف و في انتظار العامل';734 break; 735 736 case '4':737 $task->state = 'انتظار من المدير';738 break;739 case '5':740 $task->state = 'مقبولة';741 break;742 case '6':743 $task->state = 'مرفوض من المدير';744 break;745 case '7':746 $task->state = 'انتظار العامل بعد الرفض';747 break;748 749 default:750 # code...751 break;752 }753 754 }755 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );756 }757 758 }759 public function taskStoreCompany(Request $request)760 {761 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {762 return $this->returnError(401, 'enter valid token');763 }764 else {765 //2=> المشرف بعت المهمة للمديربتاعة الفريق766 $task = Task::find($request->id);767 $request->validate([768 'file' => 'required',769 ]);770 771 $title = time().'.'.request()->file->getClientOriginalExtension();772 773 $request->file->move(public_path('assets/attach'), $title);774 $task->update([775 'note' => $request->note,776 'attach' => $title,777 'state' => '4'778 ]);779 780 return $this->returnSuccessMessage('Task sent successfuly', 200);781 }782 }783 public function taskDoneCompany()784 {785 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {786 return $this->returnError(401, 'enter valid token');787 }788 else {789 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 2)->whereIn('state', ['5','6'])->with('company')->get();790 foreach($tasks as $task)791 {792 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;793 unset(794 $task->company->created_at,795 $task->company->updated_at,796 $task->company->clean_mantanance_manager_id,797 $task->support_type,798 $task->support_id,799 $task->branch_id,800 $task->created_at,801 $task->updated_at,802 );803 if ($task->type == "0") {804 $type = 'صيانة';805 }806 else {807 $type = 'نظافة';808 }809 $task->type = $type;810 switch ($task->state) {811 case '1':812 $task->state = 'انتظار من العامل';813 break;814 case '2':815 $task->state = 'انتظار من المشرف';816 break;817 case '3':818 $task->state = 'مرفوضة من المشرف و في انتظار العامل';819 break; 820 821 case '4':822 $task->state = 'انتظار من المدير';823 break;824 case '5':825 $task->state = 'مقبولة';826 break;827 case '6':828 $task->state = 'مرفوض من المدير';829 break;830 case '7':831 $task->state = 'انتظار العامل بعد الرفض';832 break;833 834 default:835 # code...836 break;837 }838 839 }840 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );841 }842 843 }844 public function taskWaitingCompany()845 {846 if ($this->checkGuard() == 'false' || $this->checkGuard() == 'apiEmployees') {847 return $this->returnError(401, 'enter valid token');848 }849 else {850 $tasks = Task::where('branch_id', $this->checkGuard()->user()->cleanManager->branch->id)->where('support_type', 2)->where('state', '4')->with('company')->get();851 foreach($tasks as $task)852 {853 $task->attach = 'https://fixit4maint.com/assets/attach/' . $task->attach;854 unset(855 $task->company->created_at,856 $task->company->updated_at,857 $task->company->clean_mantanance_manager_id,858 $task->support_type,859 $task->support_id,860 $task->branch_id,861 $task->created_at,862 $task->updated_at,863 );864 if ($task->type == "0") {865 $type = 'صيانة';866 }867 else {868 $type = 'نظافة';869 }870 $task->type = $type;871 switch ($task->state) {872 case '1':873 $task->state = 'انتظار من العامل';874 break;875 case '2':876 $task->state = 'انتظار من المشرف';877 break;878 case '3':879 $task->state = 'مرفوضة من المشرف و في انتظار العامل';880 break; 881 882 case '4':883 $task->state = 'انتظار من المدير';884 break;885 case '5':886 $task->state = 'مقبولة';887 break;888 case '6':889 $task->state = 'مرفوض من المدير';890 break;891 case '7':892 $task->state = 'انتظار العامل بعد الرفض';893 break;894 895 default:896 # code...897 break;898 }899 900 }901 return $this->returndata(['Tasks'], [$tasks], "return all tasks success" );902 }903 904}905}...

Full Screen

Full Screen

TasksService.php

Source:TasksService.php Github

copy

Full Screen

1<?php2namespace Craft;3/**4 * Class TasksService5 *6 * @author Pixel & Tonic, Inc. <support@pixelandtonic.com>7 * @copyright Copyright (c) 2014, Pixel & Tonic, Inc.8 * @license http://craftcms.com/license Craft License Agreement9 * @see http://craftcms.com10 * @package craft.app.services11 * @since 2.012 */13class TasksService extends BaseApplicationComponent14{15 // Properties16 // =========================================================================17 /**18 * @var19 */20 private $_taskRecordsById;21 /**22 * @var23 */24 private $_nextPendingTask;25 /**26 * @var27 */28 private $_runningTask;29 /**30 * @var31 */32 private $_listeningForRequestEnd = false;33 // Public Methods34 // =========================================================================35 /**36 * Creates a task to run later in the system.37 *38 * @param string $type39 * @param string|null $description40 * @param array|null $settings41 * @param int|null $parentId42 *43 * @throws \Exception44 * @return TaskModel45 */46 public function createTask($type, $description = null, $settings = array(), $parentId = null)47 {48 $task = new TaskModel();49 $task->type = $type;50 $task->description = $description;51 $task->settings = $settings;52 $task->parentId = $parentId;53 $this->saveTask($task);54 if (!$this->_listeningForRequestEnd && craft()->config->get('runTasksAutomatically') && !$this->isTaskRunning() && !craft()->isConsole())55 {56 // Turn this request into a runner once everything else is done57 craft()->attachEventHandler('onEndRequest', array($this, 'handleRequestEnd'));58 $this->_listeningForRequestEnd = true;59 }60 return $task;61 }62 /**63 * Saves a task.64 *65 * @param TaskModel $task66 * @param bool $validate67 *68 * @return bool69 */70 public function saveTask(TaskModel $task, $validate = true)71 {72 if ($task->isNew())73 {74 $taskRecord = new TaskRecord();75 }76 else77 {78 try79 {80 $taskRecord = $this->_getTaskRecordById($task->id);81 }82 catch (\Exception $e)83 {84 // Maybe another task runner already beat us to it. Bail early.85 Craft::log('Tried to save an existing task with an ID of '.$task->id.', but it no longer exists.', LogLevel::Warning);86 return false;87 }88 }89 $taskRecord->type = $task->type;90 $taskRecord->status = $task->status;91 $taskRecord->settings = $task->settings;92 $taskRecord->description = $task->description;93 $taskRecord->totalSteps = $task->totalSteps;94 $taskRecord->currentStep = $task->currentStep;95 $taskRecord->dateUpdated = new DateTime();96 if (!$task->parentId || !$task->isNew())97 {98 $success = $taskRecord->saveNode($validate);99 }100 else101 {102 $parentTaskRecord = $this->_getTaskRecordById($task->parentId);103 $success = $taskRecord->appendTo($parentTaskRecord, $validate);104 }105 if ($success)106 {107 if ($task->isNew())108 {109 $task->id = $taskRecord->id;110 if ($task->parentId)111 {112 // We'll be needing this soon113 $this->_taskRecordsById[$taskRecord->id] = $taskRecord;114 }115 }116 return true;117 }118 $task->addErrors($taskRecord->getErrors());119 return false;120 }121 /**122 * Closes the connection with the client and turns the request into a task runner.123 *124 * @return null125 */126 public function closeAndRun()127 {128 // Make sure nothing has been output to the browser yet129 if (!headers_sent())130 {131 // Close the client connection132 craft()->request->close('1');133 // Run any pending tasks134 $this->runPendingTasks();135 }136 }137 /**138 * Re-runs a task by a given ID.139 *140 * @param int $taskId141 *142 * @return TaskModel|null143 */144 public function rerunTaskById($taskId)145 {146 $task = $this->getTaskById($taskId);147 if ($task && $task->level == 0)148 {149 $task->currentStep = null;150 $task->totalSteps = null;151 $task->status = TaskStatus::Pending;152 $this->saveTask($task);153 // Delete any of its subtasks154 $taskRecord = $this->_getTaskRecordById($taskId);155 $subtaskRecords = $taskRecord->descendants()->findAll();156 foreach ($subtaskRecords as $subtaskRecord)157 {158 $subtaskRecord->deleteNode();159 }160 return $task;161 }162 }163 /**164 * Runs any pending tasks.165 *166 * @return null167 */168 public function runPendingTasks()169 {170 // If we're already processing tasks, let's give it a break.171 if ($this->isTaskRunning())172 {173 Craft::log('Tasks are already running.', LogLevel::Info, true);174 return;175 }176 // It's go time.177 craft()->config->maxPowerCaptain();178 while ($task = $this->getNextPendingTask())179 {180 $this->_runningTask = $task;181 $this->runTask($task);182 }183 $this->_runningTask = null;184 }185 /**186 * Runs a given task.187 *188 * @param TaskModel $task189 *190 * @return bool191 */192 public function runTask(TaskModel $task)193 {194 $error = null;195 try196 {197 $taskRecord = $this->_getTaskRecordById($task->id);198 $taskType = $task->getTaskType();199 if ($taskType)200 {201 // Figure out how many total steps there are.202 $task->totalSteps = $taskType->getTotalSteps();203 $task->status = TaskStatus::Running;204 Craft::log('Starting task '.$taskRecord->type.' that has a total of '.$task->totalSteps.' steps.', LogLevel::Info, true);205 for ($step = 0; $step < $task->totalSteps; $step++)206 {207 // Update the task208 $task->currentStep = $step+1;209 $this->saveTask($task);210 Craft::log('Starting step '.($step+1).' of '.$task->totalSteps.' total steps.', LogLevel::Info, true);211 // Run it.212 if (($result = $taskType->runStep($step)) !== true)213 {214 // Did they give us an error to report?215 if (is_string($result))216 {217 $error = $result;218 }219 else220 {221 $error = true;222 }223 break;224 }225 }226 }227 else228 {229 $error = 'Could not find the task component type.';230 }231 }232 catch (\Exception $e)233 {234 $error = 'An exception was thrown: '.$e->getMessage();235 }236 if ($task == $this->_nextPendingTask)237 {238 // Don't run this again239 $this->_nextPendingTask = null;240 }241 if ($error === null)242 {243 Craft::log('Finished task '.$task->id.' ('.$task->type.').', LogLevel::Info, true);244 // We're done with this task, nuke it.245 $taskRecord->deleteNode();246 return true;247 }248 else249 {250 $this->fail($task, $error);251 return false;252 }253 }254 /**255 * Sets a task's status to "error" and logs it.256 *257 * @param TaskModel $task258 * @param mixed $error259 *260 * @return null261 */262 public function fail(TaskModel $task, $error = null)263 {264 $task->status = TaskStatus::Error;265 $this->saveTask($task);266 // Log it267 $logMessage = 'Encountered an error running task '.$task->id.' ('.$task->type.')';268 if ($task->currentStep)269 {270 $logMessage .= ', step '.$task->currentStep;271 if ($task->totalSteps)272 {273 $logMessage .= ' of '.$task->totalSteps;274 }275 }276 if ($error && is_string($error))277 {278 $logMessage .= ': '.$error;279 }280 else281 {282 $logMessage .= '.';283 }284 Craft::log($logMessage, LogLevel::Error);285 }286 /**287 * Returns a task by its ID.288 *289 * @param int $taskId290 *291 * @return TaskModel|null292 */293 public function getTaskById($taskId)294 {295 $result = craft()->db->createCommand()296 ->select('*')297 ->from('tasks')298 ->where('id = :id', array(':id' => $taskId))299 ->queryRow();300 if ($result)301 {302 return TaskModel::populateModel($result);303 }304 }305 /**306 * Returns all the tasks.307 *308 * @return TaskModel[]309 */310 public function getAllTasks()311 {312 $results = craft()->db->createCommand()313 ->select('*')314 ->from('tasks')315 ->order('root asc, lft asc')316 ->queryAll();317 return TaskModel::populateModels($results);318 }319 /**320 * Returns the currently running task.321 *322 * @return TaskModel|null323 */324 public function getRunningTask()325 {326 if (!isset($this->_runningTask))327 {328 $result = craft()->db->createCommand()329 ->select('*')330 ->from('tasks')331 ->where(332 array('and', 'lft = 1', 'status = :status'/*, 'dateUpdated >= :aMinuteAgo'*/),333 array(':status' => TaskStatus::Running/*, ':aMinuteAgo' => DateTimeHelper::formatTimeForDb('-1 minute')*/)334 )335 ->queryRow();336 if ($result)337 {338 $this->_runningTask = TaskModel::populateModel($result);339 }340 else341 {342 $this->_runningTask = false;343 }344 }345 if ($this->_runningTask)346 {347 return $this->_runningTask;348 }349 }350 /**351 * Returns whether there is a task that is currently running.352 *353 * @return bool354 */355 public function isTaskRunning()356 {357 // Remember that a root task could appear to be stagnant if it has sub-tasks.358 return (bool) craft()->db->createCommand()359 ->from('tasks')360 ->where(361 array('and','status = :status'/*, 'dateUpdated >= :aMinuteAgo'*/),362 array(':status' => TaskStatus::Running/*, ':aMinuteAgo' => DateTimeHelper::formatTimeForDb('-1 minute')*/)363 )364 ->count('id');365 }366 /**367 * Returns whether there are any pending tasks, optionally by a given type.368 *369 * @param string|null $type370 *371 * @return bool372 */373 public function areTasksPending($type = null)374 {375 $conditions = array('and', 'lft = 1', 'status = :status');376 $params = array(':status' => TaskStatus::Pending);377 if ($type)378 {379 $conditions[] = 'type = :type';380 $params[':type'] = $type;381 }382 return (bool) craft()->db->createCommand()383 ->from('tasks')384 ->where($conditions, $params)385 ->count('id');386 }387 /**388 * Returns any pending tasks, optionally by a given type.389 *390 * @param string|null $type391 * @param int|null $limit392 *393 * @return TaskModel[]394 */395 public function getPendingTasks($type = null, $limit = null)396 {397 $conditions = array('and', 'lft = 1', 'status = :status');398 $params = array(':status' => TaskStatus::Pending);399 if ($type)400 {401 $conditions[] = 'type = :type';402 $params[':type'] = $type;403 }404 $query = craft()->db->createCommand()405 ->from('tasks')406 ->where($conditions, $params);407 if ($limit)408 {409 $query->limit($limit);410 }411 $results = $query->queryAll();412 return TaskModel::populateModels($results);413 }414 /**415 * Returns whether any tasks that have failed.416 *417 * @return bool418 */419 public function haveTasksFailed()420 {421 return (bool) craft()->db->createCommand()422 ->from('tasks')423 ->where(array('and', 'level = 0', 'status = :status'), array(':status' => TaskStatus::Error))424 ->count('id');425 }426 /**427 * Returns the total number of active tasks.428 *429 * @return int430 */431 public function getTotalTasks()432 {433 return craft()->db->createCommand()434 ->from('tasks')435 ->where(436 array('and', 'lft = 1', 'status != :status'),437 array(':status' => TaskStatus::Error)438 )439 ->count('id');440 }441 /**442 * Returns the next pending task.443 *444 * @param string|null $type445 *446 * @return TaskModel|null|false447 */448 public function getNextPendingTask($type = null)449 {450 // If a type was passed, we don't need to actually save it, as it's probably not an actual task-running request.451 if ($type)452 {453 $pendingTasks = $this->getPendingTasks($type, 1);454 if ($pendingTasks)455 {456 return $pendingTasks[0];457 }458 }459 else460 {461 if (!isset($this->_nextPendingTask))462 {463 $taskRecord = TaskRecord::model()->roots()->ordered()->findByAttributes(array(464 'status' => TaskStatus::Pending465 ));466 if ($taskRecord)467 {468 $this->_taskRecordsById[$taskRecord->id] = $taskRecord;469 $this->_nextPendingTask = TaskModel::populateModel($taskRecord);470 }471 else472 {473 $this->_nextPendingTask = false;474 }475 }476 if ($this->_nextPendingTask)477 {478 return $this->_nextPendingTask;479 }480 }481 }482 /**483 * Deletes a task by its ID.484 *485 * @param int $taskId486 *487 * @return bool|null488 */489 public function deleteTaskById($taskId)490 {491 try492 {493 $taskRecord = $this->_getTaskRecordById($taskId);494 }495 catch (Exception $e)496 {497 Craft::log('Tried to delete a task with an ID of '.$taskId.', but it does not exist.', LogLevel::Warning);498 return false;499 }500 if ($taskRecord)501 {502 $success = $taskRecord->deleteNode();503 unset($this->_taskRecordsById[$taskId]);504 return $success;505 }506 }507 /**508 * Figure out how to initiate a new task runner.509 */510 public function handleRequestEnd()511 {512 // Make sure nothing has been output to the browser yet, and there's no pending response body513 if (!headers_sent() && !ob_get_length())514 {515 $this->closeAndRun();516 }517 // Is this a non-AJAX site request and are we responding with HTML or XHTML?518 // (CP requests don't need to be told to run pending tasks)519 else if (520 craft()->request->isSiteRequest() &&521 in_array(HeaderHelper::getMimeType(), array('text/html', 'application/xhtml+xml')) &&522 !craft()->request->isAjaxRequest()523 )524 {525 // Just output JS that tells the browser to fire an Ajax request to kick off task running526 $url = JsonHelper::encode(UrlHelper::getActionUrl('tasks/runPendingTasks'));527 // Ajax request code adapted from http://www.quirksmode.org/js/xmlhttp.html - thanks ppk!528 echo <<<EOT529<script type="text/javascript">530/*<![CDATA[*/531(function(){532 var XMLHttpFactories = [533 function () {return new XMLHttpRequest()},534 function () {return new ActiveXObject("Msxml2.XMLHTTP")},535 function () {return new ActiveXObject("Msxml3.XMLHTTP")},536 function () {return new ActiveXObject("Microsoft.XMLHTTP")}537 ];538 var req = false;539 for (var i = 0; i < XMLHttpFactories.length; i++) {540 try {541 req = XMLHttpFactories[i]();542 }543 catch (e) {544 continue;545 }546 break;547 }548 if (!req) return;549 req.open('GET', $url, true);550 if (req.readyState == 4) return;551 req.send();552})();553/*]]>*/554</script>555EOT;556 }557 }558 // Private Methods559 // =========================================================================560 /**561 * Returns a task by its ID.562 *563 * @param int $taskId564 *565 * @return TaskRecord|null566 * @throws Exception567 */568 private function _getTaskRecordById($taskId)569 {570 if (!isset($this->_taskRecordsById[$taskId]))571 {572 $taskRecord = TaskRecord::model()->findById($taskId);573 if (!$taskRecord)574 {575 throw new Exception('Could not find a task record with an ID of '.$taskId);576 }577 $this->_taskRecordsById[$taskId] = $taskRecord;578 }579 return $this->_taskRecordsById[$taskId] ?: null;580 }581}...

Full Screen

Full Screen

CollectionFactory.php

Source:CollectionFactory.php Github

copy

Full Screen

1<?php2declare(strict_types=1);3namespace OpenEuropa\TaskRunner\Tasks\CollectionFactory;4use OpenEuropa\TaskRunner;5use Robo\Contract\BuilderAwareInterface;6use Robo\Contract\SimulatedInterface;7use Robo\Exception\TaskException;8use Robo\LoadAllTasks;9use Robo\Task\BaseTask;10use Symfony\Component\Yaml\Yaml;11/**12 * Return a task collection given its array representation.13 */14class CollectionFactory extends BaseTask implements BuilderAwareInterface, SimulatedInterface15{16 use LoadAllTasks;17 use TaskRunner\Tasks\ProcessConfigFile\loadTasks;18 use \NuvoleWeb\Robo\Task\Config\Php\loadTasks;19 /**20 * @var array21 */22 protected $tasks;23 /**24 * Constructs a new CollectionFactory.25 *26 * @param array $tasks27 */28 public function __construct(array $tasks = [])29 {30 $this->tasks = $tasks;31 }32 /**33 * {@inheritdoc}34 */35 public function run()36 {37 $collection = $this->collectionBuilder();38 foreach ($this->getTasks() as $task) {39 $collection->addTask($this->taskFactory($task));40 }41 return $collection->run();42 }43 /**44 * {@inheritdoc}45 */46 public function simulate($context)47 {48 foreach ($this->getTasks() as $task) {49 if (is_array($task)) {50 $task = Yaml::dump($task, 0);51 }52 $this->printTaskInfo($task, $context);53 }54 }55 /**56 * @return array57 */58 public function getTasks()59 {60 return isset($this->tasks['tasks']) ? $this->tasks['tasks'] : $this->tasks;61 }62 /**63 * @return string64 */65 public function getHelp()66 {67 return isset($this->tasks['help']) ? $this->tasks['help'] : "Dynamic command defined in runner.yml";68 }69 /**70 * Returns the Robo task for a given task definition.71 *72 * For the moment this is a hardcoded mapping of supported tasks.73 *74 * @param array|string $task75 * A task definition array consisting of the task name and optionally a76 * number of configuration options. Can also be a string representing a77 * shell command.78 *79 * @return \Robo\Contract\TaskInterface80 * The Robo task.81 *82 * @throws \Robo\Exception\TaskException83 *84 * @SuppressWarnings(PHPMD)85 *86 * @todo: Turn this into a proper plugin system.87 */88 protected function taskFactory($task)89 {90 if (is_string($task)) {91 // @codingStandardsIgnoreLine92 $message = 'Defining a task as a plain text is deprecated in openeuropa/task-runner:1.0.0 and is removed from openeuropa/task-runner:2.0.0. Use the "exec" task and pass arguments and options.';93 @trigger_error($message, E_USER_DEPRECATED);94 return $this->taskExec($task)->interactive($this->isTtySupported());95 }96 // Set a number of options to safe defaults if they have not been given97 // a different value in the task definition.98 // @todo Not all of these options apply to all available tasks. Only99 // set defaults for this task's options.100 $this->secureOption($task, 'force', false);101 $this->secureOption($task, 'umask', 0000);102 $this->secureOption($task, 'recursive', false);103 $this->secureOption($task, 'time', time());104 $this->secureOption($task, 'atime', time());105 $this->secureOption($task, 'mode', 0755);106 switch ($task['task']) {107 case "mkdir":108 return $this->taskFilesystemStack()->mkdir($task['dir'], $task['mode']);109 case "touch":110 return $this->taskFilesystemStack()->touch($task['file'], $task['time'], $task['atime']);111 case "copy":112 if (is_dir($task['from'])) {113 return $this->taskCopyDir([$task['from'] => $task['to']]);114 }115 return $this->taskFilesystemStack()->copy($task['from'], $task['to'], $task['force']);116 case "chmod":117 return $this->taskFilesystemStack()118 ->chmod($task['file'], $task['permissions'], $task['umask'], $task['recursive']);119 case "chgrp":120 return $this->taskFilesystemStack()121 ->chgrp($task['file'], $task['group'], $task['recursive']);122 case "chown":123 return $this->taskFilesystemStack()124 ->chown($task['file'], $task['user'], $task['recursive']);125 case "remove":126 return $this->taskFilesystemStack()->remove($task['file']);127 case "rename":128 return $this->taskFilesystemStack()->rename($task['from'], $task['to'], $task['force']);129 case "symlink":130 return $this->taskFilesystemStack()->symlink($task['from'], $task['to']);131 case "mirror":132 return $this->taskFilesystemStack()->mirror($task['from'], $task['to']);133 case "process":134 return $this->taskProcessConfigFile($task['source'], $task['destination']);135 case "append":136 return $this->collectionBuilder()->addTaskList([137 $this->taskWriteToFile($task['file'])->append()->text($task['text']),138 $this->taskProcessConfigFile($task['file'], $task['file']),139 ]);140 case "run":141 $taskExec = $this->taskExec($this->getConfig()->get('runner.bin_dir') . '/run')142 ->arg($task['command'])143 ->interactive($this->isTtySupported());144 if (!empty($task['arguments'])) {145 $taskExec->args($task['arguments']);146 }147 if (!empty($task['options'])) {148 $taskExec->options($task['options'], '=');149 }150 return $taskExec;151 case "process-php":152 $this->secureOption($task, 'override', false);153 // If we don't override destination file simply exit here.154 if (!$task['override'] && file_exists($task['destination'])) {155 return $this->collectionBuilder();156 }157 // Copy source file to destination before processing it.158 $tasks[] = $this->taskFilesystemStack()->copy($task['source'], $task['destination'], true);159 // Map dynamic task type to actual task callback.160 $map = [161 'append' => "taskAppendConfiguration",162 'prepend' => "taskPrependConfiguration",163 'write' => "taskWriteConfiguration",164 ];165 if (!isset($map[$task['type']])) {166 // @codingStandardsIgnoreLine167 $message = "'process-php' task type '{$task['type']}' is not supported, valid values are: 'append', 'prepend' and 'write'.";168 throw new TaskException($this, $message);169 }170 $method = $map[$task['type']];171 // Add selected process task and return collection.172 $tasks[] = $this->{$method}($task['destination'], $this->getConfig())173 ->setConfigKey($task['config']);174 return $this->collectionBuilder()->addTaskList($tasks);175 case 'exec':176 $taskExec = $this->taskExec($task['command'])->interactive($this->isTtySupported());177 if (!empty($task['arguments'])) {178 $taskExec->args($task['arguments']);179 }180 if (!empty($task['options'])) {181 $taskExec->options($task['options']);182 }183 if (!empty($task['dir'])) {184 $taskExec->dir($task['dir']);185 }186 return $taskExec;187 default:188 throw new TaskException($this, "Task '{$task['task']}' not supported.");189 }190 }191 /**192 * Sets the given safe default value for the option with the given name.193 *194 * If the option is already set it will not be overwritten.195 *196 * @param array $task197 * The task array containing the task name and configuration.198 * @param string $name199 * The name of the option for which to provide a safe default value.200 * @param mixed $default201 * The default value.202 */...

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\test;2use \mageekguy\atoum\mock;3use \mageekguy\atoum\test;4use \mageekguy\atoum\mock;5use \mageekguy\atoum\test;6use \mageekguy\atoum\mock;7use \mageekguy\atoum\test;8use \mageekguy\atoum\mock;9use \mageekguy\atoum\test;10use \mageekguy\atoum\mock;11use \mageekguy\atoum\test;12use \mageekguy\atoum\mock;13use \mageekguy\atoum\test;14use \mageekguy\atoum\mock;15use \mageekguy\atoum\test;16use \mageekguy\atoum\mock;17use \mageekguy\atoum\test;18use \mageekguy\atoum\mock;19use \mageekguy\atoum\test;20use \mageekguy\atoum\mock;21use \mageekguy\atoum\test;22use \mageekguy\atoum\mock;23use \mageekguy\atoum\test;24use \mageekguy\atoum\mock;25use \mageekguy\atoum\test;26use \mageekguy\atoum\mock;27use \mageekguy\atoum\test;

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1$task = new Task();2$task->run();3$task = new Task();4$task->run();5$task = new Task();6$task->run();7$task = new Task();8$task->run();9$task = new Task();10$task->run();11$task = new Task();12$task->run();13$task = new Task();14$task->run();15$task = new Task();16$task->run();17$task = new Task();18$task->run();19$task = new Task();20$task->run();21$task = new Task();22$task->run();23$task = new Task();24$task->run();25$task = new Task();26$task->run();27$task = new Task();28$task->run();29$task = new Task();30$task->run();31$task = new Task();32$task->run();33$task = new Task();34$task->run();

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1use Atoum\Test;2use Atoum\Test\Units;3use Atoum\Test\Units\Task;4use Atoum\Test\Units\Task\Subtask;5use Atoum\Test\Units\Task\Subtask\Subsubtask;6use Atoum\Test\Units\Task\Subtask\Subsubtask\Subsubsubtask;7use Atoum\Test\Units\Task\Subtask\Subsubtask\Subsubsubtask\Subsubsubsubtask;8use Atoum\Test\Units\Task\Subtask\Subsubtask\Subsubsubtask\Subsubsubsubtask\Subsubsubsubsubtask;9use Atoum\Test\Units\Task\Subtask\Subsubtask\Subsubsubtask\Subsubsubsubtask\Subsubsubsubsubtask\Subsubsubsubsubsubtask;

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1include_once 'vendor/autoload.php';2use mageekguy\atoum\test;3use mageekguy\atoum\tests\units;4use mageekguy\atoum\report\fields\runner\failures\execute as failures;5use mageekguy\atoum\report\fields\runner\outputs\std as stdOut;6use mageekguy\atoum\report\fields\runner\outputs\std\error as stdErr;7use mageekguy\atoum\report\fields\runner\outputs\std\out as stdOut;8use mageekguy\atoum\report\fields\runner\outputs\std\error as stdErr;9use mageekguy\atoum\report\fields\runner\failures\execute as failures;10use mageekguy\atoum\report\fields\runner\failures\uncompleted as uncompleted;11use mageekguy\atoum\report\fields\runner\failures\exceptions as exceptions;12use mageekguy\atoum\report\fields\runner\failures\outputs as outputs;13use mageekguy\atoum\report\fields\runner\failures\diffs as diffs;14use mageekguy\atoum\report\fields\runner\failures\errors as errors;15use mageekguy\atoum\report\fields\runner\failures\exceptions as exceptions;16use mageekguy\atoum\report\fields\runner\failures\outputs as outputs;17use mageekguy\atoum\report\fields\runner\failures\diffs as diffs;18use mageekguy\atoum\report\fields\runner\failures\errors as errors;19use mageekguy\atoum\report\fields\runner\failures\exceptions as exceptions;20use mageekguy\atoum\report\fields\runner\failures\outputs as outputs;21use mageekguy\atoum\report\fields\runner\failures\diffs as diffs;22use mageekguy\atoum\report\fields\runner\failures\errors as errors;

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1use atoum\atoum;2use atoum\atoum;3$test = new atoum\test();4$task = new Task();5$task = new Task();6$test->object($task);

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1$task = new Task();2$task->setName('Atoum');3$task->setDescription('Atoum is a unit testing framework for PHP');4$task->setPriority(1);5$task->setDueDate(new DateTime('2014-12-31'));6$task->setComplete(true);7$task = new Task();8$task->setName('Atoum');9$task->setDescription('Atoum is a unit testing framework for PHP');10$task->setPriority(1);11$task->setDueDate(new DateTime('2014-12-31'));12$task->setComplete(true);13$task = new Task();14$task->setName('Atoum');15$task->setDescription('Atoum is a unit testing framework for PHP');16$task->setPriority(1);17$task->setDueDate(new DateTime('2014-12-31'));18$task->setComplete(true);19$task = new Task();20$task->setName('Atoum');21$task->setDescription('Atoum is a unit testing framework for PHP');22$task->setPriority(1);23$task->setDueDate(new DateTime('2014-12-31'));24$task->setComplete(true);25$task = new Task();26$task->setName('Atoum');27$task->setDescription('Atoum is a unit testing framework for PHP');28$task->setPriority(1);29$task->setDueDate(new DateTime('2014-12-31'));30$task->setComplete(true);31$task = new Task();32$task->setName('Atoum');33$task->setDescription('Atoum is a unit testing framework for PHP');34$task->setPriority(1);35$task->setDueDate(new DateTime('2014-12-31'));36$task->setComplete(true);37$task = new Task();38$task->setName('Atoum');

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2require_once 'src/MyClass.php';3{4 public function testMyMethod()5 {6 $myClass = new MyClass();7 ->string($myClass->myMethod())8 ->isEqualTo('foo');9 }10}11$test = new MyClassTest();12$test->run();

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\test;2use \mageekguy\atoum\asserters\phpString;3require_once 'class.php';4{5 public function testClassExist()6 {7 ->if($this->newTestedInstance())8 ->object($this->testedInstance)9 ->isInstanceOf('Task');10 }11 public function testGetId()12 {13 ->if($this->newTestedInstance())14 ->integer($this->testedInstance->getId())15 ->isIdenticalTo(0);16 }17 public function testSetId()18 {19 ->if($this->newTestedInstance())20 ->object($this->testedInstance->setId(5))21 ->isInstanceOf('Task')22 ->integer($this->testedInstance->getId())23 ->isIdenticalTo(5);24 }25 public function testGetTitle()26 {27 ->if($this->newTestedInstance())28 ->variable($this->testedInstance->getTitle())29 ->isNull();30 }31 public function testSetTitle()32 {33 ->if($this->newTestedInstance())34 ->object($this->testedInstance->setTitle('test'))35 ->isInstanceOf('Task')36 ->variable($this->testedInstance->getTitle())37 ->isIdenticalTo('test');38 }39 public function testGetDescription()40 {41 ->if($this->newTestedInstance())42 ->variable($this->testedInstance->getDescription())43 ->isNull();44 }45 public function testSetDescription()46 {47 ->if($this->newTestedInstance())48 ->object($this->testedInstance->setDescription('test'))49 ->isInstanceOf('Task')50 ->variable($this->testedInstance->getDescription())51 ->isIdenticalTo('test');52 }53 public function testGetDeadline()54 {55 ->if($this->newTestedInstance())56 ->variable($this->testedInstance->getDeadline())

Full Screen

Full Screen

Task

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2$task = new Atoum\Task();3$task->setName('test');4$task->setCreator('me');5$task->setPriority(1);6$task->setDueDate(new DateTime());7$task->setCompleted(true);8echo $task->getName();9echo $task->getCreator();10echo $task->getPriority();11echo $task->getDueDate();12echo $task->isCompleted();13require_once 'vendor/autoload.php';14$task = new Atoum\Task();15$task->setName('test');16$task->setCreator('me');17$task->setPriority(1);18$task->setDueDate(new DateTime());19$task->setCompleted(true);20echo $task->getName();21echo $task->getCreator();22echo $task->getPriority();23echo $task->getDueDate();24echo $task->isCompleted();25require_once 'vendor/autoload.php';26$task = new Atoum\Task();27$task->setName('test');28$task->setCreator('me');29$task->setPriority(1);30$task->setDueDate(new DateTime());31$task->setCompleted(true);32echo $task->getName();33echo $task->getCreator();34echo $task->getPriority();35echo $task->getDueDate();36echo $task->isCompleted();37require_once 'vendor/autoload.php';38$task = new Atoum\Task();39$task->setName('test');40$task->setCreator('me');41$task->setPriority(1);42$task->setDueDate(new DateTime());43$task->setCompleted(true);44echo $task->getName();45echo $task->getCreator();46echo $task->getPriority();47echo $task->getDueDate();48echo $task->isCompleted();49require_once 'vendor/autoload.php';50$task = new Atoum\Task();51$task->setName('test');52$task->setCreator('me');53$task->setPriority(1);54$task->setDueDate(new DateTime());55$task->setCompleted(true);56echo $task->getName();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful