ImportTrait.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. trait ImportTrait {
  3. /**
  4. * Test csv file
  5. * @var [type]
  6. */
  7. protected $file;
  8. /**
  9. * Loaded csv file
  10. * @var [type]
  11. */
  12. protected $loadedFile;
  13. /**
  14. * Setup
  15. */
  16. public function setUp()
  17. {
  18. parent::setUp();
  19. // Set default heading
  20. Config::set('excel.import.heading', 'slugged');
  21. // Set excel class
  22. $this->excel = App::make('phpexcel');
  23. // Set writer class
  24. $this->reader = App::make('excel.reader');
  25. $this->reader->injectExcel($this->excel);
  26. // Disable heading usage
  27. if(isset($this->noHeadings) && $this->noHeadings)
  28. $this->reader->noHeading(true);
  29. // Load csv file
  30. $this->loadFile();
  31. }
  32. /**
  33. * Test loading a csv file
  34. * @return [type] [description]
  35. */
  36. public function testLoadFile()
  37. {
  38. $this->assertEquals($this->reader, $this->loadedFile);
  39. $this->assertInstanceOf('PHPExcel', $this->reader->getExcel());
  40. }
  41. /**
  42. * Load a csv file
  43. * @return [type] [description]
  44. */
  45. protected function loadFile()
  46. {
  47. // Set test csv file
  48. $this->file = __DIR__ . '/..' . DIRECTORY_SEPARATOR . $this->fileName;
  49. // Loaded csv
  50. $this->loadedFile = $this->reader->load($this->file);
  51. }
  52. /**
  53. * Load a csv file
  54. * @return [type] [description]
  55. */
  56. protected function reload()
  57. {
  58. // Set test csv file
  59. $this->file = __DIR__ . '/..' . DIRECTORY_SEPARATOR . $this->fileName;
  60. // Loaded csv
  61. return $this->reader->load($this->file);
  62. }
  63. }