RegistryTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Support\CrashReport;
  24. use Exception;
  25. use OC\Support\CrashReport\Registry;
  26. use OCP\Support\CrashReport\ICollectBreadcrumbs;
  27. use OCP\Support\CrashReport\IReporter;
  28. use Test\TestCase;
  29. class RegistryTest extends TestCase {
  30. /** @var Registry */
  31. private $registry;
  32. protected function setUp() {
  33. parent::setUp();
  34. $this->registry = new Registry();
  35. }
  36. /**
  37. * Doesn't assert anything, just checks whether anything "explodes"
  38. */
  39. public function testDelegateToNone() {
  40. $exception = new Exception('test');
  41. $this->registry->delegateReport($exception);
  42. $this->addToAssertionCount(1);
  43. }
  44. public function testDelegateBreadcrumbCollection() {
  45. $reporter1 = $this->createMock(IReporter::class);
  46. $reporter2 = $this->createMock(ICollectBreadcrumbs::class);
  47. $message = 'hello';
  48. $category = 'log';
  49. $reporter2->expects($this->once())
  50. ->method('collect')
  51. ->with($message, $category);
  52. $this->registry->register($reporter1);
  53. $this->registry->register($reporter2);
  54. $this->registry->delegateBreadcrumb($message, $category);
  55. }
  56. public function testDelegateToAll() {
  57. $reporter1 = $this->createMock(IReporter::class);
  58. $reporter2 = $this->createMock(IReporter::class);
  59. $exception = new Exception('test');
  60. $reporter1->expects($this->once())
  61. ->method('report')
  62. ->with($exception);
  63. $reporter2->expects($this->once())
  64. ->method('report')
  65. ->with($exception);
  66. $this->registry->register($reporter1);
  67. $this->registry->register($reporter2);
  68. $this->registry->delegateReport($exception);
  69. }
  70. }