Beispiel #1
0
 function __construct(Factory $factory, $workingDirectory, array $config)
 {
     $factory->setSingleton($this);
     $this->workingDirectory = $workingDirectory;
     $this->config = $config;
     $this->factory = $factory;
 }
Beispiel #2
0
 public function __construct($storageDir, Factory $factory)
 {
     $this->factory = $factory;
     $this->authors = new PersistentAuthorRepository($storageDir);
     $this->posts = new PersistentPostRepository($storageDir);
     $this->postService = $factory->setSingleton(new Posts($this->authors, $this->posts));
     $this->authorService = $factory->setSingleton(new Authors($this->authors));
 }
Beispiel #3
0
 protected function before()
 {
     $this->factory = new Factory();
     $this->factory->setSingleton($this->action->registry);
     $this->access = $this->factory->setSingleton(new AccessControl());
     $this->app = $this->factory->getInstance(WebApplication::class);
     $this->app->prepare();
 }
 private function whenIExecuteTheCommand()
 {
     $this->listener = new ArrayListener();
     $factory = new Factory();
     $factory->setSingleton($this->listener);
     $command = new ScrutCommand(new ConfigurationReader($this->files->fullPath(), $factory));
     $command->execute(['-c' . json_encode(['listen' => [ArrayListener::class]])]);
 }
 protected function before()
 {
     $factory = new Factory();
     $this->app = $factory->getInstance(WebApplication::class);
     $this->app->prepare();
     $this->app->fields->add(new ActionField($this->app->fields, $this->app->actions));
     $this->app->renderers->add(new PrimitiveRenderer());
     $this->app->fields->add(new StringField());
 }
 protected function before()
 {
     $this->cookies = Mockster::of(CookieStore::class);
     $factory = new Factory();
     $this->app = $factory->getInstance(WebApplication::class);
     $this->resource = new ExecuteResource(new Factory(), $this->app, Mockster::mock($this->cookies));
     $this->app->renderers->add(new PrimitiveRenderer());
     $this->app->fields->add(new StringField());
 }
Beispiel #7
0
 public function __construct($name = NULL, array $data = array(), $dataName = '')
 {
     parent::__construct($name, $data, $dataName);
     $factory = new Factory();
     $this->fixtureProvider = new FixtureProvider($this, $factory);
     $factory->setProvider(Fixture::$CLASS, $this->fixtureProvider);
     $injector = new Injector($factory);
     $injector->injectPropertyAnnotations($this, array($this, 'annotationPropertyFilter'));
     $this->setTimeZone();
 }
Beispiel #8
0
 public function givenTheBoxContainer_In_WithBody($boxName, $folder, $body)
 {
     $namespace = $this->spec->getName(false) . ($folder ? '\\' . str_replace('/', '\\', $folder) : '');
     $className = ucfirst($boxName) . WebRouter::SUFFIX;
     $code = "namespace {$namespace}; class {$className} extends \\spec\\watoki\\boxes\\fixtures\\TestBox {\n            function getMockDirectory() {\n                return '{$folder}';\n            }\n            {$body}\n        }";
     eval($code);
     $fileName = ($folder ? $folder . '/' : '') . $className . '.php';
     $this->store->create(new File($code), $fileName);
     $fullClassName = $namespace . '\\' . $className;
     $this->boxes[$boxName] = new $fullClassName($this->factory);
     $this->factory->setSingleton($this->boxes[$boxName], $fullClassName);
 }
Beispiel #9
0
 /**
  * @param Factory $factory <-
  */
 public function __construct(Factory $factory)
 {
     $this->factory = $factory;
     $factory->setSingleton($this, get_class($this));
     $this->register((new GenericActionRepresenter(RootAction::class, $factory))->setHandler(function () {
         return new RootEntity();
     })->setName('Home'));
     $this->register((new GenericEntityRepresenter(RootEntity::class))->setName('Qrator'));
     $printDateTime = function (\DateTimeInterface $d) {
         return $d->format('Y-m-d H:i:s');
     };
     $this->register((new GenericEntityRepresenter(\DateTime::class))->setStringifier($printDateTime));
     $this->register((new GenericEntityRepresenter(\DateTimeImmutable::class))->setStringifier($printDateTime));
 }
Beispiel #10
0
 public function whenIGet_From($path, $resourceClass)
 {
     $request = $this->request->withTarget(Path::fromString($path))->withMethod('get');
     $stub = new TestDelivererStub($request);
     $router = new NoneRouter(RespondingTarget::factory($this->factory, $this->factory->getInstance($resourceClass)));
     $delivery = new WebDelivery($router, $stub, $stub);
     $stub->onDeliver(function (WebResponse $response) {
         if ($response instanceof ErrorResponse) {
             throw $response->getException();
         }
         $this->model = $response->getBody();
     });
     $delivery->run();
 }
