Skip to content

Commit a995824

Browse files
committed
Use self for PHPUnit assertions
1 parent 9eae213 commit a995824

File tree

8 files changed

+104
-104
lines changed

8 files changed

+104
-104
lines changed

tests/Integration/E2ETest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ function it_can_generate_valid_request(string $filename)
5757
try {
5858
(new SchemaValidator())->validate($response, $schema);
5959
} catch (Throwable $e) {
60-
$this->fail($e->getMessage());
60+
self::fail($e->getMessage());
6161
}
6262
}
6363
}
6464
}
6565

66-
$this->assertTrue(true);
66+
self::assertTrue(true);
6767
}
6868

6969
/**
@@ -98,14 +98,14 @@ function it_can_generate_valid_response(string $filename)
9898
try {
9999
(new SchemaValidator())->validate($response, $mediaType->schema);
100100
} catch (Throwable $e) {
101-
$this->fail($e->getMessage());
101+
self::fail($e->getMessage());
102102
}
103103
}
104104
}
105105
}
106106
}
107107

108-
$this->assertTrue(true);
108+
self::assertTrue(true);
109109
}
110110

111111
/**
@@ -119,7 +119,7 @@ function it_can_generate_valid_component(string $filename)
119119

120120
$schema = (new YamlFactory($file))->createSchema();
121121

122-
$this->assertNotNull($schema->components);
122+
self::assertNotNull($schema->components);
123123

124124
/**
125125
* @var string $schemaName
@@ -131,11 +131,11 @@ function it_can_generate_valid_component(string $filename)
131131
try {
132132
(new SchemaValidator())->validate($mockSchema, $schema);
133133
} catch (Throwable $e) {
134-
$this->fail($e->getMessage());
134+
self::fail($e->getMessage());
135135
}
136136
}
137137

138-
$this->assertTrue(true);
138+
self::assertTrue(true);
139139
}
140140

141141
/**

tests/Integration/OpenAPIFakerTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function it_can_create_faker_from_json()
7676

7777
$faker = OpenAPIFaker::createFromJson($specJson);
7878

79-
$this->assertInstanceOf(OpenAPIFaker::class, $faker);
79+
self::assertInstanceOf(OpenAPIFaker::class, $faker);
8080
}
8181

8282
/**
@@ -131,7 +131,7 @@ function it_can_create_faker_from_yaml()
131131

132132
$faker = OpenAPIFaker::createFromYaml($specYaml);
133133

134-
$this->assertInstanceOf(OpenAPIFaker::class, $faker);
134+
self::assertInstanceOf(OpenAPIFaker::class, $faker);
135135
}
136136

137137
/**
@@ -185,7 +185,7 @@ function it_throws_exception_if_request_cannot_be_found(string $path, string $me
185185
$ref: '#/components/schemas/Todo'
186186
YAML;
187187

188-
$this->expectException(NoRequest::class);
188+
self::expectException(NoRequest::class);
189189
$faker = OpenAPIFaker::createFromYaml($specYaml);
190190
$faker->mockRequest($path, $method, $contentType);
191191
}
@@ -234,7 +234,7 @@ function it_throws_exception_if_response_cannot_be_found(string $path, string $m
234234
$ref: '#/components/schemas/Todo'
235235
YAML;
236236

237-
$this->expectException(NoResponse::class);
237+
self::expectException(NoResponse::class);
238238
$faker = OpenAPIFaker::createFromYaml($specYaml);
239239
$faker->mockResponse($path, $method, $statusCode, $contentType);
240240
}
@@ -277,7 +277,7 @@ function it_throws_exception_if_operation_not_found_in_responses()
277277
$ref: '#/components/schemas/Todo'
278278
YAML;
279279

280-
$this->expectException(NoPath::class);
280+
self::expectException(NoPath::class);
281281
$faker = OpenAPIFaker::createFromYaml($specYaml);
282282
$faker->mockResponse('/todoss', 'GET');
283283
}
@@ -320,24 +320,24 @@ function it_throws_exception_if_operation_not_found_in_requests()
320320
$ref: '#/components/schemas/Todo'
321321
YAML;
322322

323-
$this->expectException(NoPath::class);
323+
self::expectException(NoPath::class);
324324
$faker = OpenAPIFaker::createFromYaml($specYaml);
325325
$faker->mockRequest('/todoss', 'GET');
326326
}
327327

328328
/** @test */
329329
function it_can_mock_a_specific_schema()
330330
{
331-
$specYaml = $this->getTodosSpec();
331+
$specYaml = self::getTodosSpec();
332332

333333
$faker = OpenAPIFaker::createFromYaml($specYaml);
334334
$todo = $faker->mockComponentSchema('Todo');
335335

336-
$this->assertIsArray($todo);
337-
$this->assertArrayHasKey('id', $todo);
338-
$this->assertIsInt($todo['id']);
339-
$this->assertArrayHasKey('name', $todo);
340-
$this->assertIsString($todo['name']);
336+
self::assertIsArray($todo);
337+
self::assertArrayHasKey('id', $todo);
338+
self::assertIsInt($todo['id']);
339+
self::assertArrayHasKey('name', $todo);
340+
self::assertIsString($todo['name']);
341341
}
342342

