-
Notifications
You must be signed in to change notification settings - Fork 5
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 #16 from cycle/php8.0
Php8.0
- Loading branch information
Showing
11 changed files
with
251 additions
and
9 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
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
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,92 @@ | ||
<?php | ||
|
||
/** | ||
* Spiral Framework. Cycle ProxyFactory | ||
* | ||
* @license MIT | ||
* @author Valentin V (Vvval) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Promise\Tests80; | ||
|
||
use Cycle\ORM\Promise\Declaration\DeclarationInterface; | ||
use Cycle\ORM\Promise\Declaration\Declarations; | ||
use Cycle\ORM\Promise\Exception\ProxyFactoryException; | ||
use Cycle\ORM\Promise\Printer; | ||
use PhpParser\PrettyPrinter\Standard; | ||
use PhpParser\PrettyPrinterAbstract; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
use Spiral\Core\Container; | ||
use Throwable; | ||
|
||
use function Cycle\ORM\Promise\phpVersionBetween; | ||
|
||
class ConstantsPHP80Test extends TestCase | ||
{ | ||
protected const NS = 'Cycle\ORM\Promise\Tests80\Promises'; | ||
|
||
/** @var Container */ | ||
protected $container; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->container = new Container(); | ||
} | ||
|
||
/** | ||
* @throws ProxyFactoryException | ||
* @throws ReflectionException | ||
* @throws Throwable | ||
*/ | ||
public function testConstValues(): void | ||
{ | ||
$classname = Fixtures\EntityWithUnionTypes::class; | ||
$as = self::NS . __CLASS__ . __LINE__; | ||
$reflection = new ReflectionClass($classname); | ||
|
||
$parent = Declarations::createParentFromReflection($reflection); | ||
$class = Declarations::createClassFromName($as, $parent); | ||
|
||
$output = $this->make($reflection, $class, $parent); | ||
$output = ltrim($output, '<?php'); | ||
|
||
$this->assertStringContainsString( | ||
"PUBLIC_PROPERTIES = ['throwable'];", | ||
$output | ||
); | ||
} | ||
|
||
/** | ||
* @param ReflectionClass $reflection | ||
* @param DeclarationInterface $class | ||
* @param DeclarationInterface $parent | ||
* @return string | ||
* @throws ProxyFactoryException | ||
* @throws ReflectionException | ||
* @throws Throwable | ||
*/ | ||
protected function make( | ||
ReflectionClass $reflection, | ||
DeclarationInterface $class, | ||
DeclarationInterface $parent | ||
): string { | ||
return $this->proxyCreator()->make($reflection, $class, $parent); | ||
} | ||
|
||
/** | ||
* @return Printer | ||
* @throws Throwable | ||
*/ | ||
private function proxyCreator(): Printer | ||
{ | ||
$this->container->bind(PrettyPrinterAbstract::class, Standard::class); | ||
|
||
return $this->container->get(Printer::class); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/** | ||
* Spiral Framework. Cycle ProxyFactory | ||
* | ||
* @license MIT | ||
* @author Valentin V (Vvval) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Promise\Tests80\Fixtures; | ||
|
||
class EntityWithMixedArg | ||
{ | ||
public function method(mixed $arg): mixed | ||
{ | ||
return $arg; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/** | ||
* Spiral Framework. Cycle ProxyFactory | ||
* | ||
* @license MIT | ||
* @author Valentin V (Vvval) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Promise\Tests80\Fixtures; | ||
|
||
class EntityWithUnionTypes | ||
{ | ||
public \Exception | \Error $throwable; | ||
|
||
public function method(\Exception | \Error $arg): \Exception | \Error | ||
{ | ||
return $arg; | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Promise\Tests80; | ||
|
||
use Cycle\ORM\Promise\Declaration\Declarations; | ||
use Cycle\ORM\Promise\Exception\ProxyFactoryException; | ||
use Cycle\ORM\Promise\Tests\ProxyPrinter\BaseProxyPrinterTest; | ||
use Cycle\ORM\Promise\Tests80\Fixtures; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
use Throwable; | ||
|
||
class MethodsPHP80Test extends BaseProxyPrinterTest | ||
{ | ||
/** | ||
* @throws ProxyFactoryException | ||
* @throws ReflectionException | ||
* @throws Throwable | ||
*/ | ||
public function testUnionTypes(): void | ||
{ | ||
$output = $this->makeOutput(Fixtures\EntityWithUnionTypes::class, self::NS . __CLASS__ . __LINE__); | ||
|
||
$this->assertStringContainsString( | ||
'public function method(\Exception|\Error $arg): \Exception|\Error', | ||
$output | ||
); | ||
} | ||
|
||
/** | ||
* @throws ReflectionException | ||
* @throws ProxyFactoryException | ||
* @throws Throwable | ||
*/ | ||
public function testNullableMixedArg(): void | ||
{ | ||
$output = $this->makeOutput(Fixtures\EntityWithMixedArg::class, self::NS . __CLASS__ . __LINE__); | ||
|
||
$this->assertStringContainsString( | ||
'public function method(mixed $arg): mixed', | ||
$output | ||
); | ||
} | ||
|
||
/** | ||
* @param string $classname | ||
* @param string $as | ||
* @return string | ||
* @throws ReflectionException | ||
* @throws ProxyFactoryException | ||
* @throws Throwable | ||
*/ | ||
private function makeOutput(string $classname, string $as): string | ||
{ | ||
$reflection = new ReflectionClass($classname); | ||
|
||
$parent = Declarations::createParentFromReflection($reflection); | ||
$class = Declarations::createClassFromName($as, $parent); | ||
|
||
$output = $this->make($reflection, $class, $parent); | ||
$output = ltrim($output, '<?php'); | ||
$output = str_replace(') : ', '): ', $output); | ||
|
||
$this->assertFalse(class_exists($class->getFullName())); | ||
|
||
eval($output); | ||
|
||
return $output; | ||
} | ||
} |