SFTPTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. use Codeception\Util\Stub;
  3. /**
  4. * Module for testing remote ftp systems.
  5. *
  6. * ## Status
  7. *
  8. * Maintainer: **nathanmac**
  9. * Stability: **stable**
  10. * Contact: nathan.macnamara@outlook.com
  11. *
  12. */
  13. class SFTPTest extends \PHPUnit\Framework\TestCase
  14. {
  15. protected $config = array(
  16. 'host' => '127.0.0.1',
  17. 'port' => 22,
  18. 'tmp' => 'temp',
  19. 'user' => 'user',
  20. 'password' => 'password',
  21. 'type' => 'sftp'
  22. );
  23. /**
  24. * @var \Codeception\Module\FTP
  25. */
  26. protected $module = null;
  27. public function setUp()
  28. {
  29. $this->module = new \Codeception\Module\FTP(make_container());
  30. $this->module->_setConfig($this->config);
  31. $this->module->_before(Stub::makeEmpty('\Codeception\Test\Test'));
  32. }
  33. /**
  34. * Disabled Test - for travis testing, requires testing server
  35. */
  36. public function flow()
  37. {
  38. $this->assertEquals('/', $this->module->grabDirectory());
  39. $this->module->makeDir('TESTING');
  40. $this->module->amInPath('TESTING');
  41. $this->assertEquals('/TESTING', $this->module->grabDirectory());
  42. $files = $this->module->grabFileList();
  43. $this->module->writeToFile('test_ftp_123.txt', 'some data added here');
  44. $this->module->writeToFile('test_ftp_567.txt', 'some data added here');
  45. $this->module->writeToFile('test_ftp_678.txt', 'some data added here');
  46. $files = $this->module->grabFileList();
  47. $this->assertContains('test_ftp_123.txt', $files);
  48. $this->assertContains('test_ftp_567.txt', $files);
  49. $this->assertContains('test_ftp_678.txt', $files);
  50. $this->module->seeFileFound('test_ftp_123.txt');
  51. $this->module->dontSeeFileFound('test_ftp_321.txt');
  52. $this->module->seeFileFoundMatches('/^test_ftp_([0-9]{3}).txt$/');
  53. $this->module->dontSeeFileFoundMatches('/^test_([0-9]{3})_ftp.txt$/');
  54. $this->assertGreaterThan(0, $this->module->grabFileCount());
  55. $this->assertGreaterThan(0, $this->module->grabFileSize('test_ftp_678.txt'));
  56. $this->assertGreaterThan(0, $this->module->grabFileModified('test_ftp_678.txt'));
  57. $this->module->openFile('test_ftp_567.txt');
  58. $this->module->deleteThisFile();
  59. $this->module->dontSeeFileFound('test_ftp_567.txt');
  60. $this->module->openFile('test_ftp_123.txt');
  61. $this->module->seeInThisFile('data');
  62. $this->module->dontSeeInThisFile('banana');
  63. $this->module->seeFileContentsEqual('some data added here');
  64. $this->module->renameFile('test_ftp_678.txt', 'test_ftp_987.txt');
  65. $files = $this->module->grabFileList();
  66. $this->assertNotContains('test_ftp_678.txt', $files);
  67. $this->assertContains('test_ftp_987.txt', $files);
  68. $this->module->deleteFile('test_ftp_123.txt');
  69. $files = $this->module->grabFileList();
  70. $this->assertNotContains('test_ftp_123.txt', $files);
  71. $this->module->amInPath('/');
  72. $this->assertEquals('/', $this->module->grabDirectory());
  73. $this->module->renameDir('TESTING', 'TESTING_NEW');
  74. $this->module->deleteDir('TESTING_NEW');
  75. // Test Clearing the Directory
  76. $this->module->makeDir('TESTING');
  77. $this->module->amInPath('TESTING');
  78. $this->module->writeToFile('test_ftp_123.txt', 'some data added here');
  79. $this->module->amInPath('/');
  80. $this->assertGreaterThan(0, $this->module->grabFileCount('TESTING'));
  81. $this->module->cleanDir('TESTING');
  82. $this->assertEquals(0, $this->module->grabFileCount('TESTING'));
  83. $this->module->deleteDir('TESTING');
  84. }
  85. public function tearDown()
  86. {
  87. $this->module->_after(Stub::makeEmpty('\Codeception\Test\Test'));
  88. }
  89. }