/**
  * @return \Spot\Locator
  */
 private static function create()
 {
     $cfg = new \Spot\Config();
     $adapter = $cfg->addConnection(static::$connectionName, static::getParamsConnection());
     $adapter->getConfiguration()->setSQLLogger(self::logger());
     return new \Spot\Locator($cfg);
 }
Example #2
0
 /**
  * Test that the index page grabs a collection of talks
  * and successfully displays them
  *
  * @test
  */
 public function indexPageDisplaysTalksCorrectly()
 {
     $app = new Application(BASE_PATH, Environment::testing());
     ob_start();
     $app->run();
     ob_end_clean();
     // Create a pretend user
     $user = m::mock('StdClass');
     $user->shouldReceive('hasPermission')->with('admin')->andReturn(true);
     $user->shouldReceive('getId')->andReturn(1);
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $app['sentry'] = $sentry;
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $app['spot'] = new \Spot\Locator($cfg);
     // Create a fake request
     $req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $req->shouldReceive('get')->with('page')->andReturn(1);
     $req->shouldReceive('get')->with('sort')->andReturn('title');
     $req->shouldReceive('getRequestUri')->andReturn('foo');
     $this->createTestData($app['spot']);
     $controller = new \OpenCFP\Http\Controller\Admin\TalksController();
     $controller->setApplication($app);
     $response = $controller->indexAction($req, $app);
     $this->assertContains('Test Title', (string) $response);
     $this->assertContains('Test User', (string) $response);
 }
Example #3
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     ob_start();
     $this->app->run();
     ob_end_clean();
     // Override things so that Spot2 is using in-memory tables
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     // Initialize the talk table in the sqlite database
     $talk_mapper = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
     $talk_mapper->migrate();
     // Set things up so Sentry believes we're logged in
     $user = m::mock('StdClass');
     $user->shouldReceive('getId')->andReturn(uniqid());
     $user->shouldReceive('getLogin')->andReturn(uniqid() . '@grumpy-learning.com');
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user);
     $this->app['sentry'] = $sentry;
     // Create a test double for sessions so we can control what happens
     $this->app['session'] = new SessionDouble();
     // Create our test double for the request object
     $this->req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
 }
 public function register(Container $c)
 {
     $servicePrefix = $this->servicePrefix;
     $c[$servicePrefix . 'spot.connections.default'] = null;
     $c[$servicePrefix . 'spot'] = function () use($c, $servicePrefix) {
         return new Spot\Locator($c[$servicePrefix . 'spot.config']);
     };
     $c[$servicePrefix . 'spot.config'] = function () use($c, $servicePrefix) {
         $config = new Spot\Config();
         if (isset($c[$servicePrefix . 'spot.connections'])) {
             $connections = $c[$servicePrefix . 'spot.connections'];
         } else {
             $connections = $c['spot.connections'];
         }
         // foreach does not work with a Pimple container
         if ($connections instanceof Container) {
             $keys = $connections->keys();
         } else {
             $keys = array_keys($connections);
         }
         foreach ($keys as $key) {
             if (isset($c[$servicePrefix . 'spot.connections.default']) && $key === $c[$servicePrefix . 'spot.connections.default']) {
                 $default = true;
             } else {
                 $default = false;
             }
             $config->addConnection($key, $connections[$key], $default);
         }
         return $config;
     };
 }
Example #5
0
 public function testAddConnectionWithArray()
 {
     $cfg = new \Spot\Config();
     $dbalArray = ['dbname' => 'spot_test', 'user' => 'test', 'password' => 'password', 'host' => 'localhost', 'driver' => 'pdo_mysql'];
     $adapter = $cfg->addConnection('test_array', $dbalArray);
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $adapter);
 }
Example #6
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     $cfp = new \Spot\Config();
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
 }
