-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Paneon/develop
Release 1.1.0
- Loading branch information
Showing
6 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
Changelog | ||
====== | ||
|
||
# 1.1.0 | ||
|
||
- Add support for psalm array syntax as well: `@var array<int>` | ||
|
||
# 1.0.0 | ||
|
||
- Initial Release of the Parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Paneon\PhpToTypeScript\Tests\Fixtures; | ||
|
||
use DateTime; | ||
use Paneon\PhpToTypeScript\Annotation as PTS; | ||
|
||
/** | ||
* @PTS\TypeScriptInterface | ||
*/ | ||
class ArrayClass | ||
{ | ||
/** | ||
* @PTS\Exclude() | ||
* | ||
* @var bool[] | ||
*/ | ||
protected $excluded; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
protected $mixedArray; | ||
|
||
/** | ||
* @var SomeClass[] | ||
*/ | ||
protected $classCollection; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $mixed; | ||
|
||
/** | ||
* @PTS\Type("ClassImplementingInterface1[]|ClassImplementingInterface2[]") | ||
*/ | ||
protected $someInterfaceArray; | ||
|
||
/** | ||
* This syntax is not correct PHPDoc actually, but anyway used sometimes. | ||
* | ||
* @var array<int> | ||
*/ | ||
protected $psalmArrayType; | ||
|
||
/** | ||
* @PTS\VirtualProperty() | ||
* @return bool[] | ||
*/ | ||
public function hasSomeValue() | ||
{ | ||
return [true]; | ||
} | ||
|
||
/** | ||
* @PTS\VirtualProperty() | ||
*/ | ||
public function virtualWithReturnType(): int | ||
{ | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Paneon\PhpToTypeScript\Tests\Services; | ||
|
||
use Paneon\PhpToTypeScript\Tests\AbstractTestCase; | ||
use ReflectionException; | ||
|
||
class ParserServiceArrayTest extends AbstractTestCase | ||
{ | ||
public function testConvertsMixedToArray() | ||
{ | ||
$content = $this->loadFixture(); | ||
|
||
$this->assertStringContainsString('mixed: any;', $content); | ||
$this->assertStringContainsString('mixedArray: any[];', $content); | ||
} | ||
|
||
public function testRespectsTypeScriptTypeAnnotationForArrays() | ||
{ | ||
$content = $this->loadFixture(); | ||
|
||
$this->assertStringContainsString('someInterfaceArray: ClassImplementingInterface1[]|ClassImplementingInterface2[];', $content); | ||
} | ||
|
||
public function testPhpDocArraySyntax() | ||
{ | ||
$content = $this->loadFixture(); | ||
|
||
$this->assertStringContainsString('classCollection: SomeClass[];', $content); | ||
} | ||
|
||
public function testPsalmArraySyntax() | ||
{ | ||
$content = $this->loadFixture(); | ||
|
||
$this->assertStringContainsString('psalmArrayType: number[];', $content); | ||
} | ||
|
||
private function loadFixture(): ?string | ||
{ | ||
$fixture = $this->getDefaultFixtureFile(); | ||
return $this->parserService->getInterfaceContent($fixture); | ||
} | ||
|
||
private function getDefaultFixtureFile(): string | ||
{ | ||
return __DIR__ . '/../Fixtures/ArrayClass.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters