SetupTeardown.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Worksheet\Table;
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  5. use PHPUnit\Framework\TestCase;
  6. class SetupTeardown extends TestCase
  7. {
  8. /**
  9. * @var ?Spreadsheet
  10. */
  11. private $spreadsheet;
  12. /**
  13. * @var ?Worksheet
  14. */
  15. private $sheet;
  16. /**
  17. * @var int
  18. */
  19. protected $maxRow = 4;
  20. protected function tearDown(): void
  21. {
  22. $this->sheet = null;
  23. if ($this->spreadsheet !== null) {
  24. $this->spreadsheet->disconnectWorksheets();
  25. $this->spreadsheet = null;
  26. }
  27. }
  28. protected function getSpreadsheet(): Spreadsheet
  29. {
  30. if ($this->spreadsheet !== null) {
  31. return $this->spreadsheet;
  32. }
  33. $this->spreadsheet = new Spreadsheet();
  34. return $this->spreadsheet;
  35. }
  36. protected function getSheet(): Worksheet
  37. {
  38. if ($this->sheet !== null) {
  39. return $this->sheet;
  40. }
  41. $this->sheet = $this->getSpreadsheet()->getActiveSheet();
  42. return $this->sheet;
  43. }
  44. }