LogMethodTests.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Consolidation\Log;
  3. use Symfony\Component\Console\Output\BufferedOutput;
  4. use Symfony\Component\Console\Output\OutputInterface;
  5. use PHPUnit\Framework\TestCase;
  6. class LogMethodTests extends TestCase
  7. {
  8. protected $output;
  9. protected $logger;
  10. function setup() {
  11. $this->output = new BufferedOutput();
  12. $this->output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
  13. $this->logger = new Logger($this->output);
  14. $this->logger->setLogOutputStyler(new UnstyledLogOutputStyler());
  15. }
  16. function testError() {
  17. $this->logger->error('Do not enter - wrong way.');
  18. $outputText = rtrim($this->output->fetch());
  19. $this->assertEquals(' [error] Do not enter - wrong way.', $outputText);
  20. }
  21. function testWarning() {
  22. $this->logger->warning('Steep grade.');
  23. $outputText = rtrim($this->output->fetch());
  24. $this->assertEquals(' [warning] Steep grade.', $outputText);
  25. }
  26. function testNotice() {
  27. $this->logger->notice('No loitering.');
  28. $outputText = rtrim($this->output->fetch());
  29. $this->assertEquals(' [notice] No loitering.', $outputText);
  30. }
  31. function testInfo() {
  32. $this->logger->info('Scenic route.');
  33. $outputText = rtrim($this->output->fetch());
  34. $this->assertEquals(' [info] Scenic route.', $outputText);
  35. }
  36. function testDebug() {
  37. $this->logger->debug('Counter incremented.');
  38. $outputText = rtrim($this->output->fetch());
  39. $this->assertEquals(' [debug] Counter incremented.', $outputText);
  40. }
  41. function testSuccess() {
  42. $this->logger->success('It worked!');
  43. $outputText = rtrim($this->output->fetch());
  44. $this->assertEquals(' [success] It worked!', $outputText);
  45. }
  46. }