Skip to content

Commit

Permalink
Enhancement: Add support for PHP 7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jun 17, 2024
1 parent b928c57 commit 4cb0825
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a full diff see [`1.6.0...main`][1.6.0...main].

- Added support for PHP 8.0 ([#926]), by [@localheinz]
- Added support for PHP 7.4 ([#929]), by [@localheinz]
- Added support for PHP 7.3 ([#930]), by [@localheinz]

## [`1.6.0`][1.6.0]

Expand Down Expand Up @@ -187,6 +188,7 @@ For a full diff see [`0.4.0...0.5.0`][0.4.0...0.5.0].
[#795]: https://github.com/ergebnis/classy/pull/795
[#926]: https://github.com/ergebnis/classy/pull/926
[#929]: https://github.com/ergebnis/classy/pull/929
[#930]: https://github.com/ergebnis/classy/pull/930

[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
107 changes: 107 additions & 0 deletions test/DataProvider/Php73.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2017-2024 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\DataProvider;

use Ergebnis\Classy\Construct;
use Ergebnis\Classy\Test;

final class Php73
{
/**
* @return \Generator<string, array{0: Test\Util\Scenario}>
*/
public static function classyConstructs(): \Generator
{
$scenarios = [
Test\Util\Scenario::create(
'php73-within-namespace',
__DIR__ . '/../Fixture/Classy/Php73/WithinNamespace/source.php',
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespace\Bar::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespace\Baz::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespace\Foo::class),
),
Test\Util\Scenario::create(
'php73-within-namespace-with-braces',
__DIR__ . '/../Fixture/Classy/Php73/WithinNamespaceWithBraces/source.php',
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespaceWithBraces\Bar::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespaceWithBraces\Baz::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinNamespaceWithBraces\Foo::class),
),
Test\Util\Scenario::create(
'php73-within-multiple-namespaces-with-braces',
__DIR__ . '/../Fixture/Classy/Php73/WithinMultipleNamespaces/source.php',
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Bar\Bar::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Bar\Baz::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Bar\Foo::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Foo\Bar::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Foo\Baz::class),
Construct::fromName(Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Foo\Foo::class),
),
Test\Util\Scenario::create(
'php73-within-namespace-with-single-segment',
__DIR__ . '/../Fixture/Classy/Php73/WithinNamespaceWithSingleSegment/source.php',
Construct::fromName('Ergebnis\\Bar'),
Construct::fromName('Ergebnis\\Baz'),
Construct::fromName('Ergebnis\\Foo'),
),
Test\Util\Scenario::create(
'php73-with-methods-named-after-keywords',
__DIR__ . '/../Fixture/Classy/Php73/WithMethodsNamedAfterKeywords/source.php',
Construct::fromName(Test\Fixture\Classy\Php73\WithMethodsNamedAfterKeywords\Foo::class),
),
/**
* @see https://github.com/zendframework/zend-file/pull/41
*/
Test\Util\Scenario::create(
'php73-with-methods-named-after-keywords-and-return-type',
__DIR__ . '/../Fixture/Classy/Php73/WithMethodsNamedAfterKeywordsAndReturnType/source.php',
Construct::fromName(Test\Fixture\Classy\Php73\WithMethodsNamedAfterKeywordsAndReturnType\Foo::class),
),
Test\Util\Scenario::create(
'php73-without-namespace',
__DIR__ . '/../Fixture/Classy/Php73/WithoutNamespace/source.php',
Construct::fromName('Bar'),
Construct::fromName('Baz'),
Construct::fromName('Foo'),
),
Test\Util\Scenario::create(
'php73-without-namespace-and-multi-line-comments',
__DIR__ . '/../Fixture/Classy/Php73/WithoutNamespaceAndMultiLineComments/source.php',
Construct::fromName('Bar'),
Construct::fromName('Baz'),
Construct::fromName('Foo'),
),
Test\Util\Scenario::create(
'php73-without-namespace-and-shell-line-comments',
__DIR__ . '/../Fixture/Classy/Php73/WithoutNamespaceAndShellStyleComments/source.php',
Construct::fromName('Bar'),
Construct::fromName('Baz'),
Construct::fromName('Foo'),
),
Test\Util\Scenario::create(
'php73-without-namespace-and-single-line-comments',
__DIR__ . '/../Fixture/Classy/Php73/WithoutNamespaceAndSingleLineComments/source.php',
Construct::fromName('Bar'),
Construct::fromName('Baz'),
Construct::fromName('Foo'),
),
];

foreach ($scenarios as $scenario) {
yield $scenario->description() => [
$scenario,
];
}
}
}
18 changes: 18 additions & 0 deletions test/Fixture/Classy/Php73/WithMethodsNamedAfterKeywords/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithMethodsNamedAfterKeywords;

class Foo
{
public function class()
{
}

public function interface()
{
}

public function trait()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithMethodsNamedAfterKeywordsAndReturnType;


class Foo
{
public function class(): string
{
return '';
}

public function interface(): string
{
return '';
}

public function trait(): string
{
return '';
}
}
19 changes: 19 additions & 0 deletions test/Fixture/Classy/Php73/WithinMultipleNamespaces/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Foo;
{
class Foo {}

interface Bar {}

trait Baz {}
}

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinMultipleNamespaces\Bar;
{
class Foo {}

interface Bar {}

trait Baz {}
}
9 changes: 9 additions & 0 deletions test/Fixture/Classy/Php73/WithinNamespace/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinNamespace;

class Foo {}

interface Bar {}

trait Baz {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinNamespaceAndMultiLineComments;

/* foo */ class /* bar */ Foo /* baz */ {}

/* foo */ interface /* bar */ Bar /* baz */ {}

/* foo */ trait /* bar */ Baz /* baz */ {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinNamespaceAndShellStyleComments;

class # foo
Foo # bar
{}

interface # foo
Bar # bar
{}

trait # foo
Baz // bar
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinNamespaceAndSingleLineComments;

class // foo
Foo // bar
{}

interface // foo
Bar // bar
{}

trait // foo
Baz // bar
{}
10 changes: 10 additions & 0 deletions test/Fixture/Classy/Php73/WithinNamespaceWithBraces/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php73\WithinNamespaceWithBraces
{
class Foo {}

interface Bar {}

trait Baz {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Ergebnis;

class Foo {}

interface Bar {}

trait Baz {}
7 changes: 7 additions & 0 deletions test/Fixture/Classy/Php73/WithoutNamespace/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Foo {}

interface Bar {}

trait Baz {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

/* foo */ class /* bar */ Foo /* baz */ {}

/* foo */ interface /* bar */ Bar /* baz */ {}

/* foo */ trait /* bar */ Baz /* baz */ {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class # foo
Foo # bar
{}

interface # foo
Bar # bar
{}

trait # foo
Baz // bar
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class // foo
Foo // bar
{}

interface // foo
Bar // bar
{}

trait // foo
Baz // bar
{}
30 changes: 30 additions & 0 deletions test/Unit/ConstructsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ public static function provideScenarioWithoutClassyConstructs(): iterable
}
}

/**
* @dataProvider \Ergebnis\Classy\Test\DataProvider\Php73::classyConstructs()
*
* @requires PHP 7.3
*/
public function testFromSourceReturnsListOfClassyConstructsOnPhp73(Test\Util\Scenario $scenario): void
{
$constructs = Constructs::fromSource($scenario->source());

$expected = \array_map(static function (Construct $construct): Construct {
return Construct::fromName($construct->name());
}, $scenario->constructsSortedByName());

self::assertIsList($constructs);
self::assertEquals($expected, $constructs);
}

/**
* @dataProvider \Ergebnis\Classy\Test\DataProvider\Php74::classyConstructs()
*
Expand Down Expand Up @@ -178,6 +195,19 @@ public function testFromDirectoryReturnsEmptyArrayWhenNoClassyConstructsHaveBeen
self::assertSame([], $constructs);
}

/**
* @dataProvider \Ergebnis\Classy\Test\DataProvider\Php73::classyConstructs()
*
* @requires PHP 7.3
*/
public function testFromDirectoryReturnsListOfClassyConstructsOnPhp73(Test\Util\Scenario $scenario): void
{
$constructs = Constructs::fromDirectory($scenario->directory());

self::assertIsList($constructs);
self::assertEquals($scenario->constructsSortedByName(), $constructs);
}

/**
* @dataProvider \Ergebnis\Classy\Test\DataProvider\Php74::classyConstructs()
*
Expand Down

0 comments on commit 4cb0825

Please sign in to comment.