Skip to content

Commit 5884937

Browse files
authored
Merge up 1.1 (#22)
* Task/support php parser 5 (#20) * Support PHP-Parser 4.18 & 5 * Try testing both versions of php-parser * Support proper target branches * Add explicit test for #12 (#21)
1 parent 2606f82 commit 5884937

File tree

8 files changed

+92
-10
lines changed

8 files changed

+92
-10
lines changed

.github/workflows/php.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@ name: 'Unit Tests'
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ release-1.x ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ release-1.x ]
88

99
jobs:
1010
build-test:
11-
1211
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
composer: [lowest, highest]
1316

1417
steps:
1518
- name: Checkout
16-
uses: actions/checkout@v2
19+
uses: actions/checkout@v4
1720
- name: Setup PHP 8
1821
uses: shivammathur/setup-php@v2
1922
with:
2023
php-version: 8.1
21-
tools: composer:v2
24+
tools: none
2225
coverage: none
2326
- name: Composer Install
24-
run: composer update --no-interaction --no-progress --ansi
27+
uses: ramsey/composer-install@v2
28+
with:
29+
dependency-versions: ${{ matrix.composer }}
2530
- name: Unit Tests
2631
run: ./vendor/bin/pest --colors=always

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": "^8.1",
15-
"nikic/php-parser": "^v4.14",
15+
"nikic/php-parser": "^v4.18 || ^5.0",
1616
"cspray/typiphy": "^0.3"
1717
},
1818
"require-dev": {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Cspray\AnnotatedTargetFixture\AliasedAttribute;
4+
5+
use Cspray\AnnotatedTargetFixture\ClassOnly as MyAttributeName;
6+
7+
#[MyAttributeName('my aliased value')]
8+
class FooClass {
9+
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Cspray\AnnotatedTargetFixture;
4+
5+
use Cspray\Typiphy\ObjectType;
6+
use function Cspray\Typiphy\objectType;
7+
8+
final class AliasedAttributeFixture implements Fixture {
9+
10+
public function getPath() : string {
11+
return __DIR__ . '/AliasedAttribute';
12+
}
13+
14+
public function fooClass() : ObjectType {
15+
return objectType(AliasedAttribute\FooClass::class);
16+
}
17+
}

fixture_src/Fixtures.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ public static function targetAttributeInterface() : TargetAttributeInterfaceFixt
8989
public static function invalidSyntax() : BadPhpFileFixture {
9090
return new BadPhpFileFixture();
9191
}
92+
93+
public static function aliasedAttribute() : AliasedAttributeFixture {
94+
return new AliasedAttributeFixture();
95+
}
9296
}

src/PhpParserAnnotatedTargetParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class PhpParserAnnotatedTargetParser implements AnnotatedTargetParser {
2929
private readonly Parser $parser;
3030

3131
public function __construct() {
32-
$this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
32+
$this->parser = (new ParserFactory())->createForNewestSupportedVersion();
3333
}
3434

3535
public function parse(AnnotatedTargetParserOptions $options) : Generator {
@@ -39,7 +39,7 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator {
3939
$data = new \stdClass();
4040
$data->targets = [];
4141
$nodeTraverser->addVisitor($this->getVisitor(
42-
fn($target) => $data->targets[] = $target,
42+
static fn($target) => $data->targets[] = $target,
4343
$options->getAttributeTypes()
4444
));
4545

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Cspray\AnnotatedTarget\Unit;
4+
5+
use Cspray\AnnotatedTargetFixture\ClassOnly;
6+
use Cspray\AnnotatedTargetFixture\Fixtures;
7+
use function Cspray\Typiphy\objectType;
8+
9+
uses(AnnotatedTargetParserTestCase::class);
10+
11+
beforeEach()->withFixtures(Fixtures::aliasedAttribute());
12+
13+
it('counts parsed targets for single class')
14+
->expect(fn() => $this->getTargets())
15+
->toHaveCount(1);
16+
17+
it('ensures all targets are correct type')
18+
->expect(fn() => $this->getTargets())
19+
->toContainOnlyAnnotatedTargets();
20+
21+
it('ensures all targets share target reflection')
22+
->expect(fn() => $this->getTargets())
23+
->toShareTargetReflection();
24+
25+
it('ensures all targets share attribute reflection')
26+
->expect(fn() => $this->getTargets())
27+
->toShareAttributeReflection();
28+
29+
it('ensures all targets share attribute instance')
30+
->expect(fn() => $this->getTargets())
31+
->toShareAttributeInstance();
32+
33+
it('includes target reflection class')
34+
->expect(fn() => $this->getTargets())
35+
->toContainTargetClass(Fixtures::aliasedAttribute()->fooClass());
36+
37+
it('includes attribute reflection class')
38+
->expect(fn() => $this->getTargets())
39+
->toContainTargetClassWithAttribute(Fixtures::aliasedAttribute()->fooClass(), objectType(ClassOnly::class));
40+
41+
it('includes attribute instance with correct value')
42+
->expect(fn() => $this->getTargets())
43+
->toContainTargetClassWithAttributeInstance(
44+
Fixtures::aliasedAttribute()->fooClass(),
45+
objectType(ClassOnly::class),
46+
fn(ClassOnly $classOnly) => $classOnly->value === 'my aliased value'
47+
);

tests/Unit/ClassOnlyAttributeGroupTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Cspray\AnnotatedTargetFixture\ClassOnly;
66
use Cspray\AnnotatedTargetFixture\Fixtures;
7-
use Cspray\AnnotatedTargetFixture\ParameterOnly;
87
use Cspray\AnnotatedTargetFixture\RepeatableClassOnly;
98
use function Cspray\Typiphy\objectType;
109

0 commit comments

Comments
 (0)