343343
/** @test */
@@ -379,15 +379,15 @@ function it_will_mock_the_response()
379379

380380
$fakeData = OpenAPIFaker::createFromYaml($yamlSpec)->mockResponse('/todos', 'GET');
381381

382-
$this->assertIsArray($fakeData);
383-
$this->assertGreaterThanOrEqual(0, count($fakeData));
382+
self::assertIsArray($fakeData);
383+
self::assertGreaterThanOrEqual(0, count($fakeData));
384384

385385
foreach ($fakeData as $fakeDatum) {
386-
$this->assertIsArray($fakeDatum);
387-
$this->assertArrayHasKey('id', $fakeDatum);
388-
$this->assertIsInt($fakeDatum['id']);
389-
$this->assertArrayHasKey('name', $fakeDatum);
390-
$this->assertIsString($fakeDatum['name']);
386+
self::assertIsArray($fakeDatum);
387+
self::assertArrayHasKey('id', $fakeDatum);
388+
self::assertIsInt($fakeDatum['id']);
389+
self::assertArrayHasKey('name', $fakeDatum);
390+
self::assertIsString($fakeDatum['name']);
391391
}
392392
}
393393

@@ -402,7 +402,7 @@ function it_will_throw_exception_if_spec_does_not_have_any_components()
402402
describe: Empty
403403
YAML;
404404

405-
$this->expectException(NoSchema::class);
405+
self::expectException(NoSchema::class);
406406
$faker = OpenAPIFaker::createFromYaml($specYaml);
407407
$faker->mockComponentSchema('DummySchema');
408408
}
@@ -433,7 +433,7 @@ function it_will_throw_exception_if_schema_does_not_exist()
433433
type: string
434434
YAML;
435435

436-
$this->expectException(NoSchema::class);
436+
self::expectException(NoSchema::class);
437437
$faker = OpenAPIFaker::createFromYaml($specYaml);
438438
$faker->mockComponentSchema('DummySchema');
439439
}

tests/Unit/SchemaFaker/ArrayFakerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ function it_can_generate_unique_elements()
143143
JSON
144144
));
145145

146-
$this->assertIsArray($fakeData);
147-
$this->assertSame($fakeData, array_unique($fakeData));
146+
self::assertIsArray($fakeData);
147+
self::assertSame($fakeData, array_unique($fakeData));
148148
}
149149

150150
/** @test */
@@ -167,6 +167,6 @@ enum:
167167

168168
$uniqueArray = array_unique($fakeData);
169169
sort($uniqueArray);
170-
$this->assertSame([4, 88, 6789], $uniqueArray);
170+
self::assertSame([4, 88, 6789], $uniqueArray);
171171
}
172172
}

tests/Unit/SchemaFaker/BooleanFakerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function it_can_generate_boolean_value()
2222

2323
$fakeData = BooleanFaker::generate(SchemaFactory::fromYaml($yaml));
2424

25-
$this->assertIsBool($fakeData);
25+
self::assertIsBool($fakeData);
2626
}
2727

2828
/** @test */
@@ -36,6 +36,6 @@ enum:
3636

3737
$fakeData = BooleanFaker::generate(SchemaFactory::fromYaml($yaml));
3838

39-
$this->assertTrue($fakeData);
39+
self::assertTrue($fakeData);
4040
}
4141
}

tests/Unit/SchemaFaker/NumberFakerTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function it_can_generate_a_number()
2222

2323
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
2424

25-
$this->assertIsNumeric($fakeData);
25+
self::assertIsNumeric($fakeData);
2626
$this->assertMatchesJsonSnapshot($fakeData);
2727
}
2828

@@ -36,7 +36,7 @@ function it_can_handle_number_float_format()
3636

3737
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
3838

39-
$this->assertIsFloat($fakeData);
39+
self::assertIsFloat($fakeData);
4040
$this->assertMatchesJsonSnapshot($fakeData);
4141
}
4242

@@ -50,7 +50,7 @@ function it_can_handle_number_double_format()
5050

5151
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
5252

53-
$this->assertIsFloat($fakeData);
53+
self::assertIsFloat($fakeData);
5454
$this->assertMatchesJsonSnapshot($fakeData);
5555
}
5656

@@ -63,7 +63,7 @@ function it_can_generate_a_integer()
6363

6464
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
6565

