Skip to content

Commit

Permalink
Ensure mock entities have predictable timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Jun 12, 2024
1 parent fe33ac4 commit fa02e9d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/src/Traits/MockCropPlanEntitiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function createMockPlanEntities() {

// Create a season term.
$this->seasonTerm = Term::create([
'name' => date('Y'),
'name' => '2024',
'vid' => 'season',
]);
$this->seasonTerm->save();
Expand Down Expand Up @@ -112,14 +112,15 @@ public function createMockPlanEntities() {
]);
$this->landAsset->save();

// Start the plan on May 1, 2024.
$timestamp = strtotime('May 1, 2024');

// Create seeding logs for each plant asset.
$timestamp = strtotime('-6 month');
foreach ($this->plantAssets as $plant_asset) {
$timestamp = strtotime('+1 month', $timestamp);
foreach ($this->plantAssets as $i => $plant_asset) {
$log = Log::create([
'name' => 'Seed ' . $plant_asset->label() . ' in ' . $this->landAsset->label(),
'type' => 'seeding',
'timestamp' => $timestamp,
'timestamp' => strtotime('+' . ($i + 1) . ' month', $timestamp),
'asset' => [
['target_id' => $plant_asset->id()],
],
Expand All @@ -134,13 +135,11 @@ public function createMockPlanEntities() {
}

// Create transplanting logs for each plant asset.
$timestamp = strtotime('-5 month');
foreach ($this->plantAssets as $plant_asset) {
$timestamp = strtotime('+1 month', $timestamp);
foreach ($this->plantAssets as $i => $plant_asset) {
$log = Log::create([
'name' => 'Transplant ' . $plant_asset->label() . ' in ' . $this->landAsset->label(),
'type' => 'transplanting',
'timestamp' => $timestamp,
'timestamp' => strtotime('+' . ($i + 2) . ' month', $timestamp),
'asset' => [
['target_id' => $plant_asset->id()],
],
Expand Down

0 comments on commit fa02e9d

Please sign in to comment.