Rewrite mocks to nicer variants

[MAILPOET-2539]
This commit is contained in:
Jan Jakeš
2019-12-17 14:07:44 +01:00
committed by Jack Kitterhing
parent 04f266518b
commit a5ec593568

View File

@@ -71,17 +71,15 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123, 'token' => 123,
]; ];
$run = 0; $cron_worker_runner_mock = $this->createMock(CronWorkerRunner::class);
$cron_worker_runner_mock = $this->make(CronWorkerRunner::class, [ $cron_worker_runner_mock
'run' => function () use (&$run) { ->expects($this->at(0))
$run++; ->method('run')
if ($run === 1) { ->willThrowException(new \Exception('Message'));
throw new \Exception('Message'); $cron_worker_runner_mock
} elseif ($run === 2) { ->expects($this->at(1))
throw new \Exception(); ->method('run')
} ->willThrowException(new \Exception());
},
]);
$daemon = new Daemon($this->cron_helper, $cron_worker_runner_mock, $this->createWorkersFactoryMock()); $daemon = new Daemon($this->cron_helper, $cron_worker_runner_mock, $this->createWorkersFactoryMock());
$daemon_http_runner = $this->make(DaemonHttpRunner::class, [ $daemon_http_runner = $this->make(DaemonHttpRunner::class, [
@@ -218,17 +216,17 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
} }
function testItUpdatesTimestampsDuringExecution() { function testItUpdatesTimestampsDuringExecution() {
$run = 0; $cron_worker_runner_mock = $this->createMock(CronWorkerRunner::class);
$cron_worker_runner_mock = $this->make(CronWorkerRunner::class, [ $cron_worker_runner_mock
'run' => function () use (&$run) { ->expects($this->at(0))
$run++; ->method('run')
if ($run === 1) { ->willReturnCallback(function () {
sleep(2); sleep(2);
} elseif ($run === 2) { });
throw new \Exception(); $cron_worker_runner_mock
} ->expects($this->at(1))
}, ->method('run')
]); ->willThrowException(new \Exception());
$daemon = new Daemon($this->cron_helper, $cron_worker_runner_mock, $this->createWorkersFactoryMock()); $daemon = new Daemon($this->cron_helper, $cron_worker_runner_mock, $this->createWorkersFactoryMock());
$daemon_http_runner = $this->make(DaemonHttpRunner::class, [ $daemon_http_runner = $this->make(DaemonHttpRunner::class, [