Skip to content

Commit

Permalink
Add context logger aware trait and interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomphp committed Nov 24, 2016
1 parent 43d9ceb commit 77ce949
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.0] - 2016-11-24
### Added
* `TomPHP\ContextLogger\ContextLoggerAware` interface.
* `TomPHP\ContextLogger\ContextLoggerAwareTrait` trait.

## [1.0.0] - 2016-11-20
### Added
* `ContextLogger::addContext(string $name, $value)`
* `ContextLogger::removeContext(string $name)`
* `TomPHP\ContextLogger::addContext(string $name, $value)`
* `TomPHP\ContextLogger::removeContext(string $name)`
13 changes: 13 additions & 0 deletions src/ContextLogger/ContextLoggerAware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace TomPHP\ContextLogger;

use TomPHP\ContextLogger;

interface ContextLoggerAware
{
/**
* @return void
*/
public function setLogger(ContextLogger $logger);
}
18 changes: 18 additions & 0 deletions src/ContextLogger/ContextLoggerAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace TomPHP\ContextLogger;

use TomPHP\ContextLogger;

trait ContextLoggerAwareTrait
{
/**
* @var ContextLogger
*/
protected $logger;

public function setLogger(ContextLogger $logger)
{
$this->logger = $logger;
}
}
21 changes: 21 additions & 0 deletions tests/ContextLogger/ContextLoggerAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace test\TomPHP\ContextLogger;

use TomPHP\ContextLogger;
use TomPHP\ContextLogger\ContextLoggerAwareTrait;

final class ContextLoggerAwareTraitTest extends \PHPUnit_Framework_TestCase
{
use ContextLoggerAwareTrait;

/** @test */
public function it_sets_the_logger_field()
{
$logger = $this->prophesize(ContextLogger::class)->reveal();

$this->setLogger($logger);

assertSame($logger, $this->logger);
}
}

0 comments on commit 77ce949

Please sign in to comment.