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 #258 from lmc-eu/feature/reflections-replace
Replace deprecated nette/reflection
- Loading branch information
Showing
22 changed files
with
435 additions
and
76 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
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
16 changes: 0 additions & 16 deletions
16
src-tests/Process/Fixtures/InvalidTests/MultipleClassesInFileTest.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,136 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations; | ||
|
||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassEmptyDockBlock; | ||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassKeyAnnotations; | ||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassKeyValueAnnotations; | ||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassMixedAnnotations; | ||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassNoDocBlock; | ||
use Lmc\Steward\Utils\Annotations\Fixtures\ClassWithMethods; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Lmc\Steward\Utils\Annotations\ClassAnnotations | ||
*/ | ||
class ClassAnnotationsTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideClass | ||
*/ | ||
public function testShouldGetAnnotationsForClass(string $className, array $expectedAnnotations): void | ||
{ | ||
$annotations = ClassAnnotations::getAnnotationsForClass($className); | ||
|
||
$this->assertSame($expectedAnnotations, $annotations); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function provideClass(): array | ||
{ | ||
return [ | ||
'Class with empty doc block' => [ | ||
ClassEmptyDockBlock::class, | ||
[], | ||
], | ||
'Class having no doc block at all' => [ | ||
ClassNoDocBlock::class, | ||
[], | ||
], | ||
'Class with key-only annotations, without values' => [ | ||
ClassKeyAnnotations::class, | ||
[ | ||
'first' => ['', ''], | ||
'second' => [''], | ||
'third' => [''], | ||
], | ||
], | ||
'Class with key-value annotations' => [ | ||
ClassKeyValueAnnotations::class, | ||
[ | ||
'first' => ['First value', 'Second value of first'], | ||
'second' => ['Second value'], | ||
'third' => ['Third "special" value'], | ||
], | ||
], | ||
'Class with mixed key-only and key-value annotations' => [ | ||
ClassMixedAnnotations::class, | ||
[ | ||
'first' => ['', 'First with some value'], | ||
'second' => [''], | ||
'third' => [''], | ||
'fourth' => ['Fourth value'], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
public function testShouldGetAnnotationsForInstances(): void | ||
{ | ||
$annotations = ClassAnnotations::getAnnotationsForInstance(new ClassKeyAnnotations()); | ||
|
||
$this->assertSame( | ||
[ | ||
'first' => ['', ''], | ||
'second' => [''], | ||
'third' => [''], | ||
], | ||
$annotations | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider provideMethod | ||
*/ | ||
public function testShouldGetAnnotationsForMethodInClass(string $methodName, array $expectedAnnotations): void | ||
{ | ||
$classInstance = new ClassWithMethods(); | ||
|
||
$annotations = ClassAnnotations::getAnnotationsForMethodOfInstance($classInstance, $methodName); | ||
|
||
$this->assertSame($expectedAnnotations, $annotations); | ||
} | ||
|
||
/** | ||
* @return array[] | ||
*/ | ||
public function provideMethod(): array | ||
{ | ||
return [ | ||
'Method with empty doc block' => [ | ||
'methodWithEmptyAnnotations', | ||
[], | ||
], | ||
'Method having no doc block at all' => [ | ||
'methodWithout', | ||
[], | ||
], | ||
'Method with key-only annotations, without values' => [ | ||
'methodWithKeys', | ||
[ | ||
'first' => ['', ''], | ||
'second' => [''], | ||
'third' => [''], | ||
], | ||
], | ||
'Method with key-value annotations' => [ | ||
'methodWithKeyValues', | ||
[ | ||
'first' => ['First value', 'Second value of first'], | ||
'second' => ['Second value'], | ||
'third' => ['Third "special" @value!'], | ||
], | ||
], | ||
'Method with mixed key-only and key-value annotations' => [ | ||
'methodWithMixedKeyValues', | ||
[ | ||
'first' => ['', 'First with some value'], | ||
'second' => ['Second with value', ''], | ||
'third' => [''], | ||
], | ||
], | ||
]; | ||
} | ||
} |
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,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Utils\Annotations; | ||
|
||
use Lmc\Steward\Utils\Annotations\ClassParser; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
/** | ||
* @covers \Lmc\Steward\Utils\Annotations\ClassParser | ||
*/ | ||
class ClassParserTest extends TestCase | ||
{ | ||
public function testShouldGetClassNameFromFile(): void | ||
{ | ||
$file = $this->createFileInfo('ClassNoDocBlock.php'); | ||
|
||
$className = ClassParser::readClassNameFromFile($file); | ||
|
||
$this->assertSame('Lmc\Steward\Utils\Annotations\Fixtures\ClassNoDocBlock', $className); | ||
} | ||
|
||
public function testShouldThrowExceptionForMultipleClassesInOneFile(): void | ||
{ | ||
$file = $this->createFileInfo('MultipleClassesInFile.php'); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/^File ".+MultipleClassesInFile.php" contains definition of 2 classes\./'); | ||
ClassParser::readClassNameFromFile($file); | ||
} | ||
|
||
public function testShouldThrowExceptionForNoClassInOneFile(): void | ||
{ | ||
$file = $this->createFileInfo('NoClassInFile.php'); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/^No class found in file ".+NoClassInFile.php"/'); | ||
ClassParser::readClassNameFromFile($file); | ||
} | ||
|
||
private function createFileInfo(string $fileName): SplFileInfo | ||
{ | ||
return new SplFileInfo(__DIR__ . '/Fixtures/' . $fileName, 'Fixtures/', 'Fixtures/' . $fileName); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src-tests/Utils/Annotations/Fixtures/ClassEmptyDockBlock.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
/** | ||
* | ||
*/ | ||
class ClassEmptyDockBlock | ||
{ | ||
} |
15 changes: 15 additions & 0 deletions
15
src-tests/Utils/Annotations/Fixtures/ClassKeyAnnotations.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
/** | ||
* Some text with @tag, which will not be treated as annotation. | ||
* | ||
* @first | ||
* @second | ||
* @third | ||
* @first | ||
*/ | ||
class ClassKeyAnnotations | ||
{ | ||
} |
13 changes: 13 additions & 0 deletions
13
src-tests/Utils/Annotations/Fixtures/ClassKeyValueAnnotations.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
/** | ||
* @first First value | ||
* @second Second value | ||
* @third Third "special" value | ||
* @first Second value of first | ||
*/ | ||
class ClassKeyValueAnnotations | ||
{ | ||
} |
14 changes: 14 additions & 0 deletions
14
src-tests/Utils/Annotations/Fixtures/ClassMixedAnnotations.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
/** | ||
* @first | ||
* @second | ||
* @first First with some value | ||
* @third | ||
* @fourth Fourth value | ||
*/ | ||
class ClassMixedAnnotations | ||
{ | ||
} |
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,7 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
class ClassNoDocBlock | ||
{ | ||
} |
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,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
/** | ||
* This class has few methods with various annotations. | ||
* | ||
*/ | ||
class ClassWithMethods | ||
{ | ||
public function methodWithout(): void | ||
{ | ||
// method without annotations | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function methodWithEmptyAnnotations(): void | ||
{ | ||
// method with empty docBlock | ||
} | ||
|
||
/** | ||
* Some text not treated as @annotation | ||
* | ||
* @first | ||
* @second | ||
* @first | ||
* @third | ||
*/ | ||
public function methodWithKeys(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @first First value | ||
* @second Second value | ||
* @first Second value of first | ||
* @third Third "special" @value! | ||
*/ | ||
public function methodWithKeyValues(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @first | ||
* @second Second with value | ||
* @first First with some value | ||
* @second | ||
* @third | ||
*/ | ||
public function methodWithMixedKeyValues(): void | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src-tests/Utils/Annotations/Fixtures/MultipleClassesInFile.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Steward\Utils\Annotations\Fixtures; | ||
|
||
class ClassFirst | ||
{ | ||
} | ||
|
||
class ClassSecond | ||
{ | ||
} |
Oops, something went wrong.