Beispiel #11
0
 /**
  * @param Console $console
  * @param array $arguments Arguments as produced by the Parser
  * @throws \Exception If the class does not implement a "doExecute" method
  * @return void
  */
 public function execute(Console $console, array $arguments)
 {
     $injector = new Injector($this->factory);
     $methodName = $this->getExecutionMethodName();
     try {
         $method = new \ReflectionMethod($this, $methodName);
     } catch (\ReflectionException $e) {
         throw new \Exception("Command [" . get_class($this) . "] must implement the method [{$methodName}].");
     }
     $this->factory->setSingleton($console, Console::$CLASS);
     $resolved = $this->resolveFlags($method, $arguments);
     $filtered = $this->filter($method, $resolved);
     $arguments = $injector->injectMethodArguments($method, $filtered, $this->parameterInjectionFilter);
     $this->checkArguments($method, $resolved);
     $method->invokeArgs($this, $arguments);
 }
Beispiel #12
0
 /**
  * @param array $constructorArguments
  * @return object The Unit Under Test - an instance of the class, methods are not stubbed and the parent
  * constructor is called, mocks of dependencies are injected
  */
 public function __uut($constructorArguments = [])
 {
     $this->stubs->stubbedByDefault(false);
     $instance = $this->prepMock($this->factory->getInstance($this->class, $constructorArguments));
     $this->uuts[] = $instance;
     foreach ($this->propertyMocksters as $property => $mockster) {
         $this->properties[$property]->set($instance, $mockster->__mock());
     }
     return $instance;
 }
Beispiel #13
0
 private function createTargetFromClass($fullClassName, Request $request, Path $context)
 {
     $object = $this->factory->getInstance($fullClassName);
     $nextRequest = $request->withContext($request->getContext()->appendedAll($context->getElements()));
     $nextRequest = $nextRequest->withTarget(new Path(array_slice($request->getTarget()->getElements(), count($context->getElements()))));
     if ($object instanceof Responding) {
         return new RespondingTarget($nextRequest, $object);
     } else {
         return new ObjectTarget($nextRequest, $object, $this->factory);
     }
 }
Beispiel #14
0
 /**
  * @param $name
  * @throws \BadMethodCallException If the method does not exist
  * @return mixed
  */
 protected function invoke($name)
 {
     try {
         $reflection = new \ReflectionMethod($this->object, $name);
     } catch (\ReflectionException $e) {
         $class = get_class($this->object);
         throw new \BadMethodCallException("Method [{$name}] does not exist in [{$class}]");
     }
     $this->factory->setProvider(Request::$REQUEST_CLASS, new CallbackProvider(function () {
         return $this->request;
     }));
     $analyzer = new MethodAnalyzer($reflection);
     $arguments = $this->request->getArguments()->toArray();
     $arguments = $this->filter($analyzer, $arguments);
     $factory = $this->factory;
     $arguments = $analyzer->fillParameters($arguments, function ($class) use($factory) {
         return $factory->getInstance($class);
     }, $this->parameterInjectionFilter);
     return $reflection->invokeArgs($this->object, $arguments);
 }
 /**
  * @param callable|object|string $handler
  * @return callable
  */
 protected function makeCallable($handler)
 {
     if (is_callable($handler)) {
         return $handler;
     } else {
         $classReflection = new \ReflectionClass($this->getClass());
         $methodName = lcfirst($classReflection->getShortName());
         return function ($action) use($handler, $methodName) {
             $handler = is_object($handler) ? $handler : $this->factory->getInstance($handler);
             if (!method_exists($handler, $methodName) && !method_exists($handler, '__call')) {
                 $class = get_class($handler);
                 throw new \InvalidArgumentException("Method [{$class}::{$methodName}] does not exist.");
             }
             return call_user_func(array($handler, $methodName), $action);
         };
     }
 }
Beispiel #16
0
 function after(Factory $factory)
 {
     assert($factory->getInstance(\DateTime::class) == new \DateTime('yesterday'));
 }
Beispiel #17
0
 public function __construct(Factory $factory)
 {
     $this->domin = $factory->getInstance(WebApplication::class);
 }
