LogFileReadTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Dotdigitalgroup\Email\Helper;
  3. use Magento\TestFramework\ObjectManager;
  4. class LogFileReadTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @var string
  8. */
  9. public $pathLogfile = '';
  10. /**
  11. * @var \Dotdigitalgroup\Email\Helper\File
  12. */
  13. public $fileHelper;
  14. /**
  15. * @var \Magento\TestFramework\ObjectManager
  16. */
  17. public $objectManager;
  18. /**
  19. * @var \Dotdigitalgroup\Email\Helper\Data
  20. */
  21. public $helper;
  22. /**
  23. * @return void
  24. */
  25. public function setup()
  26. {
  27. $this->objectManager = ObjectManager::getInstance();
  28. /** @var \Dotdigitalgroup\Email\Helper\File $helper */
  29. $this->fileHelper = $this->objectManager->get(\Dotdigitalgroup\Email\Helper\File::class);
  30. $this->helper = $this->objectManager->get(\Dotdigitalgroup\Email\Helper\Data::class);
  31. }
  32. /**
  33. * @return void
  34. */
  35. public function testFileExistsAndContentContainsMessage()
  36. {
  37. $this->helper->log('logged message data');
  38. $content = $this->fileHelper->getLogFileContent();
  39. $this->assertContains('logged message', $content);
  40. }
  41. /**
  42. * @return void
  43. */
  44. public function testDebugLogContainsDataMessage()
  45. {
  46. $this->helper->debug('Dummy Title', ['mesage dummy text']);
  47. $this->assertContains('dummy text', $this->fileHelper->getLogFileContent());
  48. }
  49. /**
  50. * @return void
  51. */
  52. public function testEmptyLogFileReturnsNoError()
  53. {
  54. $content = $this->fileHelper->getLogFileContent();
  55. $this->assertNotContains('Log file is not readable or does not exist at this moment', $content);
  56. }
  57. /**
  58. * @return void
  59. */
  60. public function testLogFileWithDataReturnsNoError()
  61. {
  62. $this->helper->log('SOME TEXT DATA');
  63. $content = $this->fileHelper->getLogFileContent();
  64. $this->assertNotContains('Log file is not readable or does not exist at this moment', $content);
  65. }
  66. }