LoggerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use LeProxy\LeProxy\Logger;
  3. class LoggerTest extends PHPUnit_Framework_TestCase
  4. {
  5. public function testLogFailConnectionWithoutSourcePrintsErrorWithoutSource()
  6. {
  7. $this->expectOutputRegex('/\?\?\? failed to connect to example\.com:80 \(error\)\s+$/');
  8. $logger = new Logger();
  9. $logger->logFailConnection(null, 'example.com:80', 'error');
  10. }
  11. public function testLogFailConnectionWithSourcePrintsErrorWithSource()
  12. {
  13. $this->expectOutputRegex('/http:\/\/user@host failed to connect to example\.com:80 \(error\)\s+$/');
  14. $logger = new Logger();
  15. $logger->logFailConnection('http://user:pass@host:8080', 'example.com:80', 'error');
  16. }
  17. public function testLogConnectionWithoutSourcePrintsSuccessWithoutSource()
  18. {
  19. $this->expectOutputRegex('/\?\?\? connected to example\.com:80\s+$/');
  20. $logger = new Logger();
  21. $logger->logConnection(null, 'example.com:80', null);
  22. }
  23. public function testConnectSuccessWithSourcePrintsSuccessWithSource()
  24. {
  25. $this->expectOutputRegex('/http:\/\/user@host connected to example\.com:80\s+$/');
  26. $logger = new Logger();
  27. $logger->logConnection('http://user:pass@host:8080', 'example.com:80', null);
  28. }
  29. public function testLogConnectionWithoutRemoteIpPrintsSuccessWithDestinationAndIp()
  30. {
  31. $this->expectOutputRegex('/\?\?\? connected to example\.com:80 \(1\.2\.3\.4:5060\)\s+$/');
  32. $logger = new Logger();
  33. $logger->logConnection(null, 'example.com:80', '1.2.3.4:5060');
  34. }
  35. public function testConnectSuccessWithoutSameRemoteIpPrintsSuccessWithDestinationWithoutIp()
  36. {
  37. $this->expectOutputRegex('/\?\?\? connected to 1\.2\.3\.4:5060\s+$/');
  38. $logger = new Logger();
  39. $logger->logConnection(null, '1.2.3.4:5060', '1.2.3.4:5060');
  40. }
  41. }