Exemplo n.º 1
0
 /** @test */
 public function shouldReturnToken()
 {
     $token = 'token';
     $curlRequestMock = \Mockery::mock('\\slackbot\\util\\CurlRequest');
     $slackApi = new SlackApi($curlRequestMock);
     $slackApi->setToken($token);
     $this->assertEquals($token, $slackApi->getToken());
 }
Exemplo n.º 2
0
 public function buildContainer(ArgvParser $argvParser, Config $config = null)
 {
     $container = new Container();
     $container['started'] = time();
     $container['config'] = function () use($config, $container) {
         return null !== $config ? $config : new Config($container['yaml_parser'], $container['file_loader']);
     };
     $container['variables_placer'] = function () {
         return new VariablesPlacer();
     };
     $container['cron_expression'] = function () {
         return CronExpression::factory('@daily');
     };
     $container['argv_parser'] = function () use($argvParser) {
         return $argvParser;
     };
     $container['yaml_parser'] = function () {
         return new Parser();
     };
     $container['file_loader'] = function () {
         return new FileLoader();
     };
     $container['curl_request'] = function () {
         return new CurlRequest();
     };
     $container['post_parser'] = function () {
         return new PostParser();
     };
     $container['slack_api'] = function (Container $container) {
         $slackApi = new SlackApi($container['curl_request']);
         $token = $container['config']->getEntry('auth.token');
         if ($token !== null) {
             $slackApi->setToken($token);
         }
         return $slackApi;
     };
     $container['slack_facade'] = function (Container $container) {
         return new SlackFacade($container['slack_api']);
     };
     $container['names_resolver'] = function (Container $container) {
         return new NamesResolver($container['slack_facade']);
     };
     $container['condition_resolver'] = function () {
         return new ConditionResolver();
     };
     $container['handler_execution_resolver'] = function (Container $container) {
         return new HandlerExecutionResolver($container['config'], $container['slack_api']);
     };
     $container['core_processor'] = function (Container $container) {
         return new CoreProcessor($container['slack_facade'], $container['handler_execution_resolver']);
     };
     $container['output_manager'] = function (Container $container) {
         return new OutputManager($container['slack_facade']);
     };
     $container['api_cache'] = function () {
         return new ApiCache(new MemoryStorage());
     };
     $container['action_send_message'] = function (Container $container) {
         return new SendMessageActionHandler($container['slack_facade'], $container['output_manager']);
     };
     $container['action_set_variable'] = function (Container $container) {
         return new SetVariableActionHandler($container['slack_facade']);
     };
     $container['action_if'] = function (Container $container) {
         $handler = new IfActionHandler($container['slack_facade'], $container['condition_resolver']);
         $handler->setCoreProcessor($container['core_processor']);
         return $handler;
     };
     $container['action_loop'] = function (Container $container) {
         $handler = new LoopActionHandler($container['slack_facade'], $container['condition_resolver']);
         $handler->setCoreProcessor($container['core_processor']);
         return $handler;
     };
     $container['action_user_input'] = function (Container $container) {
         return new UserInputActionHandler($container['slack_facade'], $container['core_processor']);
     };
     $container['action_continue'] = function () {
         return new ContinueActionHandler();
     };
     $container['action_break'] = function () {
         return new BreakActionHandler();
     };
     $container['action_run_command'] = function (Container $container) {
         return new RunCommandActionHandler($container['slack_facade']);
     };
     $container['core_processor']->addActionHandler($container['action_send_message']);
     $container['core_processor']->addActionHandler($container['action_set_variable']);
     $container['core_processor']->addActionHandler($container['action_if']);
     $container['core_processor']->addActionHandler($container['action_loop']);
     $container['core_processor']->addActionHandler($container['action_user_input']);
     $container['core_processor']->addActionHandler($container['action_continue']);
     $container['core_processor']->addActionHandler($container['action_break']);
     $container['core_processor']->addActionHandler($container['action_run_command']);
     if (class_exists('\\slackbot\\handlers\\command\\TestCommandHandler')) {
         $container['command_test'] = function () {
             return new \slackbot\handlers\command\TestCommandHandler();
         };
         $container['core_processor']->addCommandHandler($container['command_test']);
     }
     $container['command_restart'] = function () {
         return new RestartCommandHandler();
     };
     $container['core_processor']->addCommandHandler($container['command_restart']);
     $container['command_status'] = function () {
         return new StatusCommandHandler();
     };
     $container['core_processor']->addCommandHandler($container['command_status']);
     $container['server'] = $this->buildServer();
     return $container;
 }