MediaWikiCoversValidator.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright (C) 2017 Kunal Mehta <legoktm@member.fsf.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. */
  20. /**
  21. * Trait that checks that covers tags are valid, since PHPUnit
  22. * won't do it unless you run it with coverage, which is super
  23. * slow.
  24. *
  25. * @since 1.31
  26. */
  27. trait MediaWikiCoversValidator {
  28. /**
  29. * Test that all methods in this class that begin
  30. * with "test" have valid covers tags.
  31. */
  32. public function testValidCovers() {
  33. $methods = get_class_methods( $this );
  34. $class = get_class( $this );
  35. $bad = '';
  36. foreach ( $methods as $method ) {
  37. if ( strpos( $method, 'test' ) === 0 ) {
  38. try {
  39. PHPUnit_Util_Test::getLinesToBeCovered( $class, $method );
  40. } catch ( PHPUnit_Framework_CodeCoverageException $e ) {
  41. $bad .= "$class::$method: {$e->getMessage()}\n";
  42. }
  43. }
  44. }
  45. $this->assertEquals( '', $bad );
  46. }
  47. }