CsvTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\File\Test\Unit;
  7. use Magento\Framework\Filesystem\Driver\File;
  8. /**
  9. * Test class for \Magento\Framework\File\Csv.
  10. */
  11. class CsvTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * Csv model
  15. *
  16. * @var \Magento\Framework\File\Csv
  17. */
  18. protected $_model;
  19. protected function setUp()
  20. {
  21. $this->_model = new \Magento\Framework\File\Csv(new File());
  22. }
  23. protected function tearDown()
  24. {
  25. unset($this->_model);
  26. }
  27. public function testSetLineLength()
  28. {
  29. $expected = 4;
  30. $this->_model->setLineLength($expected);
  31. $lineLengthProperty = new \ReflectionProperty(\Magento\Framework\File\Csv::class, '_lineLength');
  32. $lineLengthProperty->setAccessible(true);
  33. $actual = $lineLengthProperty->getValue($this->_model);
  34. $this->assertEquals($expected, $actual);
  35. }
  36. public function testSetDelimiter()
  37. {
  38. $this->assertInstanceOf(\Magento\Framework\File\Csv::class, $this->_model->setDelimiter(','));
  39. }
  40. public function testSetEnclosure()
  41. {
  42. $this->assertInstanceOf(\Magento\Framework\File\Csv::class, $this->_model->setEnclosure('"'));
  43. }
  44. /**
  45. * @expectedException \Exception
  46. * @expectedExceptionMessage File "FileNameThatShouldNotExist" does not exist
  47. */
  48. public function testGetDataFileNonExistent()
  49. {
  50. $file = 'FileNameThatShouldNotExist';
  51. $this->_model->getData($file);
  52. }
  53. }