-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramSaverTest.php
More file actions
115 lines (102 loc) · 3.57 KB
/
ProgramSaverTest.php
File metadata and controls
115 lines (102 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types=1);
namespace BOA\Programs\Tests;
use BOA\Programs\ProgramSaver;
use PHPUnit\Framework\TestCase;
/**
* @author shimomo
*/
final class ProgramSaverTest extends TestCase
{
/**
* @psalm-var non-empty-string
*
* @var string
*/
private string $tempDir;
/**
* @psalm-return void
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->tempDir = sys_get_temp_dir() . '/program_saver_test_' . bin2hex(random_bytes(8));
if (!mkdir($this->tempDir, 0755, true) && !is_dir($this->tempDir)) {
$this->fail('Failed to create temp dir: ' . $this->tempDir);
}
}
/**
* @psalm-return void
*
* @return void
*/
protected function tearDown(): void
{
if (is_dir($this->tempDir)) {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->tempDir, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
$file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath());
}
rmdir($this->tempDir);
}
}
/**
* @psalm-return void
*
* @return void
*/
public function testSave(): void
{
$saver = new ProgramSaver();
$path = $this->tempDir . '/programs.json';
$programs = [
[
'race_date' => '2025-07-15',
'race_stadium_number' => 1,
'race_number' => 1,
'race_closed_at' => '2025-07-15 15:17:00',
'race_grade_number' => 5,
'race_title' => 'にっぽん未来プロジェクト競走in桐生',
'race_subtitle' => '予選',
'race_distance' => 1800,
'boats' => [
[
'racer_boat_number' => 1,
'racer_name' => '松本 浩貴',
'racer_number' => 3860,
'racer_class_number' => 3,
'racer_branch_number' => 11,
'racer_birthplace_number' => 11,
'racer_age' => 52,
'racer_weight' => 52,
'racer_flying_count' => 0,
'racer_late_count' => 0,
'racer_average_start_timing' => 0.19,
'racer_national_top_1_percent' => 4.09,
'racer_national_top_2_percent' => 18.48,
'racer_national_top_3_percent' => 39.13,
'racer_local_top_1_percent' => 4.85,
'racer_local_top_2_percent' => 33.33,
'racer_local_top_3_percent' => 40.74,
'racer_assigned_motor_number' => 24,
'racer_assigned_motor_top_2_percent' => 28,
'racer_assigned_motor_top_3_percent' => 42.67,
'racer_assigned_boat_number' => 23,
'racer_assigned_boat_top_2_percent' => 30.47,
'racer_assigned_boat_top_3_percent' => 51.56,
],
],
],
];
$saver->save($programs, $path);
$this->assertFileExists($path);
$content = json_decode(file_get_contents($path), true);
$this->assertArrayHasKey('programs', $content);
$this->assertSame($programs, $content['programs']);
}
}