Esempio n. 1
0
 /**
  *
  * @expectedException \Exception
  * @expectedExceptionMessage Can't create Email record
  * @throws Exception
  */
 public function testGetException()
 {
     $service = new Email();
     $service->setDataSource(new PDOMock());
     $rowCount = $service->create([]);
     $this->assertInternalType('int', $rowCount);
 }
Esempio n. 2
0
 /**
  * Load the services.
  *
  * @return array
  */
 public function getServiceConfig()
 {
     return array('initializers' => array('DataSourceAwareInterface' => function ($instance, $sm) {
         if ($instance instanceof Lib\DataSourceAwareInterface) {
             $instance->setDataSource($sm->get('PDO'));
         }
     }, 'QueueConnectionAwareInterface' => function ($instance, $sm) {
         if ($instance instanceof QueueConnectionAwareInterface) {
             $i = $sm->get('Stjornvisi\\Lib\\QueueConnectionFactory');
             $instance->setQueueConnectionFactory($sm->get('Stjornvisi\\Lib\\QueueConnectionFactory'));
         }
     }, 'LoggerAwareInterface' => function ($instance, $sm) {
         if ($instance instanceof LoggerAwareInterface) {
             $instance->setLogger($sm->get('Logger'));
         }
     }, 'DataStoreInterface' => function ($instance, $sm) {
         if ($instance instanceof DataStoreInterface) {
             $instance->setDateStore($sm->get('PDO\\Config'));
         }
     }, 'NotifyEventManagerAwareInterface' => function ($instance, $sm) {
         if ($instance instanceof NotifyEventManagerAwareInterface) {
             $instance->setEventManager($sm->get('ServiceEventManager'));
         }
     }, 'ServiceEventManagerAwareInterface' => function ($instance, $sm) {
         if ($instance instanceof ServiceEventManagerAwareInterface) {
             $instance->setEventManager($sm->get('ServiceEventManager'));
         }
     }), 'invokables' => ['Stjornvisi\\Service\\User' => 'Stjornvisi\\Service\\User', 'Stjornvisi\\Service\\Company' => 'Stjornvisi\\Service\\Company', 'Stjornvisi\\Service\\Event' => 'Stjornvisi\\Service\\Event', 'Stjornvisi\\Service\\Group' => 'Stjornvisi\\Service\\Group', 'Stjornvisi\\Service\\News' => 'Stjornvisi\\Service\\News', 'Stjornvisi\\Service\\Board' => 'Stjornvisi\\Service\\Board', 'Stjornvisi\\Service\\Article' => 'Stjornvisi\\Service\\Article', 'Stjornvisi\\Service\\Page' => 'Stjornvisi\\Service\\Page', 'Stjornvisi\\Service\\Values' => 'Stjornvisi\\Service\\Values', 'Stjornvisi\\Service\\Conference' => 'Stjornvisi\\Service\\Conference', 'Stjornvisi\\Service\\Skeleton' => 'Stjornvisi\\Service\\Skeleton', 'Stjornvisi\\Service\\Anaegjuvogin' => 'Stjornvisi\\Service\\Anaegjuvogin', 'Stjornvisi\\Notify\\Submission' => 'Stjornvisi\\Notify\\Submission', 'Stjornvisi\\Notify\\Event' => 'Stjornvisi\\Notify\\Event', 'Stjornvisi\\Notify\\Password' => 'Stjornvisi\\Notify\\Password', 'Stjornvisi\\Notify\\Group' => 'Stjornvisi\\Notify\\Group', 'Stjornvisi\\Notify\\All' => 'Stjornvisi\\Notify\\All', 'Stjornvisi\\Notify\\Attend' => 'Stjornvisi\\Notify\\Attend', 'Stjornvisi\\Notify\\UserValidate' => 'Stjornvisi\\Notify\\UserValidate', 'Stjornvisi\\Notify\\Digest' => 'Stjornvisi\\Notify\\Digest', 'Stjornvisi\\Event\\SystemExceptionListener' => 'Stjornvisi\\Event\\SystemExceptionListener', 'Stjornvisi\\Event\\PersistenceLoginListener' => 'Stjornvisi\\Event\\PersistenceLoginListener', 'Stjornvisi\\Event\\LayoutSelectListener' => 'Stjornvisi\\Event\\LayoutSelectListener', 'Stjornvisi\\Event\\NotifyListener' => 'Stjornvisi\\Event\\NotifyListener', 'Imagine\\Image\\Imagine' => 'Imagine\\Gd\\Imagine', 'Stjornvisi\\Auth\\Adapter' => 'Stjornvisi\\Auth\\Adapter', 'Stjornvisi\\Auth\\Facebook' => 'Stjornvisi\\Auth\\Facebook', 'AuthenticationService' => 'Zend\\Authentication\\AuthenticationService'], 'aliases' => array('UserService' => 'Stjornvisi\\Service\\User', 'GroupService' => 'Stjornvisi\\Service\\Group', 'Zend\\Authentication\\AuthenticationService' => 'AuthenticationService'), 'factories' => array('Logger' => function ($sm) {
         $log = new Logger('stjornvisi');
         $log->pushHandler(new StreamHandler('php://stdout'));
         $evn = getenv('APPLICATION_ENV') ?: 'production';
         if ($evn == 'development') {
             //...
         } else {
             $handler = new StreamHandler('./data/log/error.json', Logger::ERROR);
             $handler->setFormatter(new \Stjornvisi\Lib\JsonFormatter());
             $log->pushHandler($handler);
             $handler = new StreamHandler('./data/log/system.log');
             $handler->setFormatter(new JsonFormatter());
             $log->pushHandler($handler);
             $log->pushHandler(new SlackHandler("xoxp-3745519896-3745519908-3921078470-26445a", "#stjornvisi", "Angry Hamster", true, null, Logger::CRITICAL));
         }
         return $log;
     }, 'ServiceEventManager' => function ($sm) {
         $logger = $sm->get('Logger');
         $manager = new EventManager();
         $manager->attach(new ErrorEventListener($logger));
         $manager->attach(new ServiceEventListener($logger));
         $activityListener = new ActivityListener($logger);
         $activityListener->setQueueConnectionFactory($sm->get('Stjornvisi\\Lib\\QueueConnectionFactory'));
         $manager->attach($activityListener);
         return $manager;
     }, 'Stjornvisi\\Service\\Map' => function ($sm) {
         return new JaMap(new Client());
     }, 'Stjornvisi\\Service\\Email' => function ($sm) {
         $config = $sm->get('config');
         $obj = new Email();
         $obj->setDataSource(new PDO($config['tracker']['dns'], $config['tracker']['user'], $config['tracker']['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ)));
         return $obj;
     }, 'PDO\\Config' => function ($sm) {
         $config = $sm->get('config');
         return array('dns' => $config['db']['dns'], 'user' => $config['db']['user'], 'password' => $config['db']['password'], 'options' => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ));
     }, 'PDO' => function ($sm) {
         $config = $sm->get('PDO\\Config');
         return new PDO($config['dns'], $config['user'], $config['password'], $config['options']);
     }, 'MailTransport' => function ($sm) {
         $evn = getenv('APPLICATION_ENV') ?: 'production';
         if ($evn == 'development') {
             $transport = new FileTransport();
             $transport->setOptions(new FileOptions(['path' => './data/', 'callback' => function (FileTransport $transport) {
                 return 'Message_' . microtime(true) . '.eml';
             }]));
             return $transport;
         } else {
             $transport = new SmtpTransport();
             $protocol = new \Zend\Mail\Protocol\Smtp();
             $transport->setConnection($protocol);
             return $transport;
         }
     }, 'Stjornvisi\\Lib\\QueueConnectionFactory' => function ($sm) {
         $evn = getenv('APPLICATION_ENV') ?: 'production';
         if ($evn == 'testing') {
             return new QueueConnectionFactoryStub();
         }
         $config = $sm->get('config');
         $queue = new QueueConnectionFactory();
         $queue->setConfig($config['queue']);
         return $queue;
     }, 'Stjornvisi\\Form\\NewUserCompanySelect' => function ($sm) {
         return new NewUserCompanySelect($sm->get('Stjornvisi\\Service\\Company'));
     }, 'Stjornvisi\\Form\\NewUserCompany' => function ($sm) {
         return new NewUserCompany($sm->get('Stjornvisi\\Service\\Values'), $sm->get('Stjornvisi\\Service\\Company'));
     }, 'Stjornvisi\\Form\\NewUserUniversitySelect' => function ($sm) {
         return new NewUserUniversitySelect($sm->get('Stjornvisi\\Service\\Company'));
     }, 'Stjornvisi\\Form\\NewUserIndividual' => function ($sm) {
         return new NewUserIndividual($sm->get('Stjornvisi\\Service\\Values'), $sm->get('Stjornvisi\\Service\\Company'));
     }, 'Stjornvisi\\Form\\NewUserCredentials' => function ($sm) {
         return new NewUserCredentials($sm->get('Stjornvisi\\Service\\Values'), $sm->get('Stjornvisi\\Service\\User'));
     }, 'Stjornvisi\\Form\\Company' => function ($sm) {
         return new CompanyForm($sm->get('Stjornvisi\\Service\\Values'), $sm->get('Stjornvisi\\Service\\Company'));
     }, 'Stjornvisi\\Queue' => function () {
         $con = new AMQPConnection('localhost', 5672, 'guest', 'guest');
         return $con;
     }), 'shared' => array('Stjornvisi\\Service\\Email' => false, 'Stjornvisi\\Queue' => false));
 }