シンプレックスとそれに依存する処理メカニズムのかなりの量がPimpleを介して処理されています。私はPimpleのコンテナ(Dependency Inversion)を通してクラスやインスタンスを解決できるように、依存性注入の全体を拡張しようとしています。PimpleのServiceProviderが登録のオプションを取得しない
私はこれを達成することを可能にするライブラリがあることを認識していますが、車輪やそのような線に沿って何かを再発明しなければ、もっと良い方法を学ぶことができますか?私のテストファイルで
namespace Agnostic\DependencyInversion\Provider;
use Pimple\ServiceProviderInterface;
use Pimple\Container;
class ContainerBindingsServiceProvider implements ServiceProviderInterface
{
public function register(Container $container)
{
if(!isset($container['context.bindings'])){
throw new \Exception("Missing bindings for the Application Context.");
}
}
}
私がチェックされている値が利用できない場合に例外がスローされた場合は、最初のテストは見ていることはまだのように2つの方法があります。
これは、 がまだ登録されていない識別子を解決しようとするときにスローされる例外と同じように機能します。当初
namespace Agnostic\Test\ServiceProviderTestSuite;
use Agnostic\DependencyInversion\Provider\ContainerBindingsServiceProvider;
use Pimple\Container;
class ContainerBindingsServiceProviderTest extends \PHPUnit_Framework_TestCase
{
public function testItThrowsExceptionIfNoBindingsSet()
{
try{
$container = new Container();
$container->register(new ContainerBindingsServiceProvider());
}catch(\Exception $exc){
$this->assertEquals($exc->getMessage(), "Missing bindings for the Application Context.");
return;
}
$this->fail("Expected Exception has not been raised.");
}
public function testItContainesBindings()
{
$container = new Container();
$container->register(new ContainerBindingsServiceProvider(), array('context.bindings' => (function(){
return include APP_DIR .'/config/bindings.php';
})())
);
}
}
私は私のテストクラスのsetUpメソッド内で作成Container
インスタンスを持っていたし、これは私が、PHPUnitが各テストメソッドのためにそこにあるすべてのものを再初期化していることを知っているにもかかわらず、問題になる可能性があり考え出しました。
以下のテスト結果で、私は何が間違っているのか不思議に思っています。
PHPUnit 5.6.4 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.0
Configuration: C:\Users\luyandasiko\Documents\spikes\dependency-inversion\phpunit.xml
.E 2/2 (100%)
Time: 42 ms, Memory: 4.00MB
There was 1 error:
1) Agnostic\Test\ServiceProviderTestSuite\ContainerBindingsServiceProviderTest::testItContainesBindings
Exception: Missing bindings for the Application Context.
C:\Users\luyandasiko\Documents\spikes\dependency-inversion\src\Provider\ContainerBindingsServiceProvider.php:13
C:\Users\luyandasiko\Documents\spikes\dependency-inversion\vendor\pimple\pimple\src\Pimple\Container.php:274
C:\Users\luyandasiko\Documents\spikes\dependency-inversion\dev\Test\ServiceProviderTestSuite\ContainerBindingsServiceProviderTest.php:35
ERRORS!
Tests: 2, Assertions: 1, Errors: 1.
私の第二のテスト機能上の線だけので、アレイを手動で私はそれをしたとして、それは問題ではないまで作ることができる特別な私の設定は何もで定義された配列を返します(以下のコードを参照してください)が、得ることができませんでしたこれを通過した。
(function(){
return include APP_DIR .'/config/bindings.php';
})()
デフォルトのサービスプロバイダがオプションを処理する方法を確認するためにSiliexコードベースを調べましたが、何か不足しているようです。私はこれで何が欠けているのか、誰かが正しい方向に向けることができますか?
実際に問題があります。 Pimpleライブラリを更新しなければならなかったので、私の解決策が解決していないかどうかを確認してください。 – Maximum86