Skip to content

Commit 500eb42

Browse files
committed
Tests - Skip tests if they don't match the expected implementation
1 parent fe3afc4 commit 500eb42

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Tests/InflectorTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function testAddRuleException()
109109
{
110110
$this->expectException(\InvalidArgumentException::class);
111111

112+
/** @noinspection PhpParamsInspection */
112113
TestHelper::invoke($this->inflector, 'addRule', new \stdClass, 'singular');
113114
}
114115

@@ -145,6 +146,11 @@ public function testAddCountableRule()
145146
*/
146147
public function testAddWordWithoutPlural()
147148
{
149+
if (!$this->checkInflectorImplementation($this->inflector))
150+
{
151+
$this->markTestSkipped('This test depends on the library\'s implementation');
152+
}
153+
148154
$this->assertSame(
149155
$this->inflector,
150156
$this->inflector->addWord('foo')
@@ -168,6 +174,11 @@ public function testAddWordWithoutPlural()
168174
*/
169175
public function testAddWordWithPlural()
170176
{
177+
if (!$this->checkInflectorImplementation($this->inflector))
178+
{
179+
$this->markTestSkipped('This test depends on the library\'s implementation');
180+
}
181+
171182
$this->assertEquals(
172183
$this->inflector,
173184
$this->inflector->addWord('bar', 'foo')
@@ -193,6 +204,11 @@ public function testAddWordWithPlural()
193204
*/
194205
public function testAddPluraliseRule()
195206
{
207+
if (!$this->checkInflectorImplementation($this->inflector))
208+
{
209+
$this->markTestSkipped('This test depends on the library\'s implementation');
210+
}
211+
196212
$this->assertSame(
197213
$this->inflector->addPluraliseRule(['/^(custom)$/i' => '\1izables']),
198214
$this->inflector,
@@ -213,6 +229,11 @@ public function testAddPluraliseRule()
213229
*/
214230
public function testAddSingulariseRule()
215231
{
232+
if (!$this->checkInflectorImplementation($this->inflector))
233+
{
234+
$this->markTestSkipped('This test depends on the library\'s implementation');
235+
}
236+
216237
$this->assertSame(
217238
$this->inflector->addSingulariseRule(['/^(inflec|contribu)tors$/i' => '\1ta']),
218239
$this->inflector,
@@ -272,6 +293,10 @@ public function testIsCountable(string $input, bool $expected)
272293
*/
273294
public function testIsPlural(string $singular, string $plural)
274295
{
296+
if ($singular === 'bus' && !$this->checkInflectorImplementation($this->inflector)) {
297+
$this->markTestSkipped('"bus/buses" is not known to the new implementation');
298+
}
299+
275300
$this->assertTrue(
276301
$this->inflector->isPlural($plural),
277302
"'$plural' should be reported as plural"
@@ -296,6 +321,11 @@ public function testIsPlural(string $singular, string $plural)
296321
*/
297322
public function testIsSingular(string $singular, string $plural)
298323
{
324+
if ($singular === 'bus' && !$this->checkInflectorImplementation($this->inflector))
325+
{
326+
$this->markTestSkipped('"bus/buses" is not known to the new implementation');
327+
}
328+
299329
$this->assertTrue(
300330
$this->inflector->isSingular($singular),
301331
"'$singular' should be reported as singular"
@@ -361,10 +391,22 @@ public function testToSingular(string $singular, string $plural)
361391
*/
362392
public function testToSingularAlreadySingular()
363393
{
394+
if (!$this->checkInflectorImplementation($this->inflector))
395+
{
396+
$this->markTestSkipped('"bus/buses" is not known to the new implementation');
397+
}
398+
364399
$this->assertSame(
365400
'bus',
366401
$this->inflector->toSingular('bus'),
367402
"'bus' should not be singularised'"
368403
);
369404
}
405+
406+
private function checkInflectorImplementation(DoctrineInflector $inflector): bool
407+
{
408+
$reflectionClass = new \ReflectionClass($inflector);
409+
410+
return $reflectionClass->hasProperty('plural');
411+
}
370412
}

0 commit comments

Comments
 (0)