Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Reflect groupping and short array syntax in property spec
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Nov 5, 2017
1 parent e49f0ed commit f893e81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Specs/Builder/PropertySpecBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getSpecMethodsOrType(PropertySpecPrototype $proto, string $de
return;
}

if (preg_match('/^(?<type>\w+(?:\(.*\))?)$/', $definition, $matches)) {
if (preg_match('/^(?<type>([\w\-]*(?:\(.*\))?(?:\[\s*\])?)(?:\s*\|\s*(?-1))*)$/', $definition, $matches)) {
$proto->definition = $this->builder->build($matches['type']);

return;
Expand Down
28 changes: 28 additions & 0 deletions tests/Specs/Builder/PropertySpecBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,34 @@ public function testBuildingTyped()
$this->assertNull($spec->getSetterName());
}

public function testBuildingTypedArray()
{
$this->extractorDefinitionShouldBuildOn('[]');

$spec = $this->builder->build('[]');

$this->assertInstanceOf(PropertySpecInterface::class, $spec);

$this->assertInstanceOf(ExtractorDefinitionInterface::class, $spec->getExtractorDefinition());
$this->assertFalse($spec->isReadonly());
$this->assertNull($spec->getGetterName());
$this->assertNull($spec->getSetterName());
}

public function testBuildingTypedAndGroupedArray()
{
$this->extractorDefinitionShouldBuildOn('(foo|bar[])[]');

$spec = $this->builder->build('(foo|bar[])[]');

$this->assertInstanceOf(PropertySpecInterface::class, $spec);

$this->assertInstanceOf(ExtractorDefinitionInterface::class, $spec->getExtractorDefinition());
$this->assertFalse($spec->isReadonly());
$this->assertNull($spec->getGetterName());
$this->assertNull($spec->getSetterName());
}

public function testBuildingReadonlyTyped()
{
$this->extractorDefinitionShouldBuildOn('test');
Expand Down

0 comments on commit f893e81

Please sign in to comment.