Exemplo n.º 1
0
 private function setUpDependencyInjection()
 {
     $this->diManager->register('httpMockServer', function () {
         return $this->server;
     });
     $this->diManager->register('httpMockBuilder', function () {
         return new MockBuilder(new MatcherFactory(), new ExtractorFactory());
     });
 }
 /**
  * @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);
 }
Exemplo n.º 3
0
 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";
     }
 }
Exemplo n.º 4
0
 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());
 }
Exemplo n.º 5
0
use Mcustiel\Phiremock\Server\Actions\StoreRequestAction;
use Mcustiel\Phiremock\Server\Actions\ResetRequestsCountAction;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Mcustiel\Phiremock\Server\Utils\HomePathService;
use Mcustiel\Phiremock\Server\Utils\FileExpectationsLoader;
use Mcustiel\Phiremock\Server\Utils\ResponseStrategyFactory;
use Mcustiel\Phiremock\Server\Utils\Strategies\HttpResponseStrategy;
use Mcustiel\Phiremock\Server\Utils\Strategies\ProxyResponseStrategy;
use Mcustiel\Phiremock\Common\Http\RemoteConnectionInterface;
use Mcustiel\Phiremock\Common\Http\Implementation\GuzzleConnection;
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'));
});