Skip to content

Commit 974d8bc

Browse files
committed
Fix dashed path segment generation
1 parent 4d0b777 commit 974d8bc

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/Operation/DashPathSegmentNameGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ final class DashPathSegmentNameGenerator implements PathSegmentNameGeneratorInte
2727
*/
2828
public function getSegmentName(string $name, bool $collection = true): string
2929
{
30-
$name = $this->dashize($name);
31-
32-
return $collection ? Inflector::pluralize($name) : $name;
30+
return $collection ? $this->dashize(Inflector::pluralize($name)) : $this->dashize($name);
3331
}
3432

3533
private function dashize(string $string): string
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Operation;
15+
16+
use ApiPlatform\Core\Operation\DashPathSegmentNameGenerator;
17+
use PHPUnit\Framework\TestCase;
18+
19+
class DashedPathSegmentNameGeneratorTest extends TestCase
20+
{
21+
public function testCreateSegmentNameGeneration()
22+
{
23+
$generator = new DashPathSegmentNameGenerator();
24+
$this->assertSame('ordering-people', $generator->getSegmentName('orderingPerson'));
25+
$this->assertSame('some-person-names', $generator->getSegmentName('somePersonName'));
26+
}
27+
}

0 commit comments

Comments
 (0)