ExcelTestCase.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. use Mockery as m;
  3. use Maatwebsite\Excel\Excel;
  4. use Illuminate\Filesystem\Filesystem;
  5. class ExcelTestCase extends PHPUnit_Framework_TestCase {
  6. /**
  7. * Mocks
  8. * @var [type]
  9. */
  10. public $phpexcel;
  11. public $reader;
  12. public $writer;
  13. public $excel;
  14. public $batch;
  15. /**
  16. * Setup test case
  17. */
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. // Set the mocks
  22. $this->setMocks();
  23. // Init our excel class
  24. $this->excel = new Excel($this->phpexcel, $this->reader, $this->writer);
  25. }
  26. /**
  27. * Test the constructor
  28. * @return [type] [description]
  29. */
  30. public function testConstructor()
  31. {
  32. $this->assertInstanceOf('Maatwebsite\Excel\Excel', $this->excel);
  33. }
  34. /**
  35. * Set the mocks
  36. */
  37. public function setMocks()
  38. {
  39. $this->mockPHPExcel();
  40. $this->mockReader();
  41. $this->mockWriter();
  42. $this->mockBatch();
  43. }
  44. /**
  45. * Mock PHPExcel class
  46. * @return [type] [description]
  47. */
  48. public function mockPHPExcel()
  49. {
  50. $this->phpexcel = m::mock('Maatwebsite\Excel\Classes\PHPExcel');
  51. $this->phpexcel->shouldReceive('getID');
  52. $this->phpexcel->shouldReceive('disconnectWorksheets');
  53. $this->phpexcel->shouldReceive('setDefaultProperties');
  54. }
  55. /**
  56. * Mock Reader class
  57. * @return [type] [description]
  58. */
  59. public function mockReader()
  60. {
  61. $this->reader = m::mock('Maatwebsite\Excel\Readers\LaravelExcelReader');
  62. $this->reader->shouldReceive('injectExcel')->with($this->phpexcel);
  63. $this->reader->shouldReceive('load');
  64. $this->reader->shouldReceive('setSelectedSheets');
  65. $this->reader->shouldReceive('setSelectedSheetIndices');
  66. $this->reader->shouldReceive('setFilters');
  67. }
  68. /**
  69. * Mock Writer class
  70. * @return [type] [description]
  71. */
  72. public function mockWriter()
  73. {
  74. $this->writer = m::mock('Maatwebsite\Excel\Writers\LaravelExcelWriter');
  75. $this->writer->shouldReceive('injectExcel')->with($this->phpexcel);
  76. $this->writer->shouldReceive('setTitle');
  77. $this->writer->shouldReceive('setFileName');
  78. $this->writer->shouldReceive('shareView')->andReturn($this->writer);
  79. }
  80. /**
  81. * Mock Writer class
  82. * @return [type] [description]
  83. */
  84. public function mockBatch()
  85. {
  86. $this->batch = m::mock('Maatwebsite\Excel\Readers\Batch');
  87. $this->batch->shouldReceive('start')->andReturn('foo');
  88. }
  89. /**
  90. * Teardown
  91. * @return [type] [description]
  92. */
  93. public function tearDown()
  94. {
  95. m::close();
  96. }
  97. }