PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/output/LimeOutputRawTest.php

http://github.com/bschussek/lime
PHP | 128 lines | 48 code | 39 blank | 41 comment | 0 complexity | f65e110fbe1bf29c56f39d742a60ee9f MD5 | raw file
Possible License(s): ISC
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. LimeAnnotationSupport::enable();
  12. $t = new LimeTest();
  13. // @Before
  14. $output = new LimeOutputRaw();
  15. ob_start();
  16. $output->focus('/test/file'); // do something to avoid the header being printed every test
  17. ob_end_clean();
  18. // @After
  19. $output = null;
  20. // @Test: focus() prints the method call as serialized array
  21. // test
  22. ob_start();
  23. $output->focus('/test/file');
  24. $result = ob_get_clean();
  25. // assertions
  26. $t->is($result, serialize(array('focus', array('/test/file')))."\n", 'The method call is serialized');
  27. // @Test: close() prints the method call as serialized array
  28. // test
  29. ob_start();
  30. $output->close();
  31. $result = ob_get_clean();
  32. // assertions
  33. $t->is($result, serialize(array('close', array()))."\n", 'The method call is serialized');
  34. // @Test: pass() prints the method call as serialized array
  35. // test
  36. ob_start();
  37. $output->pass('A passed test', 'Class', 100, '/test/file', 11);
  38. $result = ob_get_clean();
  39. // assertions
  40. $t->is($result, serialize(array('pass', array('A passed test', 'Class', 100, '/test/file', 11)))."\n", 'The method call is serialized');
  41. // @Test: fail() prints the method call as serialized array
  42. // test
  43. ob_start();
  44. $output->fail('A failed test', 'Class', 100, '/test/file', 11, new LimeError('A very important error', '/test/file', 11));
  45. $result = ob_get_clean();
  46. // assertions
  47. $t->is($result, serialize(array('fail', array('A failed test', 'Class', 100, '/test/file', 11, new LimeError('A very important error', '/test/file', 11))))."\n", 'The method call is serialized');
  48. // @Test: skip() prints the method call as serialized array
  49. // test
  50. ob_start();
  51. $output->skip('A skipped test', 'Class', 100, '/test/file', 11, 'Reason');
  52. $result = ob_get_clean();
  53. // assertions
  54. $t->is($result, serialize(array('skip', array('A skipped test', 'Class', 100, '/test/file', 11, 'Reason')))."\n", 'The method call is serialized');
  55. // @Test: todo() prints the method call as serialized array
  56. // test
  57. ob_start();
  58. $output->todo('A todo', 'Class', '/test/file', 11);
  59. $result = ob_get_clean();
  60. // assertions
  61. $t->is($result, serialize(array('todo', array('A todo', 'Class', '/test/file', 11)))."\n", 'The method call is serialized');
  62. // @Test: error() prints the method call as serialized array
  63. // test
  64. ob_start();
  65. $output->error($error = new LimeError('An error', '/test/file', 11));
  66. $result = ob_get_clean();
  67. // assertions
  68. $t->is($result, serialize(array('error', array($error)))."\n", 'The method call is serialized');
  69. // @Test: comment() prints the method call as serialized array
  70. // test
  71. ob_start();
  72. $output->comment('A comment');
  73. $result = ob_get_clean();
  74. // assertions
  75. $t->is($result, serialize(array('comment', array('A comment')))."\n", 'The method call is serialized');
  76. // @Test: flush() prints the method call as serialized array
  77. // test
  78. ob_start();
  79. $output->flush();
  80. $result = ob_get_clean();
  81. // assertions
  82. $t->is($result, serialize(array('flush', array()))."\n", 'The method call is serialized');
  83. // @Test: Strings in arguments are escaped
  84. // test
  85. ob_start();
  86. $output->comment("A \\n\\r comment \n with line \r breaks");
  87. $result = ob_get_clean();
  88. // assertions
  89. $t->is($result, serialize(array('comment', array('A \\n\\r comment \n with line \r breaks')))."\n", 'LFs and CRs are escaped');