コード例 #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  *
  * @return mixed
  */
 public function record($request)
 {
     $route = Route::getCurrentRoute();
     list($namespace, $name) = explode('@', $route->getActionName());
     $record = CoverageRecord::RecordEntry('Route', $namespace, $name);
 }
コード例 #2
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     if (CoverageRun::getActiveRun()) {
         $this->error('Error: Active runs exists. Stop run before running report');
         return;
     }
     $run = CoverageRun::orderBy('created_at', 'DESC')->first();
     if (!$run) {
         $this->error('No run found');
         return;
     }
     $runIds = [];
     array_push($runIds, $run->id);
     $actions = [];
     foreach ($this->routes as $route) {
         $actions[$route->getActionName()] = 0;
     }
     $records = CoverageRecord::whereIn('coverage_run_id', $runIds)->where('category', '=', 'Route')->get();
     foreach ($records as $record) {
         $actionName = $record->namespace . '@' . $record->name;
         $actions[$actionName] = 1;
     }
     $total = count($actions);
     $covered = 0;
     ksort($actions);
     $ignoreRoutes = config('coverage.ignore_routes');
     $ignoreRoutes = $ignoreRoutes ? $ignoreRoutes : [];
     foreach ($actions as $actionName => $count) {
         if (!$count) {
             if ($actionName == 'Closure') {
                 continue;
             }
             if (in_array($actionName, $ignoreRoutes)) {
                 continue;
             }
             list($namespace, $name) = explode('@', $actionName);
             if ($name == 'missingMethod') {
                 $method = new ReflectionMethod($namespace, $name);
                 $has = $method->class == $namespace;
                 if (!$has) {
                     continue;
                 }
             }
             $this->comment('Uncovered action ' . $actionName);
         } else {
             ++$covered;
         }
     }
     $this->comment("Route Coverage {$covered}/{$total}");
     $ignoreViews = config('coverage.ignore_views');
     $ignoreViews = $ignoreViews ? $ignoreViews : [];
     $views = [];
     foreach (\Config::get('view.paths') as $folder) {
         $finder = \Symfony\Component\Finder\Finder::create()->in($folder);
         foreach ($finder->files() as $i) {
             $views[$i->getRelativePathname()] = 0;
         }
     }
     foreach (view()->getFinder()->getHints() as $hint => $paths) {
         foreach ($paths as $path) {
             $finder = \Symfony\Component\Finder\Finder::create()->in($path);
             foreach ($finder->files() as $i) {
                 $path = $hint . '::' . $i->getRelativePathname();
                 $views[$path] = 0;
             }
         }
     }
     $records = CoverageRecord::whereIn('coverage_run_id', $runIds)->where('category', '=', 'View')->get();
     foreach ($records as $record) {
         $views[$record->name] = 1;
     }
     foreach ($ignoreViews as $key) {
         unset($views[$key]);
     }
     $total = count($views);
     $covered = 0;
     ksort($views);
     foreach ($views as $actionName => $count) {
         if (!$count) {
             $this->comment('Uncovered view ' . $actionName);
         } else {
             ++$covered;
         }
     }
     $this->comment("View Coverage {$covered}/{$total}");
 }