示例#1
0
 /**
  * Construct a new generator spy factory.
  *
  * @param CallEventFactory $callEventFactory The call event factory to use.
  * @param FeatureDetector  $featureDetector  The feature detector to use.
  */
 public function __construct(CallEventFactory $callEventFactory, FeatureDetector $featureDetector)
 {
     $this->callEventFactory = $callEventFactory;
     $this->isGeneratorImplicitNextSupported = $featureDetector->isSupported('generator.implicit-next');
     $this->isGeneratorReturnSupported = $featureDetector->isSupported('generator.return');
     $this->isHhvm = $featureDetector->isSupported('runtime.hhvm');
 }
示例#2
0
 /**
  * Construct a new mock builder.
  *
  * Each value in `$types` can be either a class name, or an ad hoc mock
  * definition. If only a single type is being mocked, the class name or
  * definition can be passed without being wrapped in an array.
  *
  * @param mixed              $types              The types to mock.
  * @param MockFactory        $factory            The factory to use.
  * @param HandleFactory      $handleFactory      The handle factory to use.
  * @param InvocableInspector $invocableInspector The invocable inspector.
  * @param FeatureDetector    $featureDetector    The feature detector to use.
  *
  * @throws MockException If invalid input is supplied.
  */
 public function __construct($types, MockFactory $factory, HandleFactory $handleFactory, InvocableInspector $invocableInspector, FeatureDetector $featureDetector)
 {
     $this->isTraitSupported = $featureDetector->isSupported('trait');
     $this->isAnonymousClassSupported = $featureDetector->isSupported('class.anonymous');
     $this->isRelaxedKeywordsSupported = $featureDetector->isSupported('parser.relaxed-keywords');
     $this->isEngineErrorExceptionSupported = $featureDetector->isSupported('error.exception.engine');
     $this->isDateTimeInterfaceSupported = interface_exists('DateTimeInterface');
     $this->factory = $factory;
     $this->handleFactory = $handleFactory;
     $this->invocableInspector = $invocableInspector;
     $this->featureDetector = $featureDetector;
     $this->types = array();
     $this->parentClassName = null;
     $this->customMethods = array();
     $this->customProperties = array();
     $this->customStaticMethods = array();
     $this->customStaticProperties = array();
     $this->customConstants = array();
     $this->isFinalized = false;
     $this->emptyCallback = function () {
     };
     if (null !== $types) {
         $this->like($types);
     }
 }
示例#3
0
 /**
  * Cosntruct a new mock factory.
  *
  * @param Sequencer       $labelSequencer  The label sequencer to use.
  * @param MockGenerator   $generator       The generator to use.
  * @param HandleFactory   $handleFactory   The handle factory to use.
  * @param FeatureDetector $featureDetector The feature detector to use.
  */
 public function __construct(Sequencer $labelSequencer, MockGenerator $generator, HandleFactory $handleFactory, FeatureDetector $featureDetector)
 {
     $this->labelSequencer = $labelSequencer;
     $this->generator = $generator;
     $this->handleFactory = $handleFactory;
     $this->definitions = array();
     $this->isConstructorBypassSupported = $featureDetector->isSupported('object.constructor.bypass');
     $this->isConstructorBypassSupportedForExtendedInternals = $featureDetector->isSupported('object.constructor.bypass.extended-internal');
 }
示例#4
0
 /**
  * Construct a new mock generator.
  *
  * @param Sequencer                  $labelSequencer     The label sequencer to use.
  * @param FunctionSignatureInspector $signatureInspector The function signature inspector to use.
  * @param FeatureDetector            $featureDetector    The feature detector to use.
  */
 public function __construct(Sequencer $labelSequencer, FunctionSignatureInspector $signatureInspector, FeatureDetector $featureDetector)
 {
     $this->labelSequencer = $labelSequencer;
     $this->signatureInspector = $signatureInspector;
     $this->featureDetector = $featureDetector;
     $this->isClosureBindingSupported = $this->featureDetector->isSupported('closure.bind');
     $this->isReturnTypeSupported = $this->featureDetector->isSupported('return.type');
     $this->isNullableTypeSupported = $this->featureDetector->isSupported('type.nullable');
     $this->isHhvm = $featureDetector->isSupported('runtime.hhvm');
     $this->canMockPharDestruct = $this->isHhvm || !version_compare(PHP_VERSION, '7.x', '<');
 }
