Skip to content

Commit

Permalink
Add PHP 74 version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin V / vvval committed Nov 11, 2019
1 parent cb615cd commit 9ec9141
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 25 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"autoload-dev": {
"psr-4": {
"Cycle\\ORM\\Promise\\Tests\\": "tests/Promise/",
"Cycle\\ORM\\Promise\\Tests74\\": "tests/php74/",
"Cycle\\ORM\\Promise\\Tests\\Promises\\": "tests/fixtures/promises/",
"": "tests/fixtures/withoutNamespace/"
}
Expand Down
9 changes: 6 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
>

<testsuites>
<testsuite name="Proxy Creator">
<directory>./tests/</directory>
<testsuite name="Proxy Factory">
<directory>./tests/Promise/</directory>
</testsuite>
<testsuite name="Proxy Factory 74">
<directory phpVersion="7.4.0-dev" phpVersionOperator="ge">./tests/php74/</directory>
</testsuite>
</testsuites>

Expand All @@ -23,4 +26,4 @@
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
13 changes: 12 additions & 1 deletion src/functions/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@

namespace Cycle\ORM\Promise;

/**
* @return bool
*/
function php74(): bool
{
return version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, '7.4.0', '>=');
return version_compare(phpVersion(), '7.4.0', '>=');
}

/**
* @return string
*/
function phpVersion(): string
{
return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
}
21 changes: 6 additions & 15 deletions tests/Promise/ProxyPrinter/ConstantsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Cycle\ORM\Promise\Declaration\Declarations;
use Cycle\ORM\Promise\Printer;

use function Cycle\ORM\Promise\php74;

class ConstantsTest extends BaseProxyPrinterTest
{
/**
Expand All @@ -25,7 +23,7 @@ class ConstantsTest extends BaseProxyPrinterTest
*/
public function testConstValues(): void
{
$classname = Fixtures\EntityWithoutConstConflicts::class;
$classname = Fixtures\EntityWithProperties::class;
$as = self::NS . __CLASS__ . __LINE__;
$reflection = new \ReflectionClass($classname);

Expand All @@ -36,21 +34,14 @@ public function testConstValues(): void
$output = ltrim($output, '<?php');

$this->assertStringContainsString(
'PUBLIC_PROPERTIES = [\'publicProperty\', \'publicPropertyWithDefaults\'];',
"PUBLIC_PROPERTIES = ['publicProperty', 'publicPropertyWithDefaults'];",
$output
);

if (php74()) {
$this->assertStringContainsString(
'UNSET_PROPERTIES = [\'publicPropertyWithDefaults\'];',
$output
);
} else {
$this->assertStringContainsString(
'UNSET_PROPERTIES = [\'publicProperty\', \'publicPropertyWithDefaults\'];',
$output
);
}
$this->assertStringContainsString(
"UNSET_PROPERTIES = ['publicProperty', 'publicPropertyWithDefaults'];",
$output
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/Promise/ProxyPrinter/Fixtures/EntityWithProperties.php
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\Tests\ProxyPrinter\Fixtures;

class EntityWithProperties
{
public $publicProperty;
public $publicPropertyWithDefaults = 'defaultPublicValue';
protected $protectedProperty;
protected $protectedPropertyWithDefaults = 'defaultProtectedValue';
}
21 changes: 21 additions & 0 deletions tests/Promise/ProxyPrinter/Fixtures/EntityWithProperties74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* Spiral Framework. Cycle ProxyFactory
*
* @license MIT
* @author Valentin V (Vvval)
*/

declare(strict_types=1);

namespace Cycle\ORM\Promise\Tests\ProxyPrinter\Fixtures;

class EntityWithProperties74
{
public $publicProperty;
public string $publicTypedProperty;
public $publicPropertyWithDefaults = 'defaultPublicValue';
protected $protectedProperty;
protected $protectedPropertyWithDefaults = 'defaultProtectedValue';
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ class EntityWithoutConstConflicts
public const PUBLIC_CONST = 1;
protected const PROTECTED_CONST = 2;
private const PRIVATE_CONST = 3;

public $publicProperty;
public $publicPropertyWithDefaults = 'defaultPublicValue';
protected $protectedProperty;
protected $protectedPropertyWithDefaults = 'defaultProtectedValue';
}
3 changes: 2 additions & 1 deletion tests/fixtures/promises/FileTestThree.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php
namespace Cycle\ORM\Promise\Tests\Promises; class FileTestThree {}
// phpcs:ignoreFile
namespace Cycle\ORM\Promise\Tests\Promises; class FileTestThree {}
91 changes: 91 additions & 0 deletions tests/php74/ConstantsPHP74Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/**
* Spiral Framework. Cycle ProxyFactory
*
* @license MIT
* @author Valentin V (Vvval)
*/

declare(strict_types=1);

namespace Cycle\ORM\Promise\Tests74;

use Cycle\ORM\Promise\Declaration\DeclarationInterface;
use Cycle\ORM\Promise\Declaration\Declarations;
use Cycle\ORM\Promise\Printer;
use PhpParser\PrettyPrinter\Standard;
use PhpParser\PrettyPrinterAbstract;
use PHPUnit\Framework\TestCase;
use Spiral\Core\Container;

class ConstantsPHP74Test extends TestCase
{
protected const NS = 'Cycle\ORM\Promise\Tests74\Promises';

/** @var \Spiral\Core\Container */
protected $container;

/**
* @throws \Cycle\ORM\Promise\Exception\ProxyFactoryException
* @throws \ReflectionException
* @throws \Throwable
*/
public function testConstValues(): void
{
$classname = Fixtures\EntityWithProperties74::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 = ['publicProperty', 'publicTypedProperty', 'publicPropertyWithDefaults'];",
$output
);

$this->assertStringContainsString(
"UNSET_PROPERTIES = ['publicProperty', 'publicPropertyWithDefaults'];",
$output
);
}

public function setUp(): void
{
parent::setUp();

$this->container = new Container();
}

/**
* @param \ReflectionClass $reflection
* @param DeclarationInterface $class
* @param DeclarationInterface $parent
* @return string
* @throws \Cycle\ORM\Promise\Exception\ProxyFactoryException
* @throws \ReflectionException
* @throws \Throwable
*/
protected function make(
\ReflectionClass $reflection,
DeclarationInterface $class,
DeclarationInterface $parent
): string {
return $this->proxyCreator()->make($reflection, $class, $parent);
}

/**
* @return \Cycle\ORM\Promise\Printer
* @throws \Throwable
*/
private function proxyCreator(): Printer
{
$this->container->bind(PrettyPrinterAbstract::class, Standard::class);

return $this->container->get(Printer::class);
}
}
21 changes: 21 additions & 0 deletions tests/php74/Fixtures/EntityWithProperties74.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* Spiral Framework. Cycle ProxyFactory
*
* @license MIT
* @author Valentin V (Vvval)
*/

declare(strict_types=1);

namespace Cycle\ORM\Promise\Tests74\Fixtures;

class EntityWithProperties74
{
public $publicProperty;
public string $publicTypedProperty;
public $publicPropertyWithDefaults = 'defaultPublicValue';
protected $protectedProperty;
protected $protectedPropertyWithDefaults = 'defaultProtectedValue';
}

0 comments on commit 9ec9141

Please sign in to comment.