RegistryTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\IMessageReporter;
  28. use OCP\Support\CrashReport\IReporter;
  29. use Test\TestCase;
  30. class RegistryTest extends TestCase {
  31. /** @var Registry */
  32. private $registry;
  33. protected function setUp() {
  34. parent::setUp();
  35. $this->registry = new Registry();
  36. }
  37. /**
  38. * Doesn't assert anything, just checks whether anything "explodes"
  39. */
  40. public function testDelegateToNone() {
  41. $exception = new Exception('test');
  42. $this->registry->delegateReport($exception);
  43. $this->addToAssertionCount(1);
  44. }
  45. public function testDelegateBreadcrumbCollection() {
  46. $reporter1 = $this->createMock(IReporter::class);
  47. $reporter2 = $this->createMock(ICollectBreadcrumbs::class);
  48. $message = 'hello';
  49. $category = 'log';
  50. $reporter2->expects($this->once())
  51. ->method('collect')
  52. ->with($message, $category);
  53. $this->registry->register($reporter1);
  54. $this->registry->register($reporter2);
  55. $this->registry->delegateBreadcrumb($message, $category);
  56. }
  57. public function testDelegateToAll() {
  58. $reporter1 = $this->createMock(IReporter::class);
  59. $reporter2 = $this->createMock(IReporter::class);
  60. $exception = new Exception('test');
  61. $reporter1->expects($this->once())
  62. ->method('report')
  63. ->with($exception);
  64. $reporter2->expects($this->once())
  65. ->method('report')
  66. ->with($exception);
  67. $this->registry->register($reporter1);
  68. $this->registry->register($reporter2);
  69. $this->registry->delegateReport($exception);
  70. }
  71. public function testDelegateMessage() {
  72. $reporter1 = $this->createMock(IReporter::class);
  73. $reporter2 = $this->createMock(IMessageReporter::class);
  74. $message = 'hello';
  75. $reporter2->expects($this->once())
  76. ->method('reportMessage')
  77. ->with($message, []);
  78. $this->registry->register($reporter1);
  79. $this->registry->register($reporter2);
  80. $this->registry->delegateMessage($message);
  81. }
  82. }