/** * @param \Mcustiel\Phiremock\Domain\Expectation $expectation * * @return \Mcustiel\Phiremock\Server\Utils\Strategies\ResponseStrategyInterface */ public function getStrategyForExpectation(Expectation $expectation) { if (!empty($expectation->getProxyTo())) { return $this->diService->get(ProxyResponseStrategy::class); } if ($this->requestBodyOrUrlAreRegexp($expectation)) { return $this->diService->get(RegexResponseStrategy::class); } return $this->diService->get(HttpResponseStrategy::class); }
public function testInstantiationWithSingleton() { $this->dependencyContainer->add('fakeDependencyWithouthSingleton', function () { return new FakeDependency('someValue'); }); $this->dependencyContainer->add('anotherDependencyWithouthSingleton', function () { return new AnotherDependency('otherValue'); }); $this->dependencyContainer->add('requiresDependencyInConstructorWithouthSingleton', function () { $injector = new DependencyInjectionService(); return new RequiresAnotherDependency($injector->get('fakeDependencyWithouthSingleton'), $injector->get('anotherDependencyWithouthSingleton')); }); foreach ([5000, 15000, 25000, 50000] as $cycles) { $start = microtime(true); for ($i = $cycles; $i > 0; $i--) { $this->dependencyContainer->get('requiresDependencyInConstructorWithouthSingleton'); } echo "\n{$cycles} cycles executed in " . (microtime(true) - $start) . " microseconds with singleton\n"; } }
public function testInjection() { $this->dependencyContainer->register('fakeDependency', function () { return new FakeDependency('someValue'); }); $this->dependencyContainer->register('anotherDependency', function () { return new AnotherDependency('anotherValue'); }); $this->dependencyContainer->register('requiresDependencyInConstructor', function () { $injector = new DependencyInjectionService(); return new RequiresAnotherDependency($injector->get('fakeDependency'), $injector->get('anotherDependency')); }); $instance = $this->dependencyContainer->get('requiresDependencyInConstructor'); $this->assertInstanceOf(FakeDependency::class, $instance->getFakeDependency()); }
use Mcustiel\Phiremock\Server\Utils\Strategies\RegexResponseStrategy; use Mcustiel\Phiremock\Server\Config\Matchers; use Mcustiel\Phiremock\Common\Utils\RequestBuilderFactory; use Mcustiel\Phiremock\Server\Http\InputSources\UrlFromPath; $di = new DependencyInjectionService(); $di->register('logger', function () { // create a log channel $log = new Logger('stdoutLogger'); $log->pushHandler(new StreamHandler(STDOUT, LOG_LEVEL)); return $log; }); $di->register(RemoteConnectionInterface::class, function () { return new GuzzleConnection(new GuzzleHttp\Client()); }); $di->register(HttpResponseStrategy::class, function () use($di) { return new HttpResponseStrategy($di->get('logger')); }); $di->register(RegexResponseStrategy::class, function () use($di) { return new RegexResponseStrategy($di->get('logger')); }); $di->register(ProxyResponseStrategy::class, function () use($di) { return new ProxyResponseStrategy($di->get(RemoteConnectionInterface::class), $di->get('logger')); }); $di->register('responseStrategyFactory', function () use($di) { return new ResponseStrategyFactory($di); }); $di->register('config', function () { return RouterConfig::get(); }); $di->register('homePathService', function () { return new HomePathService();