29 Commits
1.0 ... 1.2.0

Author SHA1 Message Date
Benjamin Eberlei
b699ecc7f2 Merge pull request #35 from doctrine/GH-34-SetValueUnitialized
[GH-34] Instead of NULL, unitialize typed properties without default.
2020-03-21 12:34:59 +01:00
Benjamin Eberlei
cd4811c644 [GH-34] Instead of NULL, unitialize typed properties without default. 2020-03-16 09:38:51 +01:00
Maciej Malarz
aa0689034e Merge pull request #31 from Spomky/patch-1
No doc files for distribution
2020-02-28 21:27:16 +01:00
Florent Morselli
2fc2828857 No doc files for distribution
This PR adds the folder `/docs` in .gitattributes so that it will not be present in distribution
2020-02-28 14:43:01 +01:00
Claudio Zizza
c7588e0baa Merge pull request #30 from doctrine/patch-1
Update of project config for latest version
2020-01-29 22:57:36 +01:00
Claudio Zizza
d9cf1f3deb Update of project config for latest version
Because of a failing website build the config for the
latest version was adapted to the same version
syntax like in other Doctrine projects.
2020-01-29 00:23:19 +01:00
Andreas Braun
12fea966b2 Update branch-alias to 1.2.x-dev 2020-01-18 13:09:54 +01:00
Andreas Braun
c390808aca Update maintained branches 2020-01-18 13:09:53 +01:00
Benjamin Eberlei
bc420ead87 Run PHPStan with PHP 7.4 for typed properties related checks. 2020-01-08 20:53:19 +01:00
Benjamin Eberlei
68b6aa3299 Merge branch 'add_reflection_typed_no_default_property_class' 2020-01-08 20:47:06 +01:00
Grégoire Paris
895c94dcee Merge pull request #28 from andreybolonin/patch-2
Use php 7.4 image instead of 7.4snapshot
2020-01-04 18:34:07 +01:00
Andrey Bolonin
45270d8e58 Use php 7.4 image instead of 7.4snapshot 2020-01-04 19:09:00 +02:00
Andreas Braun
76bb6bc20a Merge pull request #26 from sspat/fix_annotation_parsing_for_classes_creating_anon_classes
Fix reading docblocks for classes containing anonymous classes
2019-12-03 16:26:53 +01:00
Patrik Foldes
9acbb8ccce Replaced isset with ReflectionProperty::isInitialized #23 2019-12-03 16:23:51 +01:00
Patrik Foldes
8299ca45da Changed the property access syntax again #23 2019-12-03 16:23:51 +01:00
Patrik Foldes
7fba840747 Changed dynamic property name access syntax #23 2019-12-03 16:23:51 +01:00
Patrik Foldes
bbf9810b57 Changed test assertion method #23 2019-12-03 16:23:51 +01:00
Patrik Foldes
6efdc3f15a Added php 7.4 specific tests directory to composer autoloading config #23 2019-12-03 16:23:51 +01:00
Patrik Foldes
0ac0da52c1 Updated phpunit and travis configs to work with tests containing code in php 7.4 syntax #23 2019-12-03 16:23:50 +01:00
Patrik Foldes
70707057f6 Added reflection class for handling typed properties without default value #23 2019-12-03 16:22:57 +01:00
Andreas Braun
f3e4e24667 Merge pull request #25 from doctrine/update-dependencies
Update dependencies for CI build
2019-12-03 16:14:59 +01:00
Andreas Braun
2c2888effb Resolve version conflict with doctrine/common 2019-12-03 16:03:00 +01:00
Patrik Foldes
512a4f0ec1 Fix for issue #19 2019-12-03 17:00:27 +03:00
Andreas Braun
07b0d59986 Simplify phpstan call on travis-ci 2019-12-02 21:17:43 +01:00
Andreas Braun
5eefae4186 Update dependencies 2019-12-02 21:15:19 +01:00
Andreas Braun
7a2c95aa7c Merge pull request #22 from sspat/fix_php74_and_windows_test_errors
Fixed tests to work with php 7.4 and on windows #21
2019-12-02 14:05:25 +01:00
Patrik Foldes
859446e967 Fixed code style #21 2019-12-02 15:14:36 +03:00
Patrik Foldes
81f27df605 Added PHP 7.4 to travis builds #21 2019-12-02 15:14:24 +03:00
Patrik Foldes
de66230870 Fixed tests to work with php 7.4 and on windows #21 2019-12-02 14:41:27 +03:00
17 changed files with 1104 additions and 536 deletions

