Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function create(string $resourceClass, array $options = []): PropertyName
}

$propertyName = $this->reflection->getProperty($reflectionMethod->name);
if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
$propertyName = lcfirst($propertyName);
}

Expand Down
59 changes: 59 additions & 0 deletions tests/Fixtures/TestBundle/Entity/UpperCaseIdentifierDummy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
* UpperCaseIdentifier dummy.
*
* @ApiResource
* @ORM\Entity
*/
class UpperCaseIdentifierDummy
{
/**
* @var string The custom identifier
*
* @ORM\Column(type="guid")
* @ORM\Id
*/
private $Uuid;

/**
* @var string The dummy name
*
* @ORM\Column(length=30)
*/
private $name;

public function getUuid(): string
{
return $this->Uuid;
}

public function setUuid(string $Uuid)
{
$this->Uuid = $Uuid;
}

public function getName(): string
{
return $this->name;
}

public function setName(string $name)
{
$this->name = $name;
}
}
2 changes: 2 additions & 0 deletions tests/Fixtures/TestBundle/Entity/UuidIdentifierDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/**
* Custom identifier dummy.
*
* @author Exploit.cz <insekticid@exploit.cz>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol no I wondered the same

IMO we should keep as @author the one who created the class not uppon each edit :). Should be fixed in other classes too. Still, what's the point of adding @author when we can git blame?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@insekticid I have no problems with the @author tag but you made no changes on this class! 😄
Add it to the UpperCaseIdentifierDummy class instead, it's more relevant! 😉

*
* @ApiResource
* @ORM\Entity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyNameCollection;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UpperCaseIdentifierDummy;
use Doctrine\Common\Annotations\Reader;
use Prophecy\Argument;
use Prophecy\Prophecy\ProphecyInterface;
Expand Down Expand Up @@ -60,6 +61,36 @@ public function getDependencies()
];
}

/**
* @dataProvider getUpperCaseDependencies
*/
public function testUpperCaseCreate(ProphecyInterface $decorated = null, array $results)
{
$reader = $this->prophesize(Reader::class);
$reader->getPropertyAnnotation(new \ReflectionProperty(UpperCaseIdentifierDummy::class, 'name'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
$reader->getPropertyAnnotation(new \ReflectionProperty(UpperCaseIdentifierDummy::class, 'Uuid'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
$reader->getPropertyAnnotation(Argument::type(\ReflectionProperty::class), ApiProperty::class)->willReturn(null)->shouldBeCalled();
$reader->getMethodAnnotation(new \ReflectionMethod(UpperCaseIdentifierDummy::class, 'getName'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
$reader->getMethodAnnotation(new \ReflectionMethod(UpperCaseIdentifierDummy::class, 'getUuid'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
$reader->getMethodAnnotation(Argument::type(\ReflectionMethod::class), ApiProperty::class)->willReturn(null)->shouldBeCalled();

$factory = new AnnotationPropertyNameCollectionFactory($reader->reveal(), $decorated ? $decorated->reveal() : null);
$metadata = $factory->create(UpperCaseIdentifierDummy::class, []);

$this->assertEquals($results, iterator_to_array($metadata));
}

public function getUpperCaseDependencies()
{
$decoratedThrowsNotFound = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
$decoratedThrowsNotFound->create(UpperCaseIdentifierDummy::class, [])->willThrow(new ResourceClassNotFoundException())->shouldBeCalled();

return [
[null, ['Uuid', 'name']],
[$decoratedThrowsNotFound, ['Uuid', 'name']],
];
}

/**
* @expectedException \ApiPlatform\Core\Exception\ResourceClassNotFoundException
* @expectedExceptionMessage The resource class "\DoNotExist" does not exist.
Expand Down