-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix proxies with return types in magic methods
Co-authored-by: Jan Barášek <janbarasek@gmail.com> Co-authored-by: Miloš Havlíček <miloshavlicek@gmail.com>
- Loading branch information
1 parent
c72150a
commit 0f00cb9
Showing
9 changed files
with
474 additions
and
32 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
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicGetClassWithScalarType.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,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <jan@barasek.com> | ||
*/ | ||
class MagicGetClassWithScalarType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return string | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __get(string $name): string | ||
{ | ||
if ($name === 'test') { | ||
return 'test'; | ||
} | ||
|
||
if ($name === 'publicField' || $name === 'id') { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return 'not defined'; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicGetClassWithScalarTypeAndRenamedParameter.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,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <jan@barasek.com> | ||
*/ | ||
class MagicGetClassWithScalarTypeAndRenamedParameter | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $n | ||
* | ||
* @return string | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __get(string $n): string | ||
{ | ||
if ($n === 'test') { | ||
return 'test'; | ||
} | ||
|
||
if ($n === 'publicField' || $n === 'id') { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return 'not defined'; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Doctrine/Tests/Common/Proxy/MagicGetClassWithVoid.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,21 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Magic class asset test with void return type for getter | ||
*/ | ||
class MagicGetClassWithVoid | ||
{ | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return void | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __get(string $name): void | ||
{ | ||
return; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicIssetClassWithBoolean.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,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <jan@barasek.com> | ||
*/ | ||
class MagicIssetClassWithBoolean | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return bool | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __isset(string $name): bool | ||
{ | ||
if ('test' === $name) { | ||
return true; | ||
} | ||
|
||
if ('publicField' === $name || 'id' === $name) { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return false; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
tests/Doctrine/Tests/Common/Proxy/MagicIssetClassWithInteger.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,39 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Proxy; | ||
|
||
/** | ||
* Test asset class | ||
* @author Jan Barasek <jan@barasek.com> | ||
*/ | ||
class MagicIssetClassWithInteger | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $id = 'id'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $publicField = 'publicField'; | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return int | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __isset(string $name): int | ||
{ | ||
if ('test' === $name) { | ||
return 1; | ||
} | ||
|
||
if ('publicField' === $name || 'id' === $name) { | ||
throw new \BadMethodCallException('Should never be called for "publicField" or "id"'); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.