Refactor tests to use $this->getApplication().

Move LoginTest specific use case into LoginTest class
This commit is contained in:
Benoît Burnichon
2016-05-19 14:39:05 +02:00
parent f0e2ff2bd1
commit c14e48437d
2 changed files with 23 additions and 20 deletions

View File

@@ -1961,4 +1961,19 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['app']['registration.manager'] = $managerMock;
self::$DI['app']['registration.manager']->expects($this->any())->method('isRegistrationEnabled')->will($this->returnValue(false));
}
private function mockNotificationsDeliverer(array &$expectedMails)
{
$app = $this->getApplication();
$app['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()
->getMock();
$app['notification.deliverer']->expects($this->any())
->method('deliver')
->will($this->returnCallback(function ($email, $receipt) use (&$expectedMails) {
$this->assertTrue(isset($expectedMails[get_class($email)]));
$expectedMails[get_class($email)]++;
}));
}
}

View File

@@ -686,38 +686,26 @@ abstract class PhraseanetTestCase extends WebTestCase
protected function mockNotificationDeliverer($expectedMail, $qty = 1, $receipt = null)
{
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
$app = $this->getApplication();
$app['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()
->getMock();
self::$DI['app']['notification.deliverer']->expects($this->exactly($qty))
$app['notification.deliverer']->expects($this->exactly($qty))
->method('deliver')
->with($this->isInstanceOf($expectedMail), $this->equalTo($receipt));
}
protected function mockNotificationsDeliverer(array &$expectedMails)
{
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer')
->disableOriginalConstructor()
->getMock();
self::$DI['app']['notification.deliverer']->expects($this->any())
->method('deliver')
->will($this->returnCallback(function ($email, $receipt) use (&$expectedMails) {
$this->assertTrue(isset($expectedMails[get_class($email)]));
$expectedMails[get_class($email)]++;
}));
}
protected function mockUserNotificationSettings($notificationName, $returnValue = true)
{
if (false === self::$DI['app']['settings'] instanceof \PHPUnit_Framework_MockObject_MockObject) {
self::$DI['app']['settings'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\DisplaySettingService')
$app = $this->getApplication();
if (false === $app['settings'] instanceof \PHPUnit_Framework_MockObject_MockObject) {
$app['settings'] = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\DisplaySettingService')
->disableOriginalConstructor()
->getMock();
}
self::$DI['app']['settings']
$app['settings']
->expects($this->any())
->method('getUserNotificationSetting')
->with(
@@ -726,7 +714,7 @@ abstract class PhraseanetTestCase extends WebTestCase
)
->will($this->returnValue($returnValue));
self::$DI['app']['setting'] = 'toto';
$app['setting'] = 'toto';
}
public function createGeneratorMock()