Skip to content

Commit

Permalink
Fixed dependency graph to share and alias correct types (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
cspray authored Nov 2, 2019
1 parent 5ae7239 commit 6c83e39
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 3.0.0-beta6 2019-11-02

#### Fixed

- Fixes the DependencyGraph aliases to ensure that the appropriate services are shared and aliased to the correct
default implementation.

## 3.0.0-beta5 2019-11-02

This release represents a major refactor to the Plugin system in an attempt to make the more common use
Expand Down
9 changes: 5 additions & 4 deletions src/DependencyGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Cspray\Labrador;

use Amp\ByteStream\OutputBuffer;
use Amp\ByteStream\ResourceOutputStream;
use Amp\Log\StreamHandler;
use Auryn\Injector;
use Auryn\InjectorException;
use Cspray\Labrador\AsyncEvent\Emitter;
use Cspray\Labrador\AsyncEvent\AmpEmitter;
use Cspray\Labrador\Exception\DependencyInjectionException;
use Cspray\Labrador\Plugin\Pluggable;
use Cspray\Labrador\Plugin\PluginManager;
use Monolog\Logger;
use Psr\Log\LoggerAwareInterface;
Expand Down Expand Up @@ -44,15 +44,16 @@ public function wireObjectGraph(Injector $injector = null) : Injector {
try {
$injector = $injector ?? new Injector();

$injector->share(AmpEmitter::class);
$injector->share(Emitter::class);
$injector->alias(Emitter::class, AmpEmitter::class);

$injector->share(PluginManager::class);
$injector->share(Pluggable::class);
$injector->alias(Pluggable::class, PluginManager::class);
$injector->define(PluginManager::class, [
':injector' => $injector
]);

$injector->share(AmpEngine::class);
$injector->share(Engine::class);
$injector->alias(Engine::class, AmpEngine::class);

$logger = new Logger($this->configuration->getLogName());
Expand Down
24 changes: 22 additions & 2 deletions test/DependencyGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Cspray\Labrador\Configuration;
use Cspray\Labrador\DependencyGraph;
use Auryn\Injector;
use Cspray\Labrador\Engine;
use Cspray\Labrador\Plugin\Pluggable;
use Cspray\Labrador\Plugin\PluginManager;
use Cspray\Labrador\Test\Stub\LoggerAwareStub;
use Monolog\Logger;
Expand Down Expand Up @@ -69,10 +71,28 @@ public function testInjectorIsNotShared() {
$this->assertNotSame($injector, $injector->make(Injector::class));
}

public function testInjectorCreatesEngine() {
public function testEngineAliasedToAmpEngine() {
$injector = (new DependencyGraph($this->getConfiguration()))->wireObjectGraph();

$this->assertInstanceOf(AmpEngine::class, $injector->make(AmpEngine::class));
$this->assertInstanceOf(AmpEngine::class, $injector->make(Engine::class));
}

public function testEngineShared() {
$injector = (new DependencyGraph($this->getConfiguration()))->wireObjectGraph();

$this->assertSame($injector->make(Engine::class), $injector->make(Engine::class));
}

public function testPluggableAliasedToPluginManager() {
$injector = (new DependencyGraph($this->getConfiguration()))->wireObjectGraph();

$this->assertInstanceOf(PluginManager::class, $injector->make(Pluggable::class));
}

public function testPluggableShared() {
$injector = (new DependencyGraph($this->getConfiguration()))->wireObjectGraph();

$this->assertSame($injector->make(Pluggable::class), $injector->make(Pluggable::class));
}

public function testPluginManagerGetsCorrectInjector() {
Expand Down

0 comments on commit 6c83e39

Please sign in to comment.