View File

@@ -5,14 +5,26 @@
"docsSlug": "doctrine-reflection",
"versions": [
{
"name": "1.0",
"name": "1.2",
"branchName": "master",
"slug": "latest",
"upcoming": true
},
{
"name": "1.1",
"branchName": "1.1.x",
"slug": "1.1",
"current": true,
"aliases": [
"current",
"stable"
]
},
{
"name": "1.0",
"branchName": "1.0",
"slug": "1.0",
"maintained": false
}
]
}

1
.gitattributes vendored
View File

@@ -1,3 +1,4 @@
/docs export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore

View File

@@ -10,6 +10,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly
before_install:
@@ -43,4 +44,5 @@ jobs:
- ./vendor/bin/phpcs
- stage: Lint
script: vendor/bin/phpstan analyse -l 3 -c phpstan.neon lib tests
php: 7.4
script: vendor/bin/phpstan analyse

View File

@@ -22,14 +22,14 @@
"doctrine/annotations": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^0.9.2",
"phpstan/phpstan-phpunit": "^0.9.4",
"phpstan/phpstan": "^0.11.0",
"phpstan/phpstan-phpunit": "^0.11.0",
"phpunit/phpunit": "^7.0",
"doctrine/coding-standard": "^5.0",
"doctrine/common": "^2.8"
"doctrine/common": "^2.10"
},
"conflict": {
"doctrine/common": "<2.9@dev"
"doctrine/common": "<2.9"
},
"autoload": {
"psr-4": {
@@ -38,12 +38,13 @@
},
"autoload-dev": {
"psr-4": {
"Doctrine\\Tests\\": "tests/Doctrine/Tests"
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
"Doctrine\\Tests_PHP74\\": "tests/Doctrine/Tests_PHP74"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.2.x-dev"
}
}
}

1443
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -89,7 +89,7 @@ class StaticReflectionMethod extends ReflectionMethod
/**
* {@inheritDoc}
*/
public function getClosure($object)
public function getClosure($object = null)
{
throw new ReflectionException('Method not implemented');
}

View File

