ReportTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\test;
  9. use lithium\test\Report;
  10. use lithium\test\Group;
  11. class ReportTest extends \lithium\test\Unit {
  12. public function testInit() {
  13. $report = new Report(array(
  14. 'title' => 'lithium\tests\mocks\test\MockUnitTest',
  15. 'group' => new Group(array('data' => array('lithium\tests\mocks\test\MockUnitTest')))
  16. ));
  17. $report->run();
  18. $expected = 'lithium\tests\mocks\test\MockUnitTest';
  19. $result = $report->title;
  20. $this->assertEqual($expected, $result);
  21. $expected = 'testNothing';
  22. $result = $report->results['group'][0][0]['method'];
  23. $this->assertEqual($expected, $result);
  24. $expected = 'pass';
  25. $result = $report->results['group'][0][0]['result'];
  26. $this->assertEqual($expected, $result);
  27. }
  28. public function testFilters() {
  29. $report = new Report(array(
  30. 'title' => 'lithium\tests\mocks\test\MockFilterClassTest',
  31. 'group' => new Group(
  32. array('data' => array('lithium\tests\mocks\test\MockFilterClassTest'))
  33. ),
  34. 'filters' => array("Complexity" => ""),
  35. 'format' => 'html'
  36. ));
  37. $expected = array('lithium\test\filter\Complexity' => array(
  38. 'name' => 'complexity', 'apply' => array(), 'analyze' => array()
  39. ));
  40. $result = $report->filters();
  41. $this->assertEqual($expected, $result);
  42. }
  43. public function testStats() {
  44. $report = new Report(array(
  45. 'title' => 'lithium\tests\mocks\test\MockUnitTest',
  46. 'group' => new Group(array('data' => array('lithium\tests\mocks\test\MockUnitTest')))
  47. ));
  48. $report->run();
  49. $expected = 2;
  50. $result = $report->stats();
  51. $this->assertEqual($expected, $result['count']['asserts']);
  52. $this->assertEqual($expected, $result['count']['passes']);
  53. $this->assertTrue($result['success']);
  54. }
  55. public function testRender() {
  56. $report = new Report(array(
  57. 'title' => '\lithium\tests\mocks\test\MockUnitTest',
  58. 'group' => new Group(array('data' => array('\lithium\tests\mocks\test\MockUnitTest'))),
  59. 'format' => 'txt'
  60. ));
  61. $report->run();
  62. $result = $report->render('result', $report->stats());
  63. $this->assertPattern('#2.*2.*passes.*0.*fails.*0.*exceptions#s', $result);
  64. }
  65. public function testSingleFilter() {
  66. $report = new Report(array(
  67. 'title' => 'lithium\tests\mocks\test\MockFilterClassTest',
  68. 'group' => new Group(array(
  69. 'data' => array('lithium\tests\mocks\test\MockFilterClassTest')
  70. )),
  71. 'filters' => array("Complexity" => "")
  72. ));
  73. $report->run();
  74. $class = 'lithium\test\filter\Complexity';
  75. $result = $report->results['filters'][$class];
  76. $this->assertTrue(isset($report->results['filters'][$class]));
  77. }
  78. }
  79. ?>