Skip to content

Commit

Permalink
Enhancement: Implement PhpVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 30, 2021
1 parent 061ca7f commit 9772e89
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/Unit/ConstructsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,37 @@ public function provideScenarioWithoutClassyConstructs(): \Generator
{
$scenariosWithoutClassyConstructs = [
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'no-php-file',
__DIR__ . '/../Fixture/NoClassy/NoPhpFile/source.md'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-anonymous-class',
__DIR__ . '/../Fixture/NoClassy/WithAnonymousClass/source.php'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-anonymous-class-and-multi-line-comments',
__DIR__ . '/../Fixture/NoClassy/WithAnonymousClassAndMultiLineComments/source.php'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-anonymous-class-and-shell-style-comments',
__DIR__ . '/../Fixture/NoClassy/WithAnonymousClassAndShellStyleComments/source.php'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-anonymous-class-and-single-line-comments',
__DIR__ . '/../Fixture/NoClassy/WithAnonymousClassAndSingleLineComments/source.php'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-class-keyword',
__DIR__ . '/../Fixture/NoClassy/WithClassKeyword/source.php'
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-nothing',
__DIR__ . '/../Fixture/NoClassy/WithNothing/source.php'
),
Expand Down Expand Up @@ -163,41 +170,47 @@ public function provideScenarioWithClassyConstructs(): \Generator
{
$scenariosWithClassyConstructs = [
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace',
__DIR__ . '/../Fixture/Classy/WithinNamespace/source.php',
Construct::fromName(Test\Fixture\Classy\WithinNamespace\Bar::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespace\Baz::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespace\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace-and-shell-style-comments',
__DIR__ . '/../Fixture/Classy/WithinNamespaceAndShellStyleComments/source.php',
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndShellStyleComments\Bar::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndShellStyleComments\Baz::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndShellStyleComments\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace-and-single-line-comments',
__DIR__ . '/../Fixture/Classy/WithinNamespaceAndSingleLineComments/source.php',
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndSingleLineComments\Bar::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndSingleLineComments\Baz::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndSingleLineComments\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace-and-multi-line-comments',
__DIR__ . '/../Fixture/Classy/WithinNamespaceAndMultiLineComments/source.php',
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndMultiLineComments\Bar::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndMultiLineComments\Baz::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceAndMultiLineComments\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace-with-braces',
__DIR__ . '/../Fixture/Classy/WithinNamespaceWithBraces/source.php',
Construct::fromName(Test\Fixture\Classy\WithinNamespaceWithBraces\Bar::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceWithBraces\Baz::class),
Construct::fromName(Test\Fixture\Classy\WithinNamespaceWithBraces\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-multiple-namespaces-with-braces',
__DIR__ . '/../Fixture/Classy/WithinMultipleNamespaces/source.php',
Construct::fromName(Test\Fixture\Classy\WithinMultipleNamespaces\Bar\Bar::class),
Expand All @@ -208,13 +221,15 @@ public function provideScenarioWithClassyConstructs(): \Generator
Construct::fromName(Test\Fixture\Classy\WithinMultipleNamespaces\Foo\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'within-namespace-with-single-segment',
__DIR__ . '/../Fixture/Classy/WithinNamespaceWithSingleSegment/source.php',
Construct::fromName('Ergebnis\\Bar'),
Construct::fromName('Ergebnis\\Baz'),
Construct::fromName('Ergebnis\\Foo')
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-methods-named-after-keywords',
__DIR__ . '/../Fixture/Classy/WithMethodsNamedAfterKeywords/source.php',
Construct::fromName(Test\Fixture\Classy\WithMethodsNamedAfterKeywords\Foo::class)
Expand All @@ -223,32 +238,37 @@ public function provideScenarioWithClassyConstructs(): \Generator
* @see https://github.com/zendframework/zend-file/pull/41
*/
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'with-methods-named-after-keywords-and-return-type',
__DIR__ . '/../Fixture/Classy/WithMethodsNamedAfterKeywordsAndReturnType/source.php',
Construct::fromName(Test\Fixture\Classy\WithMethodsNamedAfterKeywordsAndReturnType\Foo::class)
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'without-namespace',
__DIR__ . '/../Fixture/Classy/WithoutNamespace/source.php',
Construct::fromName('Bar'),
Construct::fromName('Baz'),
Construct::fromName('Foo')
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'without-namespace-and-multi-line-comments',
__DIR__ . '/../Fixture/Classy/WithoutNamespaceAndMultiLineComments/source.php',
Construct::fromName('Quux'),
Construct::fromName('Quuz'),
Construct::fromName('Qux')
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'without-namespace-and-shell-line-comments',
__DIR__ . '/../Fixture/Classy/WithoutNamespaceAndShellStyleComments/source.php',
Construct::fromName('Corge'),
Construct::fromName('Garply'),
Construct::fromName('Grault')
),
Test\Util\Scenario::create(
Test\Util\PhpVersion::fromInt(70200),
'without-namespace-and-single-line-comments',
__DIR__ . '/../Fixture/Classy/WithoutNamespaceAndSingleLineComments/source.php',
Construct::fromName('Fred'),
Expand Down
40 changes: 40 additions & 0 deletions test/Util/PhpVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2017-2021 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/classy
*/

namespace Ergebnis\Classy\Test\Util;

/**
* @psalm-immutable
*/
final class PhpVersion
{
/**
* @var int
*/
private $value;

private function __construct(int $value)
{
$this->value = $value;
}

public static function fromInt(int $value): self
{
return new self($value);
}

public function toInt(): int
{
return $this->value;
}
}
14 changes: 14 additions & 0 deletions test/Util/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
final class Scenario
{
/**
* @var PhpVersion
*/
private $phpVersion;

/**
* @var string
*/
Expand All @@ -41,11 +46,13 @@ final class Scenario
private $constructs;

private function __construct(
PhpVersion $phpVersion,
string $description,
string $fileName,
string $fileContent,
Classy\Construct ...$constructs
) {
$this->phpVersion = $phpVersion;
$this->description = $description;
$this->fileName = $fileName;
$this->fileContent = $fileContent;
Expand All @@ -56,6 +63,7 @@ private function __construct(
* @throws \InvalidArgumentException
*/
public static function create(
PhpVersion $phpVersion,
string $description,
string $fileName,
Classy\Construct ...$constructs
Expand Down Expand Up @@ -93,6 +101,7 @@ public static function create(
});

return new self(
$phpVersion,
$description,
$fileName,
$fileContent,
Expand All @@ -102,6 +111,11 @@ public static function create(
);
}

public function phpVersion(): PhpVersion
{
return $this->phpVersion;
}

public function description(): string
{
return $this->description;
Expand Down

0 comments on commit 9772e89

Please sign in to comment.