Example #7
0
 public static function getInstace($config)
 {
     $impl = '\\Impl\\' . $config["app"]["implementation"];
     $implementation = new $impl();
     $cfg = new \Spot\Config();
     $cfg->addConnection($config["rds"]["driver"], $config["rds"]["connectionString"]);
     $spot = new \Spot\Locator($cfg);
     return new EntitySyncronizer($spot->mapper($implementation->entity()), $implementation);
 }
Example #8
0
 protected function setup()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\Talk');
     $this->mapper->migrate();
 }
function spot()
{
    static $spot;
    if ($spot === null) {
        $config = new \Spot\Config();
        $config->addConnection('mysql', 'mysql://*****:*****@$p0^^3D@localhost/employee_scheduling');
        $spot = new \Spot\Locator($config);
    }
    return $spot;
}
Example #10
0
 protected function setUp()
 {
     if (!class_exists("Spot\\Mapper")) {
         $this->markTestSkipped("Run composer install vlucas/spot to run Spot tests.");
     } else {
         $config = new \Spot\Config();
         $config->addConnection("sqlite", ["path" => "/tmp/test.sqlite", "driver" => "pdo_sqlite"]);
         $this->spot = new \Spot\Locator($config);
         $this->mapper = $this->spot->mapper("Beeper\\Test\\Dragon");
     }
 }
Example #11
0
 protected function setUp()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
     foreach ($this->entities as $entity) {
         $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\' . $entity)->migrate();
     }
 }
Example #12
0
 public static function getDbLocator()
 {
     if (is_null(self::$db)) {
         $config = \Spyc::YAMLLoad(self::getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.yml');
         $cfg = new \Spot\Config();
         $cfg->addConnection($config['name'], $config['dsn']);
         $spot = new \Spot\Locator($cfg);
         self::$db = $spot;
     }
     return self::$db;
 }
Example #13
0
 public function setUp()
 {
     $cfg = new \Spot\Config();
     $adapter = $cfg->addConnection('test_mysql', $_ENV['db_dsn']);
     $entity = '\\Fixture\\Auth\\UserEntity';
     $mapper = new \Spot\Mapper($cfg);
     $mapper->migrate($entity);
     $mapper->truncateDatasource($entity);
     $auth = \Saros\Auth::getInstance();
     $authAdapter = new \Saros\Auth\Adapter\Spot\Hash($mapper, $entity, "username", "password", "salt");
     $auth->setAdapter($authAdapter);
     $this->sharedFixture = array("Mapper" => $mapper, "EntityName" => $entity, "Auth" => $auth);
 }
Example #14
0
 protected function setUp()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     // Create an in-memory database
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $this->app['spot'] = new \Spot\Locator($cfg);
     $this->mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Favorite::class);
     $this->mapper->migrate();
     // Create a talk
     $talk_mapper = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\Talk::class);
     $data = ['title' => 'Favorite Entity Test', 'description' => 'This is a stubbed talk for a Favorite Entity Test', 'user_id' => 1];
     $talk_mapper->migrate();
     $this->talk = $talk_mapper->create($data);
 }
 /**
  * Test that the index page returns a list of talks associated
  * with a specific user and information about that user as well
  *
  * @test
  */
 public function indexDisplaysUserAndTalks()
 {
     $bootstrap = new \OpenCFP\Bootstrap();
     $app = $bootstrap->getApp();
     // Create an in-memory database for the test
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $app['spot'] = new \Spot\Locator($cfg);
     // Create a test user
     $user_mapper = $app['spot']->mapper('OpenCFP\\Entity\\User');
     $user_mapper->migrate();
     $user = $user_mapper->build(['email' => '*****@*****.**', 'password' => 'randompasswordhashed', 'first_name' => 'Test', 'last_name' => 'User', 'activated' => 1, 'transportation' => 0, 'hotel' => 0]);
     $user_mapper->save($user);
     $speaker_mapper = $app['spot']->mapper('OpenCFP\\Entity\\Speaker');
     $speaker_mapper->migrate();
     $speaker = $speaker_mapper->build(['user_id' => $user->id, 'photo_path' => '/path/to/photo', 'bio' => "This is speaker bio information", 'info' => "This is additional speaker infi"]);
     $speaker_mapper->save($speaker);
     // Create the favorite table
     $favorite_mapper = $app['spot']->mapper('OpenCFP\\Entity\\Favorite');
     $favorite_mapper->migrate();
     // Create a talk to display
     $talk_mapper = $app['spot']->mapper('OpenCFP\\Entity\\Talk');
     $talk_mapper->migrate();
     $talk = $talk_mapper->build(['title' => 'Test Title', 'description' => 'Test title description', 'user_id' => 1, 'type' => 'regular', 'category' => 'testing', 'level' => 'beginner', 'desired' => 1, 'slides' => 'slides', 'other' => 'other', 'sponsor' => 1, 'favorite' => 0, 'selected' => 0]);
     $talk_mapper->save($talk);
     // Set things up so Sentry believes we're logged in
     $user_mock = m::mock('StdClass');
     $user_mock->shouldReceive('hasPermission')->with('admin')->andReturn(true);
     $user_mock->shouldReceive('getId')->andReturn(1);
     // Create a test double for Sentry
     $sentry = m::mock('StdClass');
     $sentry->shouldReceive('check')->andReturn(true);
     $sentry->shouldReceive('getUser')->andReturn($user_mock);
     $app['sentry'] = $sentry;
     // Create a fake request object
     $req = m::mock('Symfony\\Component\\HttpFoundation\\Request');
     $req->shouldReceive('get')->with('page')->andReturn($user->id);
     // Instantiate the controller and run the indexAction
     $controller = new \OpenCFP\Controller\DashboardController();
     $response = $controller->indexAction($req, $app);
     $this->assertContains('Test Title', $response);
     $this->assertContains('Test User', $response);
 }
