コード例 #1
0
ファイル: TestRunConfiguration.php プロジェクト: rtens/scrut
 function __construct(Factory $factory, $workingDirectory, array $config)
 {
     $factory->setSingleton($this);
     $this->workingDirectory = $workingDirectory;
     $this->config = $config;
     $this->factory = $factory;
 }
コード例 #2
0
ファイル: Admin.php プロジェクト: rtens/domin-sample
 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));
 }
コード例 #3
0
ファイル: ListActionsSpec.php プロジェクト: rtens/domin
 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();
 }
コード例 #4
0
 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]])]);
 }
コード例 #5
0
 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());
 }
コード例 #6
0
 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());
 }
コード例 #7
0
ファイル: Specification.php プロジェクト: watoki/scrut
 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();
 }
コード例 #8
0
ファイル: BoxFixture.php プロジェクト: watoki/boxes
 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);
 }
コード例 #9
0
ファイル: RepresenterRegistry.php プロジェクト: watoki/qrator
 /**
  * @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));
 }
コード例 #10
0
ファイル: WebFixture.php プロジェクト: jonfm/domin
 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();
 }
コード例 #11
0
ファイル: DefaultCommand.php プロジェクト: watoki/cli
 /**
  * @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);
 }
コード例 #12
0
ファイル: Mockster.php プロジェクト: rtens/mockster
 /**
  * @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;
 }
コード例 #13
0
ファイル: StaticRouter.php プロジェクト: watoki/deli
 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);
     }
 }
コード例 #14
0
ファイル: ObjectTarget.php プロジェクト: watoki/deli
 /**
  * @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);
 }
コード例 #15
0
 /**
  * @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);
         };
     }
 }
コード例 #16
0
ファイル: RunPlainTestSuites.php プロジェクト: rtens/scrut
 function after(Factory $factory)
 {
     assert($factory->getInstance(\DateTime::class) == new \DateTime('yesterday'));
 }
コード例 #17
0
 public function __construct(Factory $factory)
 {
     $this->domin = $factory->getInstance(WebApplication::class);
 }
コード例 #18
0
ファイル: SetListeners.php プロジェクト: rtens/scrut
 function withRegisteredListener()
 {
     $this->factory->setSingleton($this->listener, TimeConsoleListener::class);
     $this->whenIExecuteTheCommandWithTheArguments(['-lTime']);
     $this->thenTheListenerShouldHaveReceivedSomething();
 }
コード例 #19
0
ファイル: LinkedConfiguration.php プロジェクト: rtens/scrut
 function __construct(Factory $factory, TestRunConfiguration $config, TestName $parent)
 {
     $factory->setSingleton($this, get_class($config));
     $this->config = $config;
     $this->parent = $parent;
 }
コード例 #20
0
ファイル: WebApplication.php プロジェクト: rtens/domin
 /**
  * @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);
 }
コード例 #21
0
ファイル: LoaderFixture.php プロジェクト: watoki/cfg
 public function thenAnInstanceOf_ShouldBeTheSingletonOf($userClass, $baseClass)
 {
     $this->instance = $this->myFactory->getInstance($baseClass);
     $this->spec->assertInstanceOf($userClass, $this->instance);
 }
コード例 #22
0
ファイル: TargetFactory.php プロジェクト: watoki/deli
 /**
  * @param Request $request
  * @return Target
  */
 public function create(Request $request)
 {
     return $this->factory->getInstance($this->targetClass, array_merge(array('request' => $request), $this->arguments));
 }
コード例 #23
0
ファイル: FilesFixture.php プロジェクト: rtens/scrut
 /**
  * @param Assert $assert <-
  * @param Factory $factory <-
  */
 function __construct(Assert $assert, Factory $factory)
 {
     parent::__construct($assert);
     $factory->setSingleton($this);
 }
コード例 #24
0
ファイル: RunTestByName.php プロジェクト: rtens/scrut
 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);
 }
コード例 #25
0
ファイル: CliApplication.php プロジェクト: rtens/domin
 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));
 }
コード例 #26
0
ファイル: Resource.php プロジェクト: watoki/curir
 /**
  * @return Renderer
  */
 protected function createDefaultRenderer()
 {
     return $this->factory->getInstance(Renderer::RENDERER);
 }
コード例 #27
0
ファイル: Injector.php プロジェクト: watoki/factory
 public function __construct(Factory $factory, callable $internalInjector = null)
 {
     $this->injector = $internalInjector ?: function ($class) use($factory) {
         return $factory->getInstance($class);
     };
 }
コード例 #28
0
ファイル: IntroductionTest.php プロジェクト: watoki/curir
 public static function quickResponse($respondingClass, Factory $factory = null)
 {
     $targetFactory = RespondingTarget::factory(self::$factory, self::$factory->getInstance($respondingClass));
     self::quickRoute(new NoneRouter($targetFactory));
 }
コード例 #29
0
ファイル: WebRouter.php プロジェクト: watoki/curir
 /**
  * @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);
 }
コード例 #30
0
ファイル: ConfigurationReader.php プロジェクト: rtens/scrut
 /**
  * @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]);
 }