示例#5
0
 /**
  * Get the static instance of this factory.
  *
  * @return MockBuilderFactory The static factory.
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self(MockFactory::instance(), HandleFactory::instance(), InvocableInspector::instance(), FeatureDetector::instance());
     }
     return self::$instance;
 }
示例#6
0
 /**
  * Get the static instance of this engine.
  *
  * @return DifferenceEngine The static engine.
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self(FeatureDetector::instance());
     }
     return self::$instance;
 }
示例#7
0
 /**
  * Get the static instance of this renderer.
  *
  * @return AssertionRenderer The static renderer.
  */
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new self(MatcherVerifier::instance(), InlineExporter::instance(), DifferenceEngine::instance(), FeatureDetector::instance());
     }
     return self::$instance;
 }
 /**
  * Get the static instance of this inspector.
  *
  * @return FunctionSignatureInspector The static inspector.
  */
 public static function instance()
 {
     if (!self::$instance) {
         $featureDetector = FeatureDetector::instance();
         if ($featureDetector->isSupported('runtime.hhvm')) {
             // @codeCoverageIgnoreStart
             self::$instance = new HhvmFunctionSignatureInspector(InvocableInspector::instance(), $featureDetector);
             // @codeCoverageIgnoreEnd
         } else {
             self::$instance = new PhpFunctionSignatureInspector(InvocableInspector::instance(), $featureDetector);
         }
     }
     return self::$instance;
 }
 /**
  * Construct a new function signature inspector.
  *
  * @param InvocableInspector $invocableInspector The invocable inspector to use.
  * @param FeatureDetector    $featureDetector    The feature detector to use.
  */
 public function __construct(InvocableInspector $invocableInspector, FeatureDetector $featureDetector)
 {
     parent::__construct($invocableInspector);
     $this->isExportReferenceSupported = $featureDetector->isSupported('reflection.function.export.reference');
     $this->isVariadicParameterSupported = $featureDetector->isSupported('parameter.variadic');
     $this->isScalarTypeHintSupported = $featureDetector->isSupported('parameter.hint.scalar');
     $this->isCallableTypeHintSupported = $featureDetector->isSupported('type.callable');
     $this->isIterableTypeHintSupported = $featureDetector->isSupported('type.iterable');
 }
 /**
  * Construct a new generator answer builder factory.
  *
  * @param InvocableInspector $invocableInspector The invocable inspector to use.
  * @param Invoker            $invoker            The invoker to use.
  * @param FeatureDetector    $featureDetector    The feature detector to use.
  */
 public function __construct(InvocableInspector $invocableInspector, Invoker $invoker, FeatureDetector $featureDetector)
 {
     $this->invocableInspector = $invocableInspector;
     $this->invoker = $invoker;
     $this->isGeneratorReturnSupported = $featureDetector->isSupported('generator.return');
 }
 /**
  * Construct a new function signature inspector.
  *
  * @param InvocableInspector $invocableInspector The invocable inspector to use.
  * @param FeatureDetector    $featureDetector    The feature detector to use.
  */
 public function __construct(InvocableInspector $invocableInspector, FeatureDetector $featureDetector)
 {
     parent::__construct($invocableInspector);
     $this->isVariadicParameterSupported = $featureDetector->isSupported('parameter.variadic');
     $this->isIterableTypeHintSupported = $featureDetector->isSupported('type.iterable');
 }