Example #16
0
/**
 * Created by PhpStorm.
 * User: Glenn
 * Date: 2015-10-05
 * Time: 9:15 AM
 */
use Skeleton\Controller\DefaultController;
use Skeleton\View\HtmlView;
use Skeleton\View\JsonView;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
return ["settings" => ['viewTemplatesDirectory' => "../templates", "session_name" => "VMS2", "db" => ['dsn' => 'mysql://root@localhost/skeleton'], 'title' => "Site Wide Title"], 'view' => function ($container) {
    $view = new Twig($container['settings']['viewTemplatesDirectory'], ['cache' => false]);
    // Instantiate and add Slim specific extension
    $view->addExtension(new TwigExtension($container['router'], $container['request']->getUri()));
    return $view;
}, 'locator' => function ($container) {
    $cfg = new \Spot\Config();
    // MySQL
    $cfg->addConnection('mysql', $container['settings']['db']['dsn']);
    // Sqlite
    //$cfg->addConnection('sqlite', 'sqlite://path/to/database.sqlite');
    return new \Spot\Locator($cfg);
}, 'html' => function ($container) {
    return new HtmlView($container['view'], $container['settings']['title']);
}, 'json' => function ($container) {
    return new JsonView($container['view']);
}, DefaultController::class => function ($container) {
    return new DefaultController($container['html']);
}];
<?php

