-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade to PHPStan 2.x * Add tests on FakerProviderReflectionExtension * Add Gitub Actions configuration
- Loading branch information
Showing
6 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
schedule: | ||
- cron: '0 1 * * *' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ '8.1', '8.2', '8.3' ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup PHP with tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
tools: composer | ||
- run: composer install | ||
- run: composer test | ||
|
||
format: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ '8.1' ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup PHP with tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
tools: composer | ||
- run: composer install | ||
- run: composer format | ||
|
||
analyse: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [ '8.1' ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup PHP with tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
tools: composer | ||
- run: composer install | ||
- run: composer analyse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Swis\PHPStan\Reflection\Tests; | ||
|
||
use Faker\Provider\Base; | ||
|
||
class BookProvider extends Base | ||
{ | ||
public function customBookIsbn(): string | ||
{ | ||
return $this->generator->ean13(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Swis\PHPStan\Reflection\Tests; | ||
|
||
use Faker; | ||
use PHPStan\Testing\PHPStanTestCase; | ||
use Swis\PHPStan\Reflection\FakerProviderReflectionExtension; | ||
|
||
class FakerProviderReflectionExtensionTest extends PHPStanTestCase | ||
{ | ||
public function testProviderCustomDataIsAvailableOnFakerGenerator(): void | ||
{ | ||
$faker = new Faker\Generator; | ||
$faker->addProvider(new BookProvider($faker)); | ||
|
||
$reflectionProvider = self::createReflectionProvider(); | ||
$sut = new FakerProviderReflectionExtension($reflectionProvider, [BookProvider::class]); | ||
|
||
$classReflection = $reflectionProvider->getClass(Faker\Generator::class); | ||
|
||
$this->assertTrue($sut->hasMethod($classReflection, 'customBookIsbn')); | ||
$this->assertTrue($sut->hasProperty($classReflection, 'customBookIsbn')); | ||
} | ||
|
||
public function testProviderCustomDataIsNotAvailabledOutsideOfFakerGenerator(): void | ||
{ | ||
$reflectionProvider = self::createReflectionProvider(); | ||
$sut = new FakerProviderReflectionExtension($reflectionProvider, [BookProvider::class]); | ||
|
||
$classReflection = $reflectionProvider->getClass(BookProvider::class); | ||
|
||
$this->assertFalse($sut->hasMethod($classReflection, 'customBookIsbn')); | ||
$this->assertFalse($sut->hasProperty($classReflection, 'customBookIsbn')); | ||
} | ||
} |