Skip to content

Commit

Permalink
PHPUnit 10 Shift (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Mar 16, 2023
1 parent ac89359 commit f0eddb2
Show file tree
Hide file tree
Showing 38 changed files with 635 additions and 1,085 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ jobs:
run: composer require laravel/framework --no-update

- name: Run tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
with:
timeout_minutes: 5
max_attempts: 5
command: cd /home/runner/work/blueprint/laravel${{ matrix.laravel-version }}-example; pwd; vendor/bin/phpunit --verbose
command: cd /home/runner/work/blueprint/laravel${{ matrix.laravel-version }}-example; pwd; vendor/bin/phpunit

- name: Run artisan test
uses: nick-invision/retry@v1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor/
/build/
.env
.phpunit.result.cache
/.phpunit.cache
composer.lock
1 change: 1 addition & 0 deletions .phpunit.result.cache

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "laravel-shift/blueprint",
"type": "library",
"description": "An expressive, human readable code generation tool.",
"keywords": ["framework", "laravel", "code generation"],
"keywords": [
"framework",
"laravel",
"code generation"
],
"license": "MIT",
"require": {
"doctrine/dbal": "^3.3",
Expand All @@ -16,7 +20,7 @@
"laravel/pint": "^1.2",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.5.10"
"phpunit/phpunit": "^10.0"
},
"suggest": {
"jasonmccreary/laravel-test-assertions": "Required to use additional assertions in generated tests (^1.0)."
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<coverage processUncoveredFiles="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
Expand Down
135 changes: 47 additions & 88 deletions tests/Feature/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use Blueprint\Contracts\Generator;
use Blueprint\Contracts\Lexer;
use Blueprint\Tree;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Component\Yaml\Exception\ParseException;
use Tests\TestCase;

/**
* @see Blueprint
*/
class BlueprintTest extends TestCase
final class BlueprintTest extends TestCase
{
/**
* @var Blueprint
Expand All @@ -26,10 +28,8 @@ protected function setUp(): void
$this->subject = new Blueprint();
}

/**
* @test
*/
public function it_parses_models()
#[Test]
public function it_parses_models(): void
{
$blueprint = $this->fixture('drafts/models-only.yaml');

Expand Down Expand Up @@ -68,10 +68,8 @@ public function it_parses_seeders()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_controllers()
#[Test]
public function it_parses_controllers(): void
{
$blueprint = $this->fixture('drafts/controllers-only.yaml');

Expand All @@ -95,10 +93,8 @@ public function it_parses_controllers()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_shorthands()
#[Test]
public function it_parses_shorthands(): void
{
$blueprint = $this->fixture('drafts/shorthands.yaml');

Expand All @@ -121,10 +117,8 @@ public function it_parses_shorthands()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_uuid_shorthand()
#[Test]
public function it_parses_uuid_shorthand(): void
{
$blueprint = $this->fixture('drafts/uuid-shorthand.yaml');

Expand All @@ -139,10 +133,8 @@ public function it_parses_uuid_shorthand()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_shorthands_with_timezones()
#[Test]
public function it_parses_shorthands_with_timezones(): void
{
$blueprint = $this->fixture('drafts/with-timezones.yaml');

Expand All @@ -156,10 +148,8 @@ public function it_parses_shorthands_with_timezones()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_longhands()
#[Test]
public function it_parses_longhands(): void
{
$blueprint = $this->fixture('drafts/longhands.yaml');

Expand All @@ -183,10 +173,8 @@ public function it_parses_longhands()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_resource_shorthands()
#[Test]
public function it_parses_resource_shorthands(): void
{
$blueprint = $this->fixture('drafts/with-timezones.yaml');

Expand All @@ -200,10 +188,8 @@ public function it_parses_resource_shorthands()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_the_readme_example()
#[Test]
public function it_parses_the_readme_example(): void
{
$blueprint = $this->fixture('drafts/readme-example.yaml');

Expand Down Expand Up @@ -236,10 +222,8 @@ public function it_parses_the_readme_example()
], $this->subject->parse($blueprint));
}

/**
* @test
*/
public function it_parses_the_readme_example_with_different_platform_eols()
#[Test]
public function it_parses_the_readme_example_with_different_platform_eols(): void
{
$definition = $this->fixture('drafts/readme-example.yaml');

Expand Down Expand Up @@ -282,10 +266,8 @@ public function it_parses_the_readme_example_with_different_platform_eols()
$this->assertEquals($expected, $this->subject->parse($definition_windows_eol));
}

/**
* @test
*/
public function it_parses_yaml_with_dashed_syntax()
#[Test]
public function it_parses_yaml_with_dashed_syntax(): void
{
$definition = $this->fixture('drafts/readme-example-dashes.yaml');

Expand Down Expand Up @@ -314,10 +296,8 @@ public function it_parses_yaml_with_dashed_syntax()
$this->assertEquals($expected, $this->subject->parse($definition));
}

/**
* @test
*/
public function it_allows_parsing_without_stripping_dashes()
#[Test]
public function it_allows_parsing_without_stripping_dashes(): void
{
$sequence = [
'numbers' => range(3, 11),
Expand All @@ -326,10 +306,8 @@ public function it_allows_parsing_without_stripping_dashes()
$this->assertEquals($sequence, $this->subject->parse($this->subject->dump($sequence), false));
}

/**
* @test
*/
public function it_throws_a_custom_error_when_parsing_fails()
#[Test]
public function it_throws_a_custom_error_when_parsing_fails(): void
{
$this->expectException(ParseException::class);

Expand All @@ -338,10 +316,8 @@ public function it_throws_a_custom_error_when_parsing_fails()
$this->subject->parse($blueprint);
}

/**
* @test
*/
public function analyze_return_default_tree_for_empty_tokens()
#[Test]
public function analyze_return_default_tree_for_empty_tokens(): void
{
$tokens = [];

Expand All @@ -354,10 +330,8 @@ public function analyze_return_default_tree_for_empty_tokens()
);
}

/**
* @test
*/
public function analyze_uses_register_lexers_to_analyze_tokens()
#[Test]
public function analyze_uses_register_lexers_to_analyze_tokens(): void
{
$lexer = \Mockery::mock(Lexer::class);
$tokens = ['tokens' => ['are', 'here']];
Expand All @@ -374,10 +348,8 @@ public function analyze_uses_register_lexers_to_analyze_tokens()
], $this->subject->analyze($tokens)->toArray());
}

/**
* @test
*/
public function generate_uses_registered_generators_and_returns_generated_files()
#[Test]
public function generate_uses_registered_generators_and_returns_generated_files(): void
{
$generatorOne = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -421,10 +393,8 @@ public function generate_uses_registered_generators_and_returns_generated_files(
], $this->subject->generate($tree));
}

/**
* @test
*/
public function generate_uses_swapped_generator_and_returns_generated_files()
#[Test]
public function generate_uses_swapped_generator_and_returns_generated_files(): void
{
$generatorOne = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -456,10 +426,8 @@ public function generate_uses_swapped_generator_and_returns_generated_files()
], $this->subject->generate($tree));
}

/**
* @test
*/
public function generate_only_one_specific_type()
#[Test]
public function generate_only_one_specific_type(): void
{
$generatorFoo = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -507,10 +475,8 @@ public function generate_only_one_specific_type()
], $actual);
}

/**
* @test
*/
public function generate_only_specific_types()
#[Test]
public function generate_only_specific_types(): void
{
$generatorFoo = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -558,10 +524,8 @@ public function generate_only_specific_types()
], $actual);
}