$container = $app->getContainer();
// -----------------------------------------------------------------------------
// SPOT
// -----------------------------------------------------------------------------
$container['spot'] = function ($c) {
    $settings = $c->get('settings');
    $cfg = new \Spot\Config();
    $cfg->addConnection('mysql', ['dbname' => $settings['spot']['dbname'], 'user' => $settings['spot']['user'], 'password' => $settings['spot']['password'], 'host' => $settings['spot']['host'], 'driver' => $settings['spot']['driver']]);
    $spot = new \Spot\Locator($cfg);
    return $spot;
};
// -----------------------------------------------------------------------------
// TWIG
// -----------------------------------------------------------------------------
$container['view'] = function ($c) {
    $settings = $c->get('settings');
    $view = new \Slim\Views\Twig($settings['view']['template_path'], $settings['view']['twig']);
    // Add extensions
    $view->addExtension(new Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri()));
    $view->addExtension(new Twig_Extension_Debug());
    return $view;
};
// -----------------------------------------------------------------------------
// Monolog
// -----------------------------------------------------------------------------
$container['Logger'] = function ($c) {
    $settings = $c->get('settings');
    $logger = new Monolog\Logger($settings['logger']['name']);
    $stream = new Monolog\Handler\StreamHandler($settings['logger']['path'], Monolog\Logger::DEBUG);
Example #18
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\Slim(array('view' => new \Slim\Views\Twig()));
$view = $app->view();
$view->twigTemplateDirs = array(__DIR__ . '/../src/templates');
$view->parserOptions = array('debug' => true, 'cache' => __DIR__ . '/../cache');
$view->parserExtensions = array(new \Slim\Views\TwigExtension(), new \MyCode\Twig\TwigExtension());
$app->container->singleton('log', function () {
    $log = new \Monolog\Logger('web-app');
    $log->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__ . '/../log/log.txt'));
    return $log;
});
$app->container->singleton('db', function () {
    $cfg = new \Spot\Config();
    $cfg->addConnection("sqlite", ["path" => __DIR__ . "/../db/db2.sqlite", "driver" => "pdo_sqlite"]);
    $spot = new \Spot\Locator($cfg);
    return $spot;
});
# Middleware - checks user id value is correct
$app->add(new \MyCode\Middleware\Security\User($app->log));
$app->post('/process/trade-message', function () use($app) {
    $tmq = new \MyCode\Entity\TradeMessageQueue();
    $raw_request = $app->request->getBody();
    $tmq->id = hash("sha256", $raw_request);
    $tmq->body = $raw_request;
    $mapper = $app->db->mapper('MyCode\\Entity\\TradeMessageQueue');
    $mapper->save($tmq);
});
$app->get('/', function () use($app) {
    $app->render('homepage.twig');
Example #19
0
-<?php 
/**
 * @package Spot
 * @link http://spot.os.ly
 */
// Require Spot_Config
require_once dirname(__DIR__) . '/Config.php';
// Date setup
date_default_timezone_set('America/Chicago');
// Setup available adapters for testing
$cfg = new \Spot\Config();
// MySQL
$adapter = $cfg->addConnection('test_mysql', 'mysql://*****:*****@localhost/spot_test');
// MongoDB with adapter options
$adapter = $cfg->addConnection('test_mongodb', 'mongodb://localhost:28017', array('cursor' => array('timeout' => 10), 'mapper' => array('translate_id' => true)));
/**
 * Return Spot mapper for use
 */
$mapper = new \Spot\Mapper($cfg);
function test_spot_mapper()
{
    global $mapper;
    return $mapper;
}
/**
 * Autoload test fixtures
 */
function test_spot_autoloader($className)
{
    // Don't attempt to autoload 'PHPUnit_' or 'Spot' namespaced classes
    if (false !== strpos($className, 'PHPUnit_') || false !== strpos($className, 'Spot')) {
Example #20
0
 public function getSpot()
 {
     $cfg = new \Spot\Config();
     $cfg->addConnection('mysql', ['dbname' => $this->getConfig('database.database'), 'user' => $this->getConfig('database.user'), 'password' => $this->getConfig('database.password'), 'host' => $this->getConfig('database.host'), 'driver' => 'pdo_mysql']);
     return new \Spot\Locator($cfg);
 }
Example #21
0
 public function testAddConnectionWithDSNString()
 {
     $cfg = new \Spot\Config();
     $adapter = $cfg->addConnection('test_mysql', 'mysql://*****:*****@localhost/test');
     $this->assertTrue($adapter instanceof \Spot\Adapter\Mysql);
 }
Example #22
0
<?php

/**
* @package Spot
*/
error_reporting(-1);
ini_set('display_errors', 1);
/**
* Autoload test fixtures
*/
$autoload = (require dirname(dirname(__FILE__)) . '/vendor/autoload.php');
$autoload->add('SpotTest', __DIR__);
// Date setup
date_default_timezone_set('America/Chicago');
// Setup available adapters for testing
$cfg = new \Spot\Config();
$dbDsn = getenv('SPOT_DB_DSN');
if (!empty($dbDsn)) {
    $cfg->addConnection('test', $dbDsn);
} else {
    die('DSN not configured');
}
/**
* Return Spot mapper for use
*/
$spot = new Spot\Locator($cfg);
function test_spot_mapper($entityName)
{
    global $spot;
    // you should never do this in real code :)
    return $spot->mapper($entityName);
Example #23
0
<?php

/* To use this you must install vlucas/spot2 */
/* $ composer require vlucas/spot2 */
$container = $app->getContainer();
$container["spot"] = function ($c) {
    $config = new \Spot\Config();
    $mysql = $config->addConnection("mysql", ["dbname" => getenv("DB_NAME"), "user" => getenv("DB_USER"), "password" => getenv("DB_PASSWORD"), "host" => getenv("DB_HOST"), "driver" => "pdo_mysql", "charset" => "utf8"]);
    $spot = new \Spot\Locator($config);
    return $spot;
};
/* Setup Spot */
/* Log SQL queries. Make sure logger is configured. */
/*
$logger = new Doctrine\DBAL\Logging\MonologSQLLogger(Monolog\Registry::sql());
$mysql->getConfiguration()->setSQLLogger($logger);
*/
Example #24
0
<?php

// Initialization
require __DIR__ . '/config/settings.php';
require __DIR__ . '/config/constants.php';
// Dependencies by Composer
$autoloader = (require __VENDOR__ . '/autoload.php');
$autoloader->add('', __DIR__ . '/models/');
$autoloader->add('', __DIR__ . '/controllers/');
// Database by Spot ORM
$db_config = new \Spot\Config();
$db_config->addConnection('mysql', __DATABASE__);
$db = new \Spot\Locator($db_config);
// Templating by Twig
$loader = new Twig_Loader_Filesystem(__DIR__ . '/views');
$twig = new Twig_Environment($loader, array('cache' => false));
// Routing by AltoRouter
$router = new AltoRouter();
$routes = Symfony\Component\Yaml\Yaml::parse(file_get_contents("routing.yaml"));
foreach ($routes as $route_name => $params) {
    $router->map($params[0], $params[1], $params[2], $route_name);
}
$match = $router->match();
if ($match && is_callable(explode("#", $match['target']))) {
    // Get the page's file and data
    $target = call_user_func_array(explode("#", $match['target']), array("data" => $match['params']));
    echo $twig->render($target["file"], array('data' => $target["data"], 'params' => $match["params"]));
} else {
    // no route was matched
    header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
Example #25
0
 public function testConfigCanUnserialize()
 {
     $cfg = new \Spot\Config();
     $adapter = $cfg->addConnection('test_mysql', 'mysql://*****:*****@localhost/test');
     $this->assertInstanceOf('\\Spot\\Config', unserialize(serialize($cfg)));
 }
Example #26
0
<?php

/**
 * BobbaJuice - Badge Scanner
 * Scott Stamp <*****@*****.**>
 */
require "vendor/autoload.php";
use BobbaJuice\BadgeScanner\Scanner;
$cfg = new \Spot\Config();
$cfg->addConnection('mysql', 'mysql://*****:*****@localhost/badges');
$spot = new \Spot\Locator($cfg);
$badgeMapper = $spot->mapper('BobbaJuice\\BadgeScanner\\Entity\\Badge');
$badges = Scanner::Scan("de");
foreach ($badges as $badge) {
    try {
        $badgeMapper->create(['code' => $badge->code, 'name' => $badge->name, 'description' => $badge->description]);
    } catch (Exception $exception) {
    }
}