66-
$this->assertIsInt($fakeData);
66+
self::assertIsInt($fakeData);
6767
$this->assertMatchesJsonSnapshot($fakeData);
6868
}
6969

@@ -77,7 +77,7 @@ function it_can_handle_integer_int32_format()
7777

7878
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
7979

80-
$this->assertIsInt($fakeData);
80+
self::assertIsInt($fakeData);
8181
$this->assertMatchesJsonSnapshot($fakeData);
8282
}
8383

@@ -91,7 +91,7 @@ function it_can_handle_integer_int64_format()
9191

9292
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
9393

94-
$this->assertIsInt($fakeData);
94+
self::assertIsInt($fakeData);
9595
$this->assertMatchesJsonSnapshot($fakeData);
9696
}
9797

@@ -105,8 +105,8 @@ function it_can_handle_minimum_keyword()
105105

106106
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
107107

108-
$this->assertIsInt($fakeData);
109-
$this->assertGreaterThanOrEqual(100, $fakeData);
108+
self::assertIsInt($fakeData);
109+
self::assertGreaterThanOrEqual(100, $fakeData);
110110
$this->assertMatchesJsonSnapshot($fakeData);
111111
}
112112

@@ -120,8 +120,8 @@ function it_can_handle_maximum_keyword()
120120

121121
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
122122

123-
$this->assertIsInt($fakeData);
124-
$this->assertLessThanOrEqual(100, $fakeData);
123+
self::assertIsInt($fakeData);
124+
self::assertLessThanOrEqual(100, $fakeData);
125125
$this->assertMatchesJsonSnapshot($fakeData);
126126
}
127127

@@ -136,7 +136,7 @@ function it_can_handle_both_minimum_and_maximum_keyword()
136136

137137
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
138138

139-
$this->assertIsNumeric($fakeData);
139+
self::assertIsNumeric($fakeData);
140140
$this->assertMatchesJsonSnapshot($fakeData);
141141
}
142142

@@ -152,8 +152,8 @@ function it_can_handle_exclusive_minimum_keyword()
152152

153153
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
154154

155-
$this->assertIsInt($fakeData);
156-
$this->assertGreaterThan(100, $fakeData);
155+
self::assertIsInt($fakeData);
156+
self::assertGreaterThan(100, $fakeData);
157157
$this->assertMatchesJsonSnapshot($fakeData);
158158
}
159159

@@ -169,8 +169,8 @@ function it_can_handle_exclusive_maximum_keyword()
169169

170170
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
171171

172-
$this->assertIsInt($fakeData);
173-
$this->assertLessThan(102, $fakeData);
172+
self::assertIsInt($fakeData);
173+
self::assertLessThan(102, $fakeData);
174174
$this->assertMatchesJsonSnapshot($fakeData);
175175
}
176176

@@ -187,8 +187,8 @@ function it_can_handle_both_exclusive_minimum_and_exclusive_maximum_keyword()
187187

188188
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
189189

190-
$this->assertIsInt($fakeData);
191-
$this->assertSame(101, $fakeData);
190+
self::assertIsInt($fakeData);
191+
self::assertSame(101, $fakeData);
192192
$this->assertMatchesJsonSnapshot($fakeData);
193193
}
194194

@@ -202,8 +202,8 @@ function it_can_handle_multiple_of_keyword()
202202

203203
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
204204

205-
$this->assertIsInt($fakeData);
206-
$this->assertSame(0, $fakeData % 10);
205+
self::assertIsInt($fakeData);
206+
self::assertSame(0, $fakeData % 10);
207207
}
208208

209209
/** @test */
@@ -216,8 +216,8 @@ function it_can_handle_multiple_of_keyword_with_float_number()
216216

217217
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
218218

219-
$this->assertIsFloat($fakeData);
220-
$this->assertSame(0, $fakeData % 8);
219+
self::assertIsFloat($fakeData);
220+
self::assertSame(0, $fakeData % 8);
221221
}
222222

223223
/** @test */
@@ -233,7 +233,7 @@ enum:
233233

234234
$fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml));
235235

236-
$this->assertIsFloat($fakeData);
236+
self::assertIsFloat($fakeData);
237237
$this->assertMatchesJsonSnapshot($fakeData);
238238
}
239239
}

tests/Unit/SchemaFaker/ObjectFakerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ function it_includes_required_properties_all_the_time()
8585

8686
$fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml));
8787

88-
$this->assertIsArray($fakeData);
89-
$this->assertArrayHasKey('id', $fakeData);
90-
$this->assertArrayHasKey('username', $fakeData);
88+
self::assertIsArray($fakeData);
89+
self::assertArrayHasKey('id', $fakeData);
90+
self::assertArrayHasKey('username', $fakeData);
9191
$this->assertMatchesJsonSnapshot($fakeData);
9292
}
9393
}

0 commit comments

Comments
 (0)