PageRenderTime 76ms CodeModel.GetById 48ms RepoModel.GetById 0ms app.codeStats 0ms

/benchmarks/classes/ezbenchmarkcase.php

https://github.com/StephanBoganskyXrow/ezpublish
PHP | 126 lines | 35 code | 7 blank | 84 comment | 4 complexity | c348153d959cd2d984af616e7ee41ad2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. //
  3. // Definition of eZBenchmarkCase class
  4. //
  5. // Created on: <18-Feb-2004 11:55:40 >
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \file ezbenchmarkcase.php
  31. */
  32. /*!
  33. \class eZBenchmarkCase ezbenchmarkcase.php
  34. \ingroup eZTest
  35. \brief eZBenchmarkCase provides a base class for doing automated benchmarks
  36. This class provides basic functionality and interface
  37. for creating benchmarks. It keeps a list of marks and
  38. a name which are accessible with markList() and name().
  39. To add new tests use addMark() or addFunctionMark()
  40. with the appropriate mark data.
  41. The methods prime() and cleanup() will be called before
  42. and after the mark itself is handled. This allows for priming
  43. certain values for the mark and cleaning up afterwards.
  44. To create a mark case inherit this class and create some mark methods
  45. that takes one parameter \a $tr which is the current test runner and
  46. a $parameter which is optional parameters added to the mark entry.
  47. The constructor must call the eZBenchmarkCase constructor with a useful
  48. name and setup some test methods with addMark() and addFunctionMark().
  49. For running the marks you must pass the case to an eZBenchmarkRunner instance.
  50. \code
  51. class MyTest extends eZBenchmarkCase
  52. {
  53. function MyTest()
  54. {
  55. $this->eZBenchmarkCase( 'My test case' );
  56. $this->addmark( 'markFunctionA', 'Addition mark' );
  57. $this->addFunctionTest( 'MyFunctionMark', 'Addition mark 2' );
  58. }
  59. function markFunctionA( &$tr, $parameter )
  60. {
  61. $a = 1 + 2;
  62. }
  63. }
  64. function MyFunctionMark( &$tr, $parameter )
  65. {
  66. $a = 1 + 2;
  67. }
  68. $case = new MyTest();
  69. $runner = new eZBenchmarkCLIRunner();
  70. $runner->run( $case );
  71. \endcode
  72. */
  73. require_once( 'lib/ezutils/classes/ezdebug.php' );
  74. class eZBenchmarkCase extends eZBenchmarkUnit
  75. {
  76. /*!
  77. Constructor
  78. */
  79. function eZBenchmarkCase( $name = false )
  80. {
  81. $this->eZBenchmarkUnit( $name );
  82. }
  83. function addMark( $method, $name, $parameter = false )
  84. {
  85. if ( !method_exists( $this, $method ) )
  86. {
  87. eZDebug::writeWarning( "Mark method $method in mark " . $this->Name . " does not exist, cannot add", __METHOD__ );
  88. }
  89. if ( !$name )
  90. $name = $method;
  91. $this->addEntry( array( 'name' => $name,
  92. 'object' => &$this,
  93. 'method' => $method,
  94. 'parameter' => $parameter ) );
  95. }
  96. function addFunctionMark( $function, $name, $parameter = false )
  97. {
  98. if ( !function_exists( $function ) )
  99. {
  100. eZDebug::writeWarning( "Mark function $method does not exist, cannot add to mark " . $this->Name, __METHOD__ );
  101. }
  102. if ( !$name )
  103. $name = $function;
  104. $this->addEntry( array( 'name' => $name,
  105. 'function' => $function,
  106. 'parameter' => $parameter ) );
  107. }
  108. }
  109. ?>