@@ -8,6 +8,7 @@ use const T_CLASS;
use const T_DOC_COMMENT;
use const T_EXTENDS;
use const T_FUNCTION;
use const T_NEW;
use const T_PAAMAYIM_NEKUDOTAYIM;
use const T_PRIVATE;
use const T_PROTECTED;
@@ -161,7 +162,7 @@ class StaticReflectionParser implements ReflectionProviderInterface
$docComment = $token[1];
break;
case T_CLASS:
if ($last_token !== T_PAAMAYIM_NEKUDOTAYIM) {
if ($last_token !== T_PAAMAYIM_NEKUDOTAYIM && $last_token !== T_NEW) {
$this->docComment['class'] = $docComment;
$docComment = '';
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Doctrine\Common\Reflection;
use ReflectionProperty;
/**
* PHP Typed No Default Reflection Property - special override for typed properties without a default value.
*/
class TypedNoDefaultReflectionProperty extends ReflectionProperty
{
/**
* {@inheritDoc}
*
* Checks that a typed property is initialized before accessing its value.
* This is neccessary to avoid PHP error "Error: Typed property must not be accessed before initialization".
* Should be used only for reflecting typed properties without a default value.
*/
public function getValue($object = null)
{
return $object !== null && $this->isInitialized($object) ? parent::getValue($object) : null;
}
/**
* {@inheritDoc}
*
* Works around the problem with setting typed no default properties to
* NULL which is not supported, instead unset() to uninitialize.
*
* @link https://github.com/doctrine/orm/issues/7999
*/
public function setValue($object, $value = null)
{
if ($value === null) {
$propertyName = $this->getName();
$unsetter = function () use ($propertyName) {
unset($this->$propertyName);
};
$unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName());
$unsetter();
return;
}
parent::setValue($object, $value);
}
}

View File

@@ -1,6 +1,11 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 3
paths:
- %rootDir%/../../../lib
- %rootDir%/../../../tests
ignoreErrors:
- '#Doctrine\\Common\\Reflection\\StaticReflection[a-zA-Z0-9_]+::__construct\(\) does not call parent constructor from Reflection[a-zA-Z0-9_]+#'
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

View File

@@ -8,7 +8,8 @@
>
<testsuites>
<testsuite name="Doctrine Event Manager Test Suite">
<directory>./tests/Doctrine/</directory>
<directory>./tests/Doctrine/Tests</directory>
<directory phpVersion="7.4" phpVersionOperator=">=">./tests/Doctrine/Tests_PHP74</directory>
</testsuite>
</testsuites>

View File

@@ -0,0 +1,19 @@
<?php
namespace Doctrine\Tests\Common\Reflection;
use Doctrine\Common\Annotations\Annotation;
/**
* @Annotation(
* key = "value"
* )
*/
class AnnotationClassWithAnonymousClass
{
public function foo()
{
$new_class = new class () {
};
}
}

View File

@@ -4,6 +4,7 @@ namespace Doctrine\Tests\Common\Reflection;
use Doctrine\Common\Reflection\Psr0FindFile;
use PHPUnit\Framework\TestCase;
use const DIRECTORY_SEPARATOR;
use function sprintf;
use function strlen;
use function substr;
@@ -17,7 +18,7 @@ class Psr0FindFileTest extends TestCase
{
$file = $this->psr0FindFile->findFile(NoParent::class);
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
}
public function testFindFileNotFound() : void
@@ -29,14 +30,14 @@ class Psr0FindFileTest extends TestCase
{
$file = $this->psr0FindFile->findFile('\Doctrine\Tests\Common\Reflection\NoParent');
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
}
public function testFindFileFromPearLikeClassName() : void
{
$file = $this->psr0FindFile->findFile('Doctrine_Tests_Common_Reflection_NoParent');
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
}
protected function setUp() : void

View File

@@ -56,7 +56,7 @@ class StaticReflectionClassTest extends TestCase
public function testGetMethod() : void
{
$staticReflectionMethod = $this->createMock(StaticReflectionMethod::class);
$staticReflectionMethod = $this->createPartialMock(StaticReflectionMethod::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getReflectionMethod')

View File

@@ -27,7 +27,7 @@ class StaticReflectionMethodTest extends TestCase
public function testGetDeclaringClass() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getReflectionClass')
@@ -47,7 +47,7 @@ class StaticReflectionMethodTest extends TestCase
public function testGetDocComment() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getDocComment')
@@ -59,7 +59,7 @@ class StaticReflectionMethodTest extends TestCase
public function testGetUseStatements() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getUseStatements')

View File

@@ -101,7 +101,7 @@ class StaticReflectionParserTest extends DoctrineTestCase
}
/**
* @return string[]|bool[]
* @return array<array<bool|string>>
*/
public function classAnnotationOptimize()
{
@@ -110,6 +110,8 @@ class StaticReflectionParserTest extends DoctrineTestCase
[ExampleAnnotationClass::class, true],
[AnnotationClassWithScopeResolution::class, false],
[AnnotationClassWithScopeResolution::class, true],
[AnnotationClassWithAnonymousClass::class, false],
[AnnotationClassWithAnonymousClass::class, true],
];
}
}

View File

@@ -27,7 +27,7 @@ class StaticReflectionPropertyTest extends TestCase
public function testGetDeclaringClass() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getReflectionClass')
@@ -38,7 +38,7 @@ class StaticReflectionPropertyTest extends TestCase
public function testGetDocComment() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getDocComment')
@@ -50,7 +50,7 @@ class StaticReflectionPropertyTest extends TestCase
public function testGetUseStatements() : void
{
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
$this->staticReflectionParser->expects($this->once())
->method('getUseStatements')

View File

@@ -0,0 +1,54 @@
<?php
namespace Doctrine\Tests_PHP74\Common\Reflection;
use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty;
use PHPUnit\Framework\TestCase;
class TypedNoDefaultReflectionPropertyTest extends TestCase
{
public function testGetValue() : void
{
$object = new TypedNoDefaultReflectionPropertyTestClass();
$reflProperty = new TypedNoDefaultReflectionProperty(TypedNoDefaultReflectionPropertyTestClass::class, 'test');
self::assertNull($reflProperty->getValue($object));
$object->test = 'testValue';
self::assertSame('testValue', $reflProperty->getValue($object));
unset($object->test);
self::assertNull($reflProperty->getValue($object));
}
public function testSetValueNull() : void
{
$reflection = new TypedNoDefaultReflectionProperty(TypedFoo::class, 'id');
$reflection->setAccessible(true);
$object = new TypedFoo();
$object->setId(1);
$reflection->setValue($object, null);
self::assertNull($reflection->getValue($object));
}
}
class TypedNoDefaultReflectionPropertyTestClass
{
public string $test;
}
class TypedFoo
{
private int $id;
public function setId($id)
{
$this->id = $id;
}
}