1010use Doctrine \Common \Inflector \Inflector as DoctrineInflector ;
1111use Joomla \String \Inflector ;
1212use Joomla \Test \TestHelper ;
13+ use PHPUnit \Framework \Attributes \DataProvider ;
1314use PHPUnit \Framework \TestCase ;
1415
1516/**
@@ -28,51 +29,55 @@ class InflectorTest extends TestCase
2829 /**
2930 * Method to seed data to testIsCountable.
3031 *
31- * @return \Generator
32+ * @return array
3233 */
33- public function seedIsCountable (): \ Generator
34+ public static function seedIsCountable (): array
3435 {
35- yield ['id ' , true ];
36- yield ['title ' , false ];
36+ return [
37+ ['id ' , true ],
38+ ['title ' , false ],
39+ ];
3740 }
3841
3942 /**
4043 * Method to seed data to testToPlural.
4144 *
42- * @return \Generator
45+ * @return array
4346 *
4447 * @since 1.0
4548 */
46- public function seedSinglePlural (): \ Generator
49+ public static function seedSinglePlural (): array
4750 {
48- // Regular plurals
49- yield ['bus ' , 'buses ' ];
50- yield ['notify ' , 'notifies ' ];
51- yield ['click ' , 'clicks ' ];
51+ return [
52+ // Regular plurals
53+ ['bus ' , 'buses ' ],
54+ ['notify ' , 'notifies ' ],
55+ ['click ' , 'clicks ' ],
5256
53- // Almost regular plurals.
54- yield ['photo ' , 'photos ' ];
55- yield ['zero ' , 'zeros ' ];
57+ // Almost regular plurals.
58+ ['photo ' , 'photos ' ],
59+ ['zero ' , 'zeros ' ],
5660
57- // Irregular identicals
58- yield ['salmon ' , 'salmon ' ];
61+ // Irregular identicals
62+ ['salmon ' , 'salmon ' ],
5963
60- // Irregular plurals
61- yield ['ox ' , 'oxen ' ];
62- yield ['quiz ' , 'quizzes ' ];
63- yield ['status ' , 'statuses ' ];
64- yield ['matrix ' , 'matrices ' ];
65- yield ['index ' , 'indices ' ];
66- yield ['vertex ' , 'vertices ' ];
67- yield ['hive ' , 'hives ' ];
64+ // Irregular plurals
65+ ['ox ' , 'oxen ' ],
66+ ['quiz ' , 'quizzes ' ],
67+ ['status ' , 'statuses ' ],
68+ ['matrix ' , 'matrices ' ],
69+ ['index ' , 'indices ' ],
70+ ['vertex ' , 'vertices ' ],
71+ ['hive ' , 'hives ' ],
6872
69- // Ablaut plurals
70- yield ['foot ' , 'feet ' ];
71- yield ['louse ' , 'lice ' ];
72- yield ['man ' , 'men ' ];
73- yield ['mouse ' , 'mice ' ];
74- yield ['tooth ' , 'teeth ' ];
75- yield ['woman ' , 'women ' ];
73+ // Ablaut plurals
74+ ['foot ' , 'feet ' ],
75+ ['louse ' , 'lice ' ],
76+ ['man ' , 'men ' ],
77+ ['mouse ' , 'mice ' ],
78+ ['tooth ' , 'teeth ' ],
79+ ['woman ' , 'women ' ],
80+ ];
7681 }
7782
7883 /**
@@ -86,7 +91,7 @@ protected function setUp(): void
8691 {
8792 parent ::setUp ();
8893
89- $ this ->inflector = Inflector:: getInstance ( true );
94+ $ this ->inflector = new Inflector ( );
9095 DoctrineInflector::reset ();
9196 }
9297
@@ -142,136 +147,13 @@ public function testAddCountableRule()
142147 );
143148 }
144149
145- /**
146- * @testdox A word can be added to the inflector without a plural form
147- */
148- public function testAddWordWithoutPlural ()
149- {
150- if (!$ this ->checkInflectorImplementation ($ this ->inflector )) {
151- $ this ->markTestSkipped ('This test depends on the library \'s implementation ' );
152- }
153-
154- $ this ->assertSame (
155- $ this ->inflector ,
156- $ this ->inflector ->addWord ('foo ' )
157- );
158-
159- $ plural = TestHelper::getValue (DoctrineInflector::class, 'plural ' );
160-
161- $ this ->assertTrue (
162- in_array ('foo ' , $ plural ['uninflected ' ])
163- );
164-
165- $ singular = TestHelper::getValue (DoctrineInflector::class, 'singular ' );
166-
167- $ this ->assertTrue (
168- in_array ('foo ' , $ singular ['uninflected ' ])
169- );
170- }
171-
172- /**
173- * @testdox A word can be added to the inflector with a plural form
174- */
175- public function testAddWordWithPlural ()
176- {
177- if (!$ this ->checkInflectorImplementation ($ this ->inflector )) {
178- $ this ->markTestSkipped ('This test depends on the library \'s implementation ' );
179- }
180-
181- $ this ->assertEquals (
182- $ this ->inflector ,
183- $ this ->inflector ->addWord ('bar ' , 'foo ' )
184- );
185-
186- $ plural = TestHelper::getValue (DoctrineInflector::class, 'plural ' );
187-
188- $ this ->assertArrayHasKey (
189- 'foo ' ,
190- $ plural ['irregular ' ]
191- );
192-
193- $ singular = TestHelper::getValue (DoctrineInflector::class, 'singular ' );
194-
195- $ this ->assertArrayHasKey (
196- 'bar ' ,
197- $ singular ['irregular ' ]
198- );
199- }
200-
201- /**
202- * @testdox A pluralisation rule can be added to the inflector
203- */
204- public function testAddPluraliseRule ()
205- {
206- if (!$ this ->checkInflectorImplementation ($ this ->inflector )) {
207- $ this ->markTestSkipped ('This test depends on the library \'s implementation ' );
208- }
209-
210- $ this ->assertSame (
211- $ this ->inflector ->addPluraliseRule (['/^(custom)$/i ' => '\1izables ' ]),
212- $ this ->inflector ,
213- 'Checks chaining. '
214- );
215-
216- $ plural = TestHelper::getValue (DoctrineInflector::class, 'plural ' );
217-
218- $ this ->assertArrayHasKey (
219- '/^(custom)$/i ' ,
220- $ plural ['rules ' ],
221- 'Checks a pluralisation rule was added. '
222- );
223- }
224-
225- /**
226- * @testdox A singularisation rule can be added to the inflector
227- */
228- public function testAddSingulariseRule ()
229- {
230- if (!$ this ->checkInflectorImplementation ($ this ->inflector )) {
231- $ this ->markTestSkipped ('This test depends on the library \'s implementation ' );
232- }
233-
234- $ this ->assertSame (
235- $ this ->inflector ->addSingulariseRule (['/^(inflec|contribu)tors$/i ' => '\1ta ' ]),
236- $ this ->inflector ,
237- 'Checks chaining. '
238- );
239-
240- $ singular = TestHelper::getValue (DoctrineInflector::class, 'singular ' );
241-
242- $ this ->assertArrayHasKey (
243- '/^(inflec|contribu)tors$/i ' ,
244- $ singular ['rules ' ],
245- 'Checks a singularisation rule was added. '
246- );
247- }
248-
249- /**
250- * @testdox The singleton instance of the inflector can be retrieved
251- */
252- public function testGetInstance ()
253- {
254- $ this ->assertInstanceOf (
255- Inflector::class,
256- Inflector::getInstance (),
257- 'Check getInstance returns the right class. '
258- );
259-
260- $ this ->assertNotSame (
261- Inflector::getInstance (),
262- Inflector::getInstance (true ),
263- 'getInstance with the new flag should not return the singleton instance '
264- );
265- }
266-
267150 /**
268151 * @testdox A string is checked to determine if it a countable word
269152 *
270153 * @param string $input A string.
271154 * @param boolean $expected The expected result of the function call.
272- *
273- * @dataProvider seedIsCountable
274155 */
156+ #[DataProvider('seedIsCountable ' )]
275157 public function testIsCountable (string $ input , bool $ expected )
276158 {
277159 $ this ->assertEquals (
@@ -285,9 +167,8 @@ public function testIsCountable(string $input, bool $expected)
285167 *
286168 * @param string $singular The singular form of a word.
287169 * @param string $plural The plural form of a word.
288- *
289- * @dataProvider seedSinglePlural
290170 */
171+ #[Dataprovider('seedSinglePlural ' )]
291172 public function testIsPlural (string $ singular , string $ plural )
292173 {
293174 if ($ singular === 'bus ' && !$ this ->checkInflectorImplementation ($ this ->inflector )) {
@@ -312,9 +193,8 @@ public function testIsPlural(string $singular, string $plural)
312193 *
313194 * @param string $singular The singular form of a word.
314195 * @param string $plural The plural form of a word.
315- *
316- * @dataProvider seedSinglePlural
317196 */
197+ #[Dataprovider('seedSinglePlural ' )]
318198 public function testIsSingular (string $ singular , string $ plural )
319199 {
320200 if ($ singular === 'bus ' && !$ this ->checkInflectorImplementation ($ this ->inflector )) {
@@ -334,68 +214,6 @@ public function testIsSingular(string $singular, string $plural)
334214 }
335215 }
336216
337- /**
338- * @testdox A string is converted to its plural form
339- *
340- * @param string $singular The singular form of a word.
341- * @param string $plural The plural form of a word.
342- *
343- * @dataProvider seedSinglePlural
344- */
345- public function testToPlural (string $ singular , string $ plural )
346- {
347- $ this ->assertSame (
348- $ plural ,
349- $ this ->inflector ->toPlural ($ singular ),
350- "' $ plural' should be the plural form of ' $ singular' "
351- );
352- }
353-
354- /**
355- * @testdox A string that is already plural is returned in the same form
356- */
357- public function testToPluralAlreadyPlural ()
358- {
359- $ this ->assertSame (
360- 'buses ' ,
361- $ this ->inflector ->toPlural ('buses ' ),
362- "'buses' should not be pluralised' "
363- );
364- }
365-
366- /**
367- * @testdox A string is converted to its singular form
368- *
369- * @param string $singular The singular form of a word.
370- * @param string $plural The plural form of a word.
371- *
372- * @dataProvider seedSinglePlural
373- */
374- public function testToSingular (string $ singular , string $ plural )
375- {
376- $ this ->assertSame (
377- $ singular ,
378- $ this ->inflector ->toSingular ($ plural ),
379- "' $ singular' should be the singular form of ' $ plural' "
380- );
381- }
382-
383- /**
384- * @testdox A string that is already singular is returned in the same form
385- */
386- public function testToSingularAlreadySingular ()
387- {
388- if (!$ this ->checkInflectorImplementation ($ this ->inflector )) {
389- $ this ->markTestSkipped ('"bus/buses" is not known to the new implementation ' );
390- }
391-
392- $ this ->assertSame (
393- 'bus ' ,
394- $ this ->inflector ->toSingular ('bus ' ),
395- "'bus' should not be singularised' "
396- );
397- }
398-
399217 private function checkInflectorImplementation (DoctrineInflector $ inflector ): bool
400218 {
401219 $ reflectionClass = new \ReflectionClass ($ inflector );
0 commit comments