/**
* @test
*/
public function generate_should_skip_one_specific_type()
#[Test]
public function generate_should_skip_one_specific_type(): void
{
$generatorFoo = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -609,10 +573,8 @@ public function generate_should_skip_one_specific_type()
], $actual);
}

/**
* @test
*/
public function generate_should_skip_specific_types()
#[Test]
public function generate_should_skip_specific_types(): void
{
$generatorFoo = \Mockery::mock(Generator::class);
$tree = new Tree(['branch' => ['code', 'attributes']]);
Expand Down Expand Up @@ -660,19 +622,16 @@ public function generate_should_skip_specific_types()
], $actual);
}

/**
* @test
*
* @dataProvider namespacesDataProvider
*/
public function relative_namespace_removes_namespace_prefix_from_reference($namespace, $expected, $reference)
#[Test]
#[DataProvider('namespacesDataProvider')]
public function relative_namespace_removes_namespace_prefix_from_reference($namespace, $expected, $reference): void
{
config(['blueprint.namespace' => $namespace]);

$this->assertEquals($expected, Blueprint::relativeNamespace($reference));
}

public function namespacesDataProvider()
public static function namespacesDataProvider(): array
{
return [
['App', 'Models\User', 'App\Models\User'],
Expand Down
Loading

0 comments on commit f0eddb2

Please sign in to comment.