Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.3][Tests] Silex2 deprecations #6564

Merged
merged 4 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Provider/DatabaseSchemaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Bolt\Helpers\Deprecated;
use Bolt\Storage\Database\Schema\Builder;
use Bolt\Storage\Database\Schema\Comparison;
use Bolt\Storage\Database\Schema\LazySchemaManager;
use Bolt\Storage\Database\Schema\Manager;
use Bolt\Storage\Database\Schema\Table;
Expand Down Expand Up @@ -209,9 +210,9 @@ function ($app) {
$app['schema.comparator.factory'] = $app->protect(
function () use ($app) {
$platforms = [
'mysql' => '\\Bolt\\Storage\\Database\\Schema\\Comparison\\MySql',
'postgresql' => '\\Bolt\\Storage\\Database\\Schema\\Comparison\\PostgreSql',
'sqlite' => '\\Bolt\\Storage\\Database\\Schema\\Comparison\\Sqlite',
'mysql' => Comparison\MySql::class,
'postgresql' => Comparison\PostgreSql::class,
'sqlite' => Comparison\Sqlite::class,
];
$platformName = $app['db']->getDatabasePlatform()->getName();

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/unit/AccessControl/AccessCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function testIsValidSessionGenerateToken()
->method('info')
->with($this->equalTo('You have been logged out.'))
;
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$userEntity = new Entity\Users();
$tokenEntity = new Entity\Authtoken();
Expand Down
26 changes: 13 additions & 13 deletions tests/phpunit/unit/AccessControl/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testLoginNoCredentials()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Login function called with empty username/password combination, or no authentication token.'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$login = new Login($app);
$login->login(null, null, new AccessControlEvent(new Request()));
Expand All @@ -54,7 +54,7 @@ public function testLoginInvalidUsername()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Username or password not correct. Please check your input.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$login = new Login($app);

Expand All @@ -72,13 +72,13 @@ public function testLoginDisabledUsername()
$logger->expects($this->atLeastOnce())
->method('alert')
->with($this->equalTo("Attempt to login with disabled account by 'admin'"));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$logger = $this->getMockFlashLogger();
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Your account is disabled. Sorry about that.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

/** @var UsersRepository $repo */
$repo = $app['storage']->getRepository(Entity\Users::class);
Expand All @@ -103,7 +103,7 @@ public function testLoginDisabledUsernameWithCorrectPassword()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Your account is disabled. Sorry about that.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$login = new Login($app);

Expand All @@ -120,13 +120,13 @@ public function testLoginWrongPassword()
$logger->expects($this->atLeastOnce())
->method('info')
->with($this->equalTo("Failed login attempt for 'Admin'."));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$logger = $this->getMockFlashLogger();
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Username or password not correct. Please check your input.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$app['request_stack']->push(new Request());

Expand All @@ -148,7 +148,7 @@ public function testLoginSuccessPassword()
$logger->expects($this->at(1))
->method('debug')
->with($this->matchesRegularExpression('#Saving new login token#'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$request = Request::createFromGlobals();
$request->server->set('HTTP_USER_AGENT', 'Bolt PHPUnit tests');
Expand All @@ -169,7 +169,7 @@ public function testLoginInvalidToken()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Invalid login parameters.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$request = Request::createFromGlobals();
$request->server->set('REMOTE_ADDR', '1.2.3.4');
Expand All @@ -191,7 +191,7 @@ public function testLoginExpiredToken()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Invalid login parameters.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$repo = $app['storage']->getRepository(Entity\Authtoken::class);
$entityAuthtoken = new Entity\Authtoken();
Expand Down Expand Up @@ -228,7 +228,7 @@ public function testLoginUnsaltedToken()
$logger->expects($this->atLeastOnce())
->method('debug')
->with($this->matchesRegularExpression('#Generating authentication cookie#'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$repo = $app['storage']->getRepository(Entity\Authtoken::class);
$entityAuthtoken = new Entity\Authtoken();
Expand Down Expand Up @@ -265,7 +265,7 @@ public function testLoginSuccessToken()
$logger->expects($this->at(1))
->method('debug')
->with($this->matchesRegularExpression('#Saving new login token#'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$logger = $this->getMockFlashLogger();
$logger->expects($this->at(0))
Expand All @@ -274,7 +274,7 @@ public function testLoginSuccessToken()
$logger->expects($this->at(1))
->method('success')
->with($this->equalTo("You've been logged on successfully."));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$userName = 'admin';
$salt = 'vinagre';
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/unit/AccessControl/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testSetRandomPassword()
$logger->expects($this->atLeastOnce())
->method('info')
->with($this->equalTo("Password for user 'admin' was reset via Nut."));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$password = new Password($app);
$newPass = $password->setRandomPassword('admin');
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testResetPasswordConfirmExpiredToken()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Somebody tried to reset a password with an invalid token.'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$shadowToken = $app['randomgenerator']->generateString(32);
$shadowTokenHash = md5($shadowToken . '-' . str_replace('.', '-', '8.8.8.8'));
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testResetPasswordConfirmInvalidIp()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Somebody tried to reset a password with an invalid token.'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$shadowToken = $app['randomgenerator']->generateString(32);
$shadowTokenHash = md5($shadowToken . '-' . str_replace('.', '-', '8.8.8.8'));
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testResetPasswordConfirmInvalidToken()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Somebody tried to reset a password with an invalid token.'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$shadowToken = $app['randomgenerator']->generateString(32);

Expand All @@ -175,7 +175,7 @@ public function testResetPasswordRequestInvalidUser()
$logger->expects($this->atLeastOnce())
->method('info')
->with($this->equalTo("A password reset link has been sent to 'sneakykoala'."));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$event = new AccessControlEvent(Request::createFromGlobals());
$password = new Password($app);
Expand All @@ -194,13 +194,13 @@ public function testResetPasswordRequestNoMailOptions()
$logger->expects($this->atLeastOnce())
->method('danger')
->with($this->equalTo("The email configuration setting 'mailoptions' hasn't been set. Bolt may be unable to send password reset."));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$mailer = $this->getMockSwiftMailer();
$mailer->expects($this->atLeastOnce())
->method('send')
->will($this->returnValue(true));
$app['mailer'] = $mailer;
$this->setService('mailer', $mailer);

$event = new AccessControlEvent(Request::createFromGlobals());
$password = new Password($app);
Expand All @@ -219,13 +219,13 @@ public function testResetPasswordRequestSendSuccess()
$logger->expects($this->never())
->method('error')
->with($this->equalTo("A password reset link has been sent to 'sneakykoala'."));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$mailer = $this->getMockSwiftMailer();
$mailer->expects($this->atLeastOnce())
->method('send')
->will($this->returnValue(true));
$app['mailer'] = $mailer;
$this->setService('mailer', $mailer);

$event = new AccessControlEvent(Request::createFromGlobals());
$password = new Password($app);
Expand All @@ -244,19 +244,19 @@ public function testResetPasswordRequestSendFailure()
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo('Failed to send password request. Please check the email settings.'));
$app['logger.flash'] = $logger;
$this->setService('logger.flash', $logger);

$logger = $this->getMockMonolog();
$logger->expects($this->atLeastOnce())
->method('error')
->with($this->equalTo("Failed to send password request sent to 'Admin'."));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);

$mailer = $this->getMockSwiftMailer();
$mailer->expects($this->atLeastOnce())
->method('send')
->will($this->returnValue(false));
$app['mailer'] = $mailer;
$this->setService('mailer', $mailer);

$event = new AccessControlEvent(Request::createFromGlobals());
$password = new Password($app);
Expand Down
7 changes: 0 additions & 7 deletions tests/phpunit/unit/Asset/AssetsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,6 @@ function ($fileName) {
public function testBadExtensionSnippets()
{
$app = $this->getApp();
$app['asset.queue.snippet'] = new \Bolt\Asset\Snippet\Queue(
$app['asset.injector'],
$app['cache'],
$app['config'],
$app['resources'],
$app['request_stack']
);
new Mock\BadExtensionSnippets($app);
$response = new Response($this->template);

Expand Down
14 changes: 8 additions & 6 deletions tests/phpunit/unit/BoltUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function allowLogin($app)
$users->expects($this->any())
->method('isEnabled')
->will($this->returnValue(true));
$app['users'] = $users;
$this->setService('users', $users);

$permissions = $this->getMockPermissions(['isAllowed']);
$permissions->expects($this->any())
Expand All @@ -191,7 +191,7 @@ protected function allowLogin($app)
->method('isValidSession')
->will($this->returnValue(true));

$app['access_control'] = $auth;
$this->setService('access_control', $auth);
}

protected function removeCSRF($app)
Expand All @@ -206,16 +206,15 @@ protected function removeCSRF($app)
->method('getToken')
->will($this->returnValue('xyz'));

$app['form.csrf_provider'] = $csrf;
$this->setService('form.csrf_provider', $csrf);
}

protected function addSomeContent()
{
$app = $this->getApp();
$this->addDefaultUser($app);
$app['config']->set('taxonomy/categories/options', ['news']);
$prefillMock = new LoripsumMock();
$app['prefill'] = $prefillMock;
$this->setService('prefill', new LoripsumMock());

$storage = new Storage($app);
$storage->prefill(['showcases', 'pages']);
Expand All @@ -227,6 +226,9 @@ protected function addSomeContent()
*/
protected function setService($key, $value)
{
// In Pimple v3+ you can't re-set a container value,
// this just keeps us working forward with tests.
$this->getApp()->offsetUnset($key);
$this->getApp()->offsetSet($key, $value);
}

Expand Down Expand Up @@ -394,7 +396,7 @@ protected function getMockSwiftMailer($methods = ['send'])
{
return $this->getMockBuilder(Swift_Mailer::class)
->setMethods($methods)
->setConstructorArgs([$this->app['swiftmailer.transport']])
->disableOriginalConstructor()
->getMock()
;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/unit/Controller/Async/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public function testDashboardNewsWithInvalidRequest()
$requestInterface = $this->createMock(RequestInterface::class);
$testGuzzle->expects($this->at(0))->method('get')->will($this->throwException(new RequestException('Mock Fail', $requestInterface)));

$app['guzzle.client'] = $testGuzzle;
$this->setService('guzzle.client', $testGuzzle);

$logger = $this->getMockLoggerManager();
$logger->expects($this->at(1))
->method('error')
->with($this->stringContains('Error occurred'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);
$this->controller()->dashboardNews($this->getRequest());
}

Expand All @@ -91,13 +91,13 @@ public function testDashboardNewsWithInvalidJson()
$testGuzzle->expects($this->any())
->method('get')
->will($this->returnValue($testRequest));
$app['guzzle.client'] = $testGuzzle;
$this->setService('guzzle.client', $testGuzzle);

$logger = $this->getMockLoggerManager();
$logger->expects($this->at(1))
->method('error')
->with($this->stringContains('Invalid JSON'));
$app['logger.system'] = $logger;
$this->setService('logger.system', $logger);
$this->controller()->dashboardNews($this->getRequest());
}

Expand All @@ -117,7 +117,7 @@ public function testDashboardNewsWithVariable()
$testGuzzle->expects($this->any())
->method('get')
->will($this->returnValue($requestInterface));
$app['guzzle.client'] = $testGuzzle;
$this->setService('guzzle.client', $testGuzzle);

$response = $this->controller()->dashboardNews($this->getRequest());

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/unit/Controller/Backend/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testClearCache()
/** @var Application $app */
$app = $this->getApp();
$flashes = $this->createMock(FlashLogger::class);
$app['logger.flash'] = $flashes;
$this->setService('logger.flash', $flashes);

$flashes->expects($this->once())
->method('error');
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/unit/Controller/FrontendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testCanonicalUrlForNumericRecord()
{
/** @var \Silex\Application $app */
$app = $this->getApp();
$app['twig.runtime.bolt_html'] = $this->getHtmlRuntime();
$this->setService('twig.runtime.bolt_html', $this->getHtmlRuntime());

$this->setRequest(Request::create('/pages/5'));
$app['request_context']->fromRequest($this->getRequest());
Expand All @@ -175,7 +175,7 @@ public function testCanonicalUrlForNumericRecord()
$content1['slug'] = 'foo';

$storage = $this->getMockStorage(['getContent']);
$app['storage'] = $storage;
$this->setService('storage', $storage);

$storage->expects($this->at(0))
->method('getContent')
Expand All @@ -199,7 +199,7 @@ public function testNumericRecord()
{
/** @var \Silex\Application $app */
$app = $this->getApp();
$app['twig.runtime.bolt_html'] = $this->getHtmlRuntime();
$this->setService('twig.runtime.bolt_html', $this->getHtmlRuntime());

$this->setRequest(Request::create('/pages/', 'GET', ['id' => 5]));
$contentType = $this->getService('storage')->getContentType('pages');
Expand Down
Loading