SnapshotCest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. class SnapshotCest
  3. {
  4. public function _openSnapshotSuite(CliGuy $I)
  5. {
  6. $I->amInPath('tests/data/snapshots');
  7. }
  8. /**
  9. * @before _openSnapshotSuite
  10. * @param CliGuy $I
  11. */
  12. public function runAllSnapshotTests(CliGuy $I)
  13. {
  14. $I->executeCommand('run tests/SnapshotDataCest.php');
  15. $I->seeInShellOutput('OK (3 tests');
  16. $I->seeInShellOutput('Load snapshot and skip refresh');
  17. $I->seeInShellOutput('Load snapshot and refresh');
  18. }
  19. /**
  20. * @before _openSnapshotSuite
  21. * @param CliGuy $I
  22. */
  23. public function runSnapshotRefresh(CliGuy $I)
  24. {
  25. $I->executeCommand('run tests/SnapshotDataCest.php:loadSnapshotAndRefresh --debug --no-colors');
  26. $I->seeInShellOutput('Snapshot\UserSnapshot: assert');
  27. $I->seeInShellOutput('I grab column from database');
  28. $I->seeInShellOutput('Snapshot assertion failed');
  29. $I->seeInShellOutput('Snapshot data updated');
  30. }
  31. /**
  32. * @before _openSnapshotSuite
  33. * @param CliGuy $I
  34. */
  35. public function runSnapshotRefreshFail(CliGuy $I)
  36. {
  37. $I->executeCommand('run tests/SnapshotDataCest.php:loadSnapshotAndSkipRefresh --debug --no-colors');
  38. $I->seeInShellOutput('Snapshot\UserSnapshot: assert');
  39. $I->seeInShellOutput('I grab column from database');
  40. $I->seeInShellOutput('Snapshot assertion failed');
  41. $I->dontSeeInShellOutput('Snapshot data updated');
  42. }
  43. /**
  44. * @before _openSnapshotSuite
  45. * @param CliGuy $I
  46. */
  47. public function loadSnapshotInDebugAndFailOnProd(CliGuy $I)
  48. {
  49. $I->executeCommand('run tests/SnapshotFailCest.php --debug');
  50. $I->seeInShellOutput('PASSED');
  51. $I->executeCommand('run tests/SnapshotFailCest.php --no-exit');
  52. $I->seeInShellOutput('FAILURES');
  53. $I->seeInShellOutput('Snapshot doesn\'t match real data');
  54. }
  55. public function generateGlobalSnapshot(CliGuy\GeneratorSteps $I)
  56. {
  57. $I->amInPath('tests/data/sandbox');
  58. $I->executeCommand('generate:snapshot Login');
  59. $I->seeFileWithGeneratedClass('Login', 'tests/_support/Snapshot');
  60. $I->dontSeeInThisFile('public function __construct(\DumbGuy $I)');
  61. $I->seeFileFound('tests/_bootstrap.php');
  62. }
  63. public function generateSuiteSnapshot(CliGuy\GeneratorSteps $I)
  64. {
  65. $I->amInPath('tests/data/sandbox');
  66. $I->executeCommand('generate:snapshot dummy Login');
  67. $I->seeFileWithGeneratedClass('Login', 'tests/_support/Snapshot/Dummy');
  68. $I->seeInThisFile('namespace Snapshot\\Dummy;');
  69. $I->seeInThisFile('class Login');
  70. $I->seeInThisFile('protected $dumbGuy;');
  71. $I->seeInThisFile('public function __construct(\DumbGuy $I)');
  72. }
  73. public function generateGlobalSnapshotInDifferentPath(CliGuy\GeneratorSteps $I)
  74. {
  75. $I->executeCommand('generate:snapshot Login -c tests/data/sandbox');
  76. $I->amInPath('tests/data/sandbox');
  77. $I->seeFileWithGeneratedClass('Login', 'tests/_support/Snapshot');
  78. $I->dontSeeInThisFile('public function __construct(\DumbGuy $I)');
  79. $I->seeFileFound('tests/_bootstrap.php');
  80. }
  81. }