|
4 | 4 |
|
5 | 5 | namespace Keboola\NotificationClient\Tests\Requests\PostEvent; |
6 | 6 |
|
| 7 | +use DateTimeImmutable; |
7 | 8 | use Keboola\NotificationClient\Requests\PostEvent\JobData; |
8 | 9 | use PHPUnit\Framework\TestCase; |
9 | 10 |
|
10 | 11 | class JobDataTest extends TestCase |
11 | 12 | { |
12 | | - public function testJsonSerialize(): void |
| 13 | + /** |
| 14 | + * @dataProvider jobDataProvider |
| 15 | + */ |
| 16 | + public function testJsonSerialize(JobData $jobData, array $expected): void |
13 | 17 | { |
14 | | - $jobData = new JobData( |
15 | | - '23456', |
16 | | - 'http://someUrl', |
17 | | - '2020-01-01', |
18 | | - '2020-02-02', |
19 | | - 'keboola.orchestrator', |
20 | | - 'Orchestrator', |
21 | | - 'my-configuration', |
22 | | - 'My configuration' |
23 | | - ); |
24 | | - self::assertSame( |
| 18 | + self::assertSame($expected, $jobData->jsonSerialize()); |
| 19 | + } |
| 20 | + |
| 21 | + public function jobDataProvider() |
| 22 | + { |
| 23 | + yield 'full data' => [ |
| 24 | + new JobData( |
| 25 | + '23456', |
| 26 | + 'http://someUrl', |
| 27 | + new DateTimeImmutable('2020-01-01T11:11:00+00:00'), |
| 28 | + new DateTimeImmutable('2020-01-01T12:11:00+00:00'), |
| 29 | + 'keboola.orchestrator', |
| 30 | + 'Orchestrator', |
| 31 | + 'my-configuration', |
| 32 | + 'My configuration' |
| 33 | + ), |
25 | 34 | [ |
26 | 35 | 'id' => '23456', |
27 | 36 | 'url' => 'http://someUrl', |
28 | | - 'startTime' => '2020-01-01', |
29 | | - 'endTime' => '2020-02-02', |
30 | 37 | 'component' => [ |
31 | 38 | 'id' => 'keboola.orchestrator', |
32 | 39 | 'name' => 'Orchestrator', |
33 | 40 | ], |
| 41 | + 'tasks' => [], |
| 42 | + 'startTime' => '2020-01-01T11:11:00+00:00', |
| 43 | + 'endTime' => '2020-01-01T12:11:00+00:00', |
34 | 44 | 'configuration' => [ |
35 | 45 | 'id' => 'my-configuration', |
36 | 46 | 'name' => 'My configuration', |
37 | 47 | ], |
| 48 | + ] |
| 49 | + ]; |
| 50 | + yield 'null configuration id' => [ |
| 51 | + new JobData( |
| 52 | + '23456', |
| 53 | + 'http://someUrl', |
| 54 | + new DateTimeImmutable('2020-01-01T11:11:00+00:00'), |
| 55 | + new DateTimeImmutable('2020-01-01T12:11:00+00:00'), |
| 56 | + 'keboola.orchestrator', |
| 57 | + 'Orchestrator', |
| 58 | + null, |
| 59 | + 'My configuration' |
| 60 | + ), |
| 61 | + [ |
| 62 | + 'id' => '23456', |
| 63 | + 'url' => 'http://someUrl', |
| 64 | + 'component' => [ |
| 65 | + 'id' => 'keboola.orchestrator', |
| 66 | + 'name' => 'Orchestrator', |
| 67 | + ], |
38 | 68 | 'tasks' => [], |
| 69 | + 'startTime' => '2020-01-01T11:11:00+00:00', |
| 70 | + 'endTime' => '2020-01-01T12:11:00+00:00', |
39 | 71 | ], |
40 | | - $jobData->jsonSerialize() |
41 | | - ); |
42 | | - } |
43 | | - |
44 | | - public function testJsonSerializeEmptyConfigurationId(): void |
45 | | - { |
46 | | - $jobData = new JobData( |
47 | | - '23456', |
48 | | - 'http://someUrl', |
49 | | - '2020-01-01', |
50 | | - '2020-02-02', |
51 | | - 'keboola.orchestrator', |
52 | | - 'Orchestrator', |
53 | | - null, |
54 | | - 'My configuration' |
55 | | - ); |
56 | | - self::assertSame( |
| 72 | + ]; |
| 73 | + yield 'null configuration name' => [ |
| 74 | + new JobData( |
| 75 | + '23456', |
| 76 | + 'http://someUrl', |
| 77 | + new DateTimeImmutable('2020-01-01T12:11:00+00:00'), |
| 78 | + new DateTimeImmutable('2020-01-01T13:11:00+00:00'), |
| 79 | + 'keboola.orchestrator', |
| 80 | + 'Orchestrator', |
| 81 | + '1234', |
| 82 | + null |
| 83 | + ), |
57 | 84 | [ |
58 | 85 | 'id' => '23456', |
59 | 86 | 'url' => 'http://someUrl', |
60 | | - 'startTime' => '2020-01-01', |
61 | | - 'endTime' => '2020-02-02', |
62 | 87 | 'component' => [ |
63 | 88 | 'id' => 'keboola.orchestrator', |
64 | 89 | 'name' => 'Orchestrator', |
65 | 90 | ], |
66 | 91 | 'tasks' => [], |
| 92 | + 'startTime' => '2020-01-01T12:11:00+00:00', |
| 93 | + 'endTime' => '2020-01-01T13:11:00+00:00', |
67 | 94 | ], |
68 | | - $jobData->jsonSerialize() |
69 | | - ); |
70 | | - } |
71 | | - |
72 | | - public function testJsonSerializeEmptyConfigurationName(): void |
73 | | - { |
74 | | - $jobData = new JobData( |
75 | | - '23456', |
76 | | - 'http://someUrl', |
77 | | - '2020-01-01', |
78 | | - '2020-02-02', |
79 | | - 'keboola.orchestrator', |
80 | | - 'Orchestrator', |
81 | | - '1234', |
82 | | - null |
83 | | - ); |
84 | | - self::assertSame( |
| 95 | + ]; |
| 96 | + yield 'empty start and end time' => [ |
| 97 | + new JobData( |
| 98 | + '23456', |
| 99 | + 'http://someUrl', |
| 100 | + null, |
| 101 | + null, |
| 102 | + 'keboola.orchestrator', |
| 103 | + 'Orchestrator', |
| 104 | + '1234', |
| 105 | + null |
| 106 | + ), |
85 | 107 | [ |
86 | 108 | 'id' => '23456', |
87 | 109 | 'url' => 'http://someUrl', |
88 | | - 'startTime' => '2020-01-01', |
89 | | - 'endTime' => '2020-02-02', |
90 | 110 | 'component' => [ |
91 | 111 | 'id' => 'keboola.orchestrator', |
92 | 112 | 'name' => 'Orchestrator', |
93 | 113 | ], |
94 | 114 | 'tasks' => [], |
95 | 115 | ], |
96 | | - $jobData->jsonSerialize() |
97 | | - ); |
| 116 | + ]; |
98 | 117 | } |
99 | 118 | } |
0 commit comments