예제 #1
0
 public function registerHooks()
 {
     foreach ($this->hooks as $config) {
         $this->functions->invoke("add_{$config->getType()}", [$config->getHookName(), $this->functions->create(function () use($config) {
             $context = new HookContext($config);
             return $config->getHook()->execute($context);
         }), $config->getPriority() ?: HookConfiguration::DEFAULT_PRIORITY, $config->getAcceptedArgumentsCount() ?: HookConfiguration::DEFAULT_ACCEPTED_ARGS]);
     }
 }
 private function shouldRegisterHookWithFunctionNamePriorityAndAcceptedArgs(FunctionWrapper $functionWrapper, Hook $hook, HookConfiguration $config, $function, $name, $priority, $args)
 {
     // We're testing that add_action or add_filter will be called with a function that when invoked
     // will execute the hook using the correct context
     $functionWrapper->create(Argument::that(function ($callable) use($hook, $config) {
         $callable();
         $hook->execute(Argument::that(function (HookContext $context) use($config) {
             return $context->getConfig() == $config->getWrappedObject();
         }))->shouldHaveBeenCalled();
         return true;
     }))->willReturn('imaginary_function_name')->shouldBeCalled();
     $functionWrapper->invoke($function, array($name, 'imaginary_function_name', $priority, $args))->shouldBeCalled();
     $this->registerHooks();
 }
 public function addSideWidget(Widget $widget)
 {
     $this->functions->invoke('add_meta_box', [$widget->getSlug(), $widget->getTitle(), $this->functions->create(array($widget, 'render')), 'dashboard']);
 }
 public function testThrowsExceptionWhenFunctionNotFound()
 {
     $this->setExpectedException('AdamQuaile\\PhpGlobal\\Functions\\Exceptions\\FunctionNotFound');
     $this->functions->invoke('not_found_function');
 }