예제 #1
0
 /**
  * @param  string $className
  * @param  array  $arguments
  *
  * @return object
  */
 public static function resolve_internal($className, $arguments = array())
 {
     if (App::$shouldInjectMockObjects) {
         // It allows the test generator to substitute the real class instance with a
         // mock object controlled by the test generator so that the test
         // generator can monitor the creation and execution of the class
         // being resolved.
         $mock = App::createMockedInstance($className, $arguments);
         if ($mock) {
             return $mock;
         }
         // If null is returned by the unit test generator,
         // it means that the developer has decided not to mock this class.
         // Proceed with creating the real object.
     }
     $singletonOrInstantiator = null;
     $isOverride = isset(self::$overrides[$className]);
     if ($isOverride) {
         return self::$overrides[$className];
     } else {
         return self::createNewInstanceWithArguments($className, $arguments);
     }
 }
예제 #2
0
파일: Diesel.php 프로젝트: martinsv/bart
 /**
  * Checks TestScribe (test generator) to determine whether the real or mock class is required.
  * If a mock class is needed, it is returned by this method (wrapped in Some), otherwise None is returned.
  * @param $className
  * @param $arguments
  * @return Option
  */
 private static function checkTestScribe($className, $arguments)
 {
     /** @noinspection PhpUndefinedNamespaceInspection */
     /** @noinspection PhpUndefinedClassInspection */
     if (self::isTestGeneratorRun() && \Box\TestScribe\App::$shouldInjectMockObjects) {
         // This code block is to support PHPUnit test generator.
         // @see https://github.com/box/TestScribe
         // The class 'Box\TestScribe\App' should only be loaded
         // when this method is executed by the test generator.
         // It allows the test generator to substitute the real class instance with a
         // mock object controlled by the test generator so that the test
         // generator can monitor the creation and execution of the class
         // being resolved.
         /** @noinspection PhpUndefinedNamespaceInspection */
         return Option::fromValue(\Box\TestScribe\App::createMockedInstance($className, $arguments));
     }
     return None::create();
 }