Skip to content

Commit 63aaebf

Browse files
committed
Fix datetime equal tests
1 parent 2b33202 commit 63aaebf

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

pkg/job-queue/Tests/CalculateRootJobStatusServiceTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function testShouldCalculateRootJobStatusAndSetStoppedAtTimeIfGotStopStat
102102
$case->calculate($childJob);
103103

104104
$this->assertEquals($stopStatus, $rootJob->getStatus());
105-
$this->assertEquals(new \DateTime(), $rootJob->getStoppedAt(), '', 1);
105+
$this->assertEquals(
106+
(new \DateTime())->getTimestamp(),
107+
$rootJob->getStoppedAt()->getTimestamp()
108+
);
106109
}
107110

108111
public function testShouldSetStoppedAtOnlyIfWasNotSet()
@@ -129,7 +132,10 @@ public function testShouldSetStoppedAtOnlyIfWasNotSet()
129132
$case = new CalculateRootJobStatusService($em);
130133
$case->calculate($childJob);
131134

132-
$this->assertEquals(new \DateTime('2012-12-12 12:12:12'), $rootJob->getStoppedAt());
135+
$this->assertEquals(
136+
(new \DateTime('2012-12-12 12:12:12'))->getTimestamp(),
137+
$rootJob->getStoppedAt()->getTimestamp()
138+
);
133139
}
134140

135141
public function testShouldThrowIfInvalidStatus()

pkg/job-queue/Tests/JobProcessorTest.php

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ public function testShouldCreateRootJobAndReturnIt()
6060

6161
$this->assertSame($job, $result);
6262
$this->assertEquals(Job::STATUS_NEW, $job->getStatus());
63-
$this->assertEquals(new \DateTime(), $job->getCreatedAt(), '', 1);
64-
$this->assertEquals(new \DateTime(), $job->getStartedAt(), '', 1);
63+
$this->assertEquals(
64+
(new \DateTime())->getTimestamp(),
65+
$job->getCreatedAt()->getTimestamp()
66+
);
67+
$this->assertEquals(
68+
(new \DateTime())->getTimestamp(),
69+
$job->getStartedAt()->getTimestamp()
70+
);
6571
$this->assertNull($job->getStoppedAt());
6672
$this->assertEquals('job-name', $job->getName());
6773
$this->assertEquals('owner-id', $job->getOwnerId());
@@ -183,7 +189,10 @@ public function testCreateChildJobShouldCreateAndSaveJobAndPublishRecalculateRoo
183189

184190
$this->assertSame($job, $result);
185191
$this->assertEquals(Job::STATUS_NEW, $job->getStatus());
186-
$this->assertEquals(new \DateTime(), $job->getCreatedAt(), '', 1);
192+
$this->assertEquals(
193+
(new \DateTime())->getTimestamp(),
194+
$job->getCreatedAt()->getTimestamp()
195+
);
187196
$this->assertNull($job->getStartedAt());
188197
$this->assertNull($job->getStoppedAt());
189198
$this->assertEquals('job-name', $job->getName());
@@ -256,7 +265,10 @@ public function testStartJobShouldUpdateJobWithRunningStatusAndStartAtTime()
256265
$processor->startChildJob($job);
257266

258267
$this->assertEquals(Job::STATUS_RUNNING, $job->getStatus());
259-
$this->assertEquals(new \DateTime(), $job->getStartedAt(), '', 1);
268+
$this->assertEquals(
269+
(new \DateTime())->getTimestamp(),
270+
$job->getStartedAt()->getTimestamp()
271+
);
260272
}
261273

262274
public function testSuccessChildJobShouldThrowIfRootJob()
@@ -325,7 +337,10 @@ public function testSuccessJobShouldUpdateJobWithSuccessStatusAndStopAtTime()
325337
$processor->successChildJob($job);
326338

327339
$this->assertEquals(Job::STATUS_SUCCESS, $job->getStatus());
328-
$this->assertEquals(new \DateTime(), $job->getStoppedAt(), '', 1);
340+
$this->assertEquals(
341+
(new \DateTime())->getTimestamp(),
342+
$job->getStoppedAt()->getTimestamp()
343+
);
329344
}
330345

331346
public function testFailChildJobShouldThrowIfRootJob()
@@ -394,7 +409,10 @@ public function testFailJobShouldUpdateJobWithFailStatusAndStopAtTime()
394409
$processor->failChildJob($job);
395410

396411
$this->assertEquals(Job::STATUS_FAILED, $job->getStatus());
397-
$this->assertEquals(new \DateTime(), $job->getStoppedAt(), '', 1);
412+
$this->assertEquals(
413+
(new \DateTime())->getTimestamp(),
414+
$job->getStoppedAt()->getTimestamp()
415+
);
398416
}
399417

400418
public function testCancelChildJobShouldThrowIfRootJob()
@@ -463,8 +481,14 @@ public function testCancelJobShouldUpdateJobWithCancelStatusAndStoppedAtTimeAndS
463481
$processor->cancelChildJob($job);
464482

465483
$this->assertEquals(Job::STATUS_CANCELLED, $job->getStatus());
466-
$this->assertEquals(new \DateTime(), $job->getStoppedAt(), '', 1);
467-
$this->assertEquals(new \DateTime(), $job->getStartedAt(), '', 1);
484+
$this->assertEquals(
485+
(new \DateTime())->getTimestamp(),
486+
$job->getStoppedAt()->getTimestamp()
487+
);
488+
$this->assertEquals(
489+
(new \DateTime())->getTimestamp(),
490+
$job->getStartedAt()->getTimestamp()
491+
);
468492
}
469493

470494
public function testInterruptRootJobShouldThrowIfNotRootJob()
@@ -536,7 +560,10 @@ public function testInterruptRootJobShouldUpdateJobAndSetInterruptedTrueAndStopp
536560
$processor->interruptRootJob($rootJob, true);
537561

538562
$this->assertTrue($rootJob->isInterrupted());
539-
$this->assertEquals(new \DateTime(), $rootJob->getStoppedAt(), '', 1);
563+
$this->assertEquals(
564+
(new \DateTime())->getTimestamp(),
565+
$rootJob->getStoppedAt()->getTimestamp()
566+
);
540567
}
541568

542569
/**

0 commit comments

Comments
 (0)