Beispiel #18
0
 function withRegisteredListener()
 {
     $this->factory->setSingleton($this->listener, TimeConsoleListener::class);
     $this->whenIExecuteTheCommandWithTheArguments(['-lTime']);
     $this->thenTheListenerShouldHaveReceivedSomething();
 }
Beispiel #19
0
 function __construct(Factory $factory, TestRunConfiguration $config, TestName $parent)
 {
     $factory->setSingleton($this, get_class($config));
     $this->config = $config;
     $this->parent = $parent;
 }
Beispiel #20
0
 /**
  * @param Factory $factory <-
  * @param ActionRegistry $actions <-
  * @param FieldRegistry $fields <-
  * @param RendererRegistry $renderers <-
  * @param LinkRegistry $links <-
  * @param IdentifiersProvider $identifiers <-
  * @param TypeFactory $types <-
  * @param MobileDetector $detect <-
  * @param WebCommentParser $parser <-
  * @param AccessControl $access <-
  */
 public function __construct(Factory $factory, ActionRegistry $actions, FieldRegistry $fields, RendererRegistry $renderers, LinkRegistry $links, IdentifiersProvider $identifiers, TypeFactory $types, MobileDetector $detect, WebCommentParser $parser, AccessControl $access)
 {
     $factory->setSingleton($this);
     $this->factory = $factory;
     $this->actions = $actions;
     $this->renderers = $renderers;
     $this->links = $links;
     $this->types = $types;
     $this->fields = $fields;
     $this->identifiers = $identifiers;
     $this->detector = $detect;
     $this->parser = $parser;
     $this->access = $access;
     $this->menu = new Menu($actions);
     $this->groups = new ActionGroups($actions);
 }
Beispiel #21
0
 public function thenAnInstanceOf_ShouldBeTheSingletonOf($userClass, $baseClass)
 {
     $this->instance = $this->myFactory->getInstance($baseClass);
     $this->spec->assertInstanceOf($userClass, $this->instance);
 }
Beispiel #22
0
 /**
  * @param Request $request
  * @return Target
  */
 public function create(Request $request)
 {
     return $this->factory->getInstance($this->targetClass, array_merge(array('request' => $request), $this->arguments));
 }
Beispiel #23
0
 /**
  * @param Assert $assert <-
  * @param Factory $factory <-
  */
 function __construct(Assert $assert, Factory $factory)
 {
     parent::__construct($assert);
     $factory->setSingleton($this);
 }
Beispiel #24
0
 private function executeCommand(Assert $assert, $arguments = [], $shouldReturn = 0)
 {
     $factory = new Factory();
     $factory->setSingleton(new RunTestByName_Configuration($this->files->fullPath(), $this->test, $this->listener), TestRunConfiguration::class);
     $command = new ScrutCommand(new ConfigurationReader($this->files->fullPath(), $factory));
     $returned = $command->execute($arguments);
     $assert($returned, $shouldReturn);
 }
Beispiel #25
0
 public static function run(Factory $factory, Console $console = null)
 {
     global $argv;
     /** @var self $app */
     $app = $factory->getInstance(self::class);
     return $app->doRun($console ?: new Console($argv));
 }
Beispiel #26
0
 /**
  * @return Renderer
  */
 protected function createDefaultRenderer()
 {
     return $this->factory->getInstance(Renderer::RENDERER);
 }
Beispiel #27
0
 public function __construct(Factory $factory, callable $internalInjector = null)
 {
     $this->injector = $internalInjector ?: function ($class) use($factory) {
         return $factory->getInstance($class);
     };
 }
Beispiel #28
0
 public static function quickResponse($respondingClass, Factory $factory = null)
 {
     $targetFactory = RespondingTarget::factory(self::$factory, self::$factory->getInstance($respondingClass));
     self::quickRoute(new NoneRouter($targetFactory));
 }
Beispiel #29
0
 /**
  * @param Factory $factory <-
  * @param string $directory
  * @param string $namespace
  * @param string $suffix
  */
 function __construct(Factory $factory, $directory, $namespace, $suffix = self::SUFFIX)
 {
     $store = $factory->getInstance(FlatFileStore::class, array('basePath' => $directory));
     parent::__construct($factory, $store, $namespace, $suffix);
 }
Beispiel #30
0
 /**
  * @param null|string $file
  * @param array $mergeWith
  * @return TestRunConfiguration
  */
 public function read($file = null, array $mergeWith = [])
 {
     $config = array_replace_recursive(self::$defaultConfiguration, $this->readFromFile($file), $mergeWith);
     return $this->factory->getInstance(TestRunConfiguration::class, [$this->factory, $this->cwd, $config]);
 }