示例#12
0
 /**
  * Construct a new facade driver.
  *
  * @param AssertionRecorder $assertionRecorder The assertion recorder to use.
  */
 protected function __construct(AssertionRecorder $assertionRecorder)
 {
     $this->sequences = array();
     $anyMatcher = new AnyMatcher();
     $objectIdSequence = Sequencer::sequence('exporter-object-id');
     $invocableInspector = new InvocableInspector();
     $exporter = new InlineExporter(1, $objectIdSequence, $invocableInspector);
     $featureDetector = new FeatureDetector();
     $invoker = new Invoker();
     $matcherVerifier = new MatcherVerifier();
     if ($featureDetector->isSupported('runtime.hhvm')) {
         // @codeCoverageIgnoreStart
         $functionSignatureInspector = new HhvmFunctionSignatureInspector($invocableInspector, $featureDetector);
         // @codeCoverageIgnoreEnd
     } else {
         $functionSignatureInspector = new PhpFunctionSignatureInspector($invocableInspector, $featureDetector);
     }
     $mockClassLabelSequence = Sequencer::sequence('mock-class-label');
     $this->sequences[] = $mockClassLabelSequence;
     $mockGenerator = new MockGenerator($mockClassLabelSequence, $functionSignatureInspector, $featureDetector);
     $wildcardMatcher = new WildcardMatcher($anyMatcher, 0, null);
     $matcherFactory = new MatcherFactory($anyMatcher, $wildcardMatcher, $exporter);
     $matcherFactory->addMatcherDriver(new HamcrestMatcherDriver());
     $matcherFactory->addMatcherDriver(new CounterpartMatcherDriver());
     $matcherFactory->addMatcherDriver(new PhpunitMatcherDriver());
     $matcherFactory->addMatcherDriver(new SimpletestMatcherDriver());
     $matcherFactory->addMatcherDriver(new PhakeMatcherDriver($wildcardMatcher));
     $matcherFactory->addMatcherDriver(new ProphecyMatcherDriver($wildcardMatcher));
     $matcherFactory->addMatcherDriver(new MockeryMatcherDriver());
     $emptyValueFactory = new EmptyValueFactory();
     $generatorAnswerBuilderFactory = new GeneratorAnswerBuilderFactory($invocableInspector, $invoker, $featureDetector);
     $stubLabelSequence = Sequencer::sequence('stub-label');
     $this->sequences[] = $stubLabelSequence;
     $stubFactory = new StubFactory($stubLabelSequence, $matcherFactory, $matcherVerifier, $invoker, $invocableInspector, $emptyValueFactory, $generatorAnswerBuilderFactory);
     $clock = new SystemClock('microtime');
     $eventSequence = Sequencer::sequence('event-sequence-number');
     $this->sequences[] = $eventSequence;
     $eventFactory = new CallEventFactory($eventSequence, $clock);
     $callFactory = new CallFactory($eventFactory, $invoker);
     $generatorSpyFactory = new GeneratorSpyFactory($eventFactory, $featureDetector);
     $iterableSpyFactory = new IterableSpyFactory($eventFactory);
     $spyLabelSequence = Sequencer::sequence('spy-label');
     $this->sequences[] = $spyLabelSequence;
     $spyFactory = new SpyFactory($spyLabelSequence, $callFactory, $invoker, $generatorSpyFactory, $iterableSpyFactory);
     $differenceEngine = new DifferenceEngine($featureDetector);
     $assertionRenderer = new AssertionRenderer($matcherVerifier, $exporter, $differenceEngine, $featureDetector);
     $generatorVerifierFactory = new GeneratorVerifierFactory($matcherFactory, $assertionRecorder, $assertionRenderer);
     $iterableVerifierFactory = new IterableVerifierFactory($matcherFactory, $assertionRecorder, $assertionRenderer);
     $callVerifierFactory = new CallVerifierFactory($matcherFactory, $matcherVerifier, $generatorVerifierFactory, $iterableVerifierFactory, $assertionRecorder, $assertionRenderer);
     $assertionRecorder->setCallVerifierFactory($callVerifierFactory);
     $functionHookGenerator = new FunctionHookGenerator();
     $functionHookManager = new FunctionHookManager($functionSignatureInspector, $functionHookGenerator);
     $stubVerifierFactory = new StubVerifierFactory($stubFactory, $spyFactory, $matcherFactory, $matcherVerifier, $generatorVerifierFactory, $iterableVerifierFactory, $callVerifierFactory, $assertionRecorder, $assertionRenderer, $generatorAnswerBuilderFactory, $functionHookManager);
     $handleFactory = new HandleFactory($stubFactory, $stubVerifierFactory, $assertionRenderer, $assertionRecorder, $invoker);
     $mockLabelSequence = Sequencer::sequence('mock-label');
     $this->sequences[] = $mockLabelSequence;
     $mockFactory = new MockFactory($mockLabelSequence, $mockGenerator, $handleFactory, $featureDetector);
     $mockBuilderFactory = new MockBuilderFactory($mockFactory, $handleFactory, $invocableInspector, $featureDetector);
     $spyVerifierFactory = new SpyVerifierFactory($spyFactory, $matcherFactory, $matcherVerifier, $generatorVerifierFactory, $iterableVerifierFactory, $callVerifierFactory, $assertionRecorder, $assertionRenderer, $functionHookManager);
     $eventOrderVerifier = new EventOrderVerifier($assertionRecorder, $assertionRenderer);
     $emptyValueFactory->setStubVerifierFactory($stubVerifierFactory);
     $emptyValueFactory->setMockBuilderFactory($mockBuilderFactory);
     $generatorVerifierFactory->setCallVerifierFactory($callVerifierFactory);
     $iterableVerifierFactory->setCallVerifierFactory($callVerifierFactory);
     $this->mockBuilderFactory = $mockBuilderFactory;
     $this->handleFactory = $handleFactory;
     $this->spyVerifierFactory = $spyVerifierFactory;
     $this->stubVerifierFactory = $stubVerifierFactory;
     $this->functionHookManager = $functionHookManager;
     $this->eventOrderVerifier = $eventOrderVerifier;
     $this->matcherFactory = $matcherFactory;
     $this->exporter = $exporter;
     $this->assertionRenderer = $assertionRenderer;
     $this->differenceEngine = $differenceEngine;
 }