GitterLogTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Tools\Test\TestCase\Utility;
  3. use Cake\Core\Configure;
  4. use Cake\Http\Client;
  5. use Cake\Http\Client\Request;
  6. use Psr\Log\LogLevel;
  7. use Shim\TestSuite\TestCase;
  8. use Tools\Utility\GitterLog;
  9. /**
  10. * GitterLogTest class
  11. */
  12. class GitterLogTest extends TestCase {
  13. /**
  14. * @return void
  15. */
  16. public function setUp(): void {
  17. parent::setUp();
  18. $key = env('GITTER_KEY') ?: '123';
  19. Configure::write('Gitter.key', $key);
  20. }
  21. /**
  22. * @return void
  23. */
  24. public function tearDown(): void {
  25. parent::tearDown();
  26. Configure::delete('Gitter.key');
  27. }
  28. /**
  29. * testLogsIntoDefaultFile method
  30. *
  31. * @return void
  32. */
  33. public function testLogsIntoDefaultFile(): void {
  34. $mockClient = $this->getMockBuilder(Client::class)->onlyMethods(['send'])->getMock();
  35. $callback = function(Request $value) {
  36. return (string)$value->getBody() === 'message=Test%3A+It+%2Aworks%2A+with+some+error+%5Bmarkup%5D%28https%3A%2F%2Fmy-url.com%29%21&level=error';
  37. };
  38. $mockClient->expects($this->once())->method('send')->with($this->callback($callback));
  39. $gitterLog = $this->getMockBuilder(GitterLog::class)->onlyMethods(['getClient'])->getMock();
  40. $gitterLog->expects($this->once())->method('getClient')->willReturn($mockClient);
  41. $gitterLog->write('Test: It *works* with some error [markup](https://my-url.com)!', LogLevel::ERROR);
  42. }
  43. }