public function get(Request $request) { $filePath = dirname(__FILE__) . '/../../../tests/files/test4.csv'; $error = null; try { $response = CSVFileService::uploadCSV($filePath); } catch (GuzzleException $e) { if ($e->getResponse() != null && $e->getResponse()->getBody() != null) { $error = json_decode($e->getResponse()->getBody()->getContents()); } else { $error = new \StdClass(); $error->code = $e->getCode(); $error->message = $e->getMessage(); $trace = null; if ($e->getTrace()) { $trace = array_map(function ($curr) { $node = new \StdClass(); if (isset($curr['file'])) { $node->file = $curr['file']; } if (isset($curr['line'])) { $node->line = $curr['line']; } if (isset($curr['function'])) { $node->function = $curr['function']; } if (isset($curr['class'])) { $node->class = $curr['class']; } return $node; }, $e->getTrace()); } $error->trace = $trace; } $response = null; } $updatedNumber = 0; $createdNumber = 0; if ($response) { foreach ($response as $person) { $updated = strtotime($person->updated_at->date); $created = strtotime($person->created_at->date); if ($updated != $created) { $person->uploadStatus = 'updated'; $updatedNumber++; } else { $person->uploadStatus = 'created'; $createdNumber++; } } } return view('home', array('results' => $response, 'updated' => $updatedNumber, 'created' => $createdNumber, 'error' => $error)); }
/** * Opens the csv and make assertions. * * @param String $filePath * * @return resource **/ private function assertOpenCSV($filePath) { $filePointer = CSVFileService::getFilePointer($filePath); $this->assertNotNull($filePointer); $this->assertInternalType('resource', $filePointer); return $filePointer; }