From c14e48437dcf340ba628819d31987ae97e2a907c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Thu, 19 May 2016 14:39:05 +0200 Subject: [PATCH] Refactor tests to use $this->getApplication(). Move LoginTest specific use case into LoginTest class --- .../Phrasea/Controller/Root/LoginTest.php | 15 ++++++++++ tests/classes/PhraseanetTestCase.php | 28 ++++++------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php index 0fed1aff41..b92e8d68f2 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php @@ -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)]++; + })); + } } diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index caf836fac2..bee24b1905 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -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()