Skip to content

Commit

Permalink
Merge pull request #313 from glensc/pimple-3
Browse files Browse the repository at this point in the history
Update pimple/pimple (v1.1.1 => v3.3.0)
  • Loading branch information
glensc committed Aug 31, 2020
2 parents 453ff9a + 40d65cd commit 0b80259
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"slim/slim": "^2.6.3",
"slim/views": "^0.1.0",
"twig/twig": "~1.17",
"pimple/pimple": "^1.0.2",
"pimple/pimple": "^3.3",
"perftools/xhgui-collector": "^1.7.0"
},
"require-dev": {
Expand Down
21 changes: 13 additions & 8 deletions src/Xhgui/ServiceContainer.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

use Pimple\Container;
use Slim\Slim;
use Slim\Views\Twig;
use Slim\Middleware\SessionCookie;

class Xhgui_ServiceContainer extends Pimple
class Xhgui_ServiceContainer extends Container
{
/** @var self */
protected static $_instance;

/**
* @return self
*/
public static function instance()
{
if (empty(static::$_instance)) {
Expand Down Expand Up @@ -43,7 +49,7 @@ protected function _slimApp()
return $view;
};

$this['app'] = $this->share(static function ($c) {
$this['app'] = static function ($c) {
if ($c['config']['timezone']) {
date_default_timezone_set($c['config']['timezone']);
}
Expand All @@ -65,7 +71,7 @@ protected function _slimApp()
$app->view($view);

return $app;
});
};
}

/**
Expand All @@ -75,7 +81,7 @@ protected function _services()
{
$this['config'] = Xhgui_Config::all();

$this['db'] = $this->share(static function ($c) {
$this['db'] = static function ($c) {
$config = $c['config'];
if (empty($config['db.options'])) {
$config['db.options'] = [];
Expand All @@ -87,15 +93,15 @@ protected function _services()
$mongo->{$config['db.db']}->results->findOne();

return $mongo->{$config['db.db']};
});
};

$this['pdo'] = $this->share(static function ($c) {
$this['pdo'] = static function ($c) {
return new PDO(
$c['config']['pdo']['dsn'],
$c['config']['pdo']['user'],
$c['config']['pdo']['pass']
);
});
};

$this['searcher.mongo'] = static function ($c) {
return new Xhgui_Searcher_Mongo($c['db']);
Expand Down Expand Up @@ -159,5 +165,4 @@ protected function _controllers()
return new Xhgui_Controller_Metrics($c['app'], $c['searcher']);
};
}

}
6 changes: 1 addition & 5 deletions tests/Controller/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ public function setUp()
]);

$di = Xhgui_ServiceContainer::instance();
$mock = $this->getMockBuilder(Slim::class)
$di['app'] = $this->getMockBuilder(Slim::class)
->setMethods(['redirect', 'render', 'urlFor'])
->setConstructorArgs([$di['config']])
->getMock();

$di['app'] = $di->share(static function ($c) use ($mock) {
return $mock;
});
$this->import = $di['importController'];

$this->profiles = $di['searcher'];
$this->profiles->truncate();
}
Expand Down
5 changes: 1 addition & 4 deletions tests/Controller/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ public function setUp()
]);

$di = Xhgui_ServiceContainer::instance();
$mock = $this->getMockBuilder(Slim::class)
$di['app'] = $this->getMockBuilder(Slim::class)
->setMethods(['redirect', 'render', 'urlFor'])
->setConstructorArgs([$di['config']])
->getMock();

$di['app'] = $di->share(static function ($c) use ($mock) {
return $mock;
});
$this->import = $di['importController'];
$this->runs = $di['runController'];
$this->app = $di['app'];
Expand Down
9 changes: 3 additions & 6 deletions tests/Controller/WatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ public function setUp()
'SCRIPT_NAME' => 'index.php',
'PATH_INFO' => '/watch'
]);
$di = Xhgui_ServiceContainer::instance();
unset($di['app']);

$mock = $this->getMockBuilder(Slim::class)
$di = Xhgui_ServiceContainer::instance();
$di['app'] = $this->getMockBuilder(Slim::class)
->setMethods(['redirect', 'render', 'urlFor'])
->setConstructorArgs([$di['config']])
->getMock();
$di['app'] = $di->share(static function ($c) use ($mock) {
return $mock;
});

$this->watches = $di['watchController'];
$this->app = $di['app'];
$this->searcher = $di['searcher'];
Expand Down

0 comments on commit 0b80259

Please sign in to comment.