Skip to content

Commit

Permalink
chore :clean up development setup (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Mar 3, 2023
1 parent 958b95d commit 234c88a
Show file tree
Hide file tree
Showing 103 changed files with 50 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ jobs:
- name: "Execute unit tests"
run: "composer run-script test:unit"

- name: "Run Larastan on Laravel sample applications"
- name: "Run Larastan on a sample Laravel application"
run: "tests/laravel-test.sh ${{ matrix.laravel }}"
13 changes: 3 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ Please review these guidelines before submitting any pull requests.

## Guidelines

* Please follow the [PSR-2 Coding Style Guide](http://www.php-fig.org/psr/psr-2/), enforced by [StyleCI](https://styleci.io/).
* Please follow the [PSR-2 Coding Style Guide](http://www.php-fig.org/psr/psr-2), enforced by [StyleCI](https://styleci.io).
* Send a coherent commit history, making sure each individual commit in your pull request is meaningful.
* You may need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts.
* Please remember that we follow [SemVer](http://semver.org/).

We have [StyleCI](https://styleci.io/) setup to automatically fix any code style issues.
* Please remember that we follow [SemVer](http://semver.org).

## Setup

Clone your fork, then install the dev dependencies:
Clone your fork, then install all dependencies:

composer update

Expand All @@ -38,8 +36,3 @@ Code analysis:
Unit tests:

composer test:unit

Our current testsuite involves running `phpstan` on each individual file in [`tests/Features`](tests/Features)
with our extension file loaded. The test will fail if PHPStan fails on the given file.
There is currently no way for us to assert that larastan will fail for a given test suite,
so it is difficult to test for expected failures in analysis.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
},
"require-dev": {
"nikic/php-parser": "^4.15.2",
"orchestra/testbench": "^7.19.0|^8.0.0",
"orchestra/testbench": "^7.19.0 || ^8.0.0",
"phpunit/phpunit": "^9.5.27"
},
"suggest": {
"orchestra/testbench": "Using Larastan for analysing a package needs Testbench"
},
"autoload-dev": {
"psr-4": {
"App\\": "tests/Application/app/",
"Database\\Factories\\": "tests/Application/database/factories/",
"Database\\Migrations\\": "tests/Application/database/migrations/"
"App\\": "tests/application/app/",
"Database\\Factories\\": "tests/application/database/factories/",
"Database\\Migrations\\": "tests/application/database/migrations/"
},
"classmap": [
"tests/"
Expand Down
8 changes: 4 additions & 4 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$filesystem = new \Illuminate\Filesystem\Filesystem();

$filesystem->copyDirectory(__DIR__.'/tests/Application/database/migrations', __DIR__.'/vendor/orchestra/testbench-core/laravel/database/migrations');
$filesystem->copyDirectory(__DIR__.'/tests/Application/database/schema', __DIR__.'/vendor/orchestra/testbench-core/laravel/database/schema');
$filesystem->copyDirectory(__DIR__.'/tests/Application/config', __DIR__.'/vendor/orchestra/testbench-core/laravel/config');
$filesystem->copyDirectory(__DIR__.'/tests/Application/resources', __DIR__.'/vendor/orchestra/testbench-core/laravel/resources');
$filesystem->copyDirectory(__DIR__.'/tests/application/database/migrations', __DIR__.'/vendor/orchestra/testbench-core/laravel/database/migrations');
$filesystem->copyDirectory(__DIR__.'/tests/application/database/schema', __DIR__.'/vendor/orchestra/testbench-core/laravel/database/schema');
$filesystem->copyDirectory(__DIR__.'/tests/application/config', __DIR__.'/vendor/orchestra/testbench-core/laravel/config');
$filesystem->copyDirectory(__DIR__.'/tests/application/resources', __DIR__.'/vendor/orchestra/testbench-core/laravel/resources');
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Tests\Integration;

use PHPStan\Analyser\Analyser;
use PHPStan\Analyser\Error;
use PHPStan\File\FileHelper;
Expand All @@ -12,9 +14,9 @@ class IntegrationTest extends PHPStanTestCase
*/
public function dataIntegrationTests(): iterable
{
yield [__DIR__.'/integration/data/test-case-extension.php'];
yield [__DIR__.'/integration/data/model-properties.php'];
yield [__DIR__.'/integration/data/blade-view.php'];
yield [__DIR__.'/data/test-case-extension.php'];
yield [__DIR__.'/data/model-properties.php'];
yield [__DIR__.'/data/blade-view.php'];
}

/**
Expand Down Expand Up @@ -59,6 +61,6 @@ private function runAnalyse(string $file, ?array $allAnalysedFiles = null): arra

public static function getAdditionalConfigFiles(): array
{
return [__DIR__.'/phpstan-tests.neon'];
return [__DIR__.'/../phpstan-tests.neon'];
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

namespace BladeViewString;

class BladeViewType
{
public function testBladeView(): void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

namespace ModelPropertiesIntegration;

use App\Group;
use App\Role;
use App\Team;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

namespace TestCase;

use App\User;
use Illuminate\Foundation\Application;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testJobDispatch(): void
{
$this->dispatchableClass = Dispatchable::class;

$this->analyse([__DIR__.'/Data/job-dispatch.php'], [
$this->analyse([__DIR__.'/data/job-dispatch.php'], [
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatch(), 2 required.', 5],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatchSync(), 2 required.', 6],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatchNow(), 2 required.', 7],
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testEventDispatch(): void
{
$this->dispatchableClass = EventDispatchable::class;

$this->analyse([__DIR__.'/Data/event-dispatch.php'], [
$this->analyse([__DIR__.'/data/event-dispatch.php'], [
['Event class Tests\Rules\Data\LaravelEvent constructor invoked with 0 parameters in Tests\Rules\Data\LaravelEvent::dispatch(), 2 required.', 5],
['Event class Tests\Rules\Data\LaravelEvent constructor invoked with 1 parameter in Tests\Rules\Data\LaravelEvent::dispatch(), 2 required.', 7],
['Parameter #1 $foo of event class Tests\Rules\Data\LaravelEvent constructor expects string in Tests\Rules\Data\LaravelEvent::dispatch(), int given.', 8],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testNoFalsePositivesDirectExistingMethod(): void
{
$this->analyse(
[
__DIR__.'/Data/CorrectDeferrableProvider.php',
__DIR__.'/data/CorrectDeferrableProvider.php',
],
[]
);
Expand All @@ -25,7 +25,7 @@ public function testNoFalsePositivesIndirectExistingMethod(): void
{
$this->analyse(
[
__DIR__.'/Data/CorrectDeferrableProviderIndirect.php',
__DIR__.'/data/CorrectDeferrableProviderIndirect.php',
],
[]
);
Expand All @@ -35,7 +35,7 @@ public function testIncorrectDeferrableServiceProvider(): void
{
$this->analyse(
[
__DIR__.'/Data/IncorrectDeferrableProvider.php',
__DIR__.'/data/IncorrectDeferrableProvider.php',
],
[
['ServiceProviders that implement the "DeferrableProvider" interface should implement the "provides" method that returns an array of strings or class-strings', 10],
Expand Down
10 changes: 5 additions & 5 deletions tests/Rules/ModelPropertyRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getRule(): Rule

public function testModelPropertyRuleOnBuilder(): void
{
$this->analyse([__DIR__.'/Data/model-property-builder.php'], [
$this->analyse([__DIR__.'/data/model-property-builder.php'], [
[
'Property \'foo\' does not exist in App\\User model.',
4,
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testModelPropertyRuleOnBuilder(): void

public function testModelPropertyRuleOnRelation(): void
{
$this->analyse([__DIR__.'/Data/model-property-relation.php'], [
$this->analyse([__DIR__.'/data/model-property-relation.php'], [
[
'Property \'foo\' does not exist in App\\Account model.',
4,
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testModelPropertyRuleOnRelation(): void

public function testModelPropertyRuleOnModel(): void
{
$this->analyse([__DIR__.'/Data/model-property-model.php'], [
$this->analyse([__DIR__.'/data/model-property-model.php'], [
[
'Property \'foo\' does not exist in ModelPropertyModel\ModelPropertyOnModel model.',
9,
Expand All @@ -119,7 +119,7 @@ public function testModelPropertyRuleOnModel(): void

public function testModelPropertyRuleOnModelFactory(): void
{
$this->analyse([__DIR__.'/Data/model-property-model-factory.php'], [
$this->analyse([__DIR__.'/data/model-property-model-factory.php'], [
[
'Property \'foo\' does not exist in App\\User model.',
7,
Expand All @@ -130,7 +130,7 @@ public function testModelPropertyRuleOnModelFactory(): void
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__.'/Data/modelPropertyConfig.neon',
__DIR__.'/data/modelPropertyConfig.neon',
];
}
}
6 changes: 3 additions & 3 deletions tests/Rules/ModelPropertyStaticCallRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getRule(): Rule

public function testModelPropertyRuleOnStaticCallsToModel(): void
{
$this->analyse([__DIR__.'/Data/model-property-static-call.php'], [
$this->analyse([__DIR__.'/data/model-property-static-call.php'], [
['Property \'foo\' does not exist in App\\User model.', 7],
['Property \'foo\' does not exist in App\\User model.', 13],
['Property \'foo\' does not exist in App\\User model.', 18],
Expand All @@ -33,7 +33,7 @@ public function testModelPropertyRuleOnStaticCallsToModel(): void

public function testModelPropertyRuleOnStaticCallsInClass(): void
{
$this->analyse([__DIR__.'/Data/ModelPropertyStaticCallsInClass.php'], [
$this->analyse([__DIR__.'/data/ModelPropertyStaticCallsInClass.php'], [
['Property \'foo\' does not exist in Tests\\Rules\\Data\\ModelPropertyStaticCallsInClass model.', 16],
['Property \'foo\' does not exist in Tests\\Rules\\Data\\ModelPropertyStaticCallsInClass model.', 24],
]);
Expand All @@ -42,7 +42,7 @@ public function testModelPropertyRuleOnStaticCallsInClass(): void
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__.'/Data/modelPropertyConfig.neon',
__DIR__.'/data/modelPropertyConfig.neon',
];
}
}
4 changes: 2 additions & 2 deletions tests/Rules/NoModelMakeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ protected function getRule(): Rule

public function testNoFalsePositives(): void
{
$this->analyse([__DIR__.'/Data/CorrectModelInstantiation.php'], []);
$this->analyse([__DIR__.'/data/CorrectModelInstantiation.php'], []);
}

public function testModelMake(): void
{
$this->analyse([__DIR__.'/Data/ModelMake.php'], [
$this->analyse([__DIR__.'/data/ModelMake.php'], [
["Called 'Model::make()' which performs unnecessary work, use 'new Model()'.", 13],
["Called 'Model::make()' which performs unnecessary work, use 'new Model()'.", 20],
]);
Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/NoUnnecessaryCollectionCallRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ protected function getRule(): Rule

public function testNoFalsePositives(): void
{
$this->analyse([__DIR__.'/Data/CorrectCollectionCalls.php'], []);
$this->analyse([__DIR__.'/data/CorrectCollectionCalls.php'], []);
}

public function testNoFalseNegativesEloquent(): void
{
$this->analyse([__DIR__.'/Data/UnnecessaryCollectionCallsEloquent.php'], [
$this->analyse([__DIR__.'/data/UnnecessaryCollectionCallsEloquent.php'], [
['Called \'pluck\' on Laravel collection, but could have been retrieved as a query.', 18],
['Called \'count\' on Laravel collection, but could have been retrieved as a query.', 23],
['Called \'pluck\' on Laravel collection, but could have been retrieved as a query.', 29],
Expand All @@ -46,7 +46,7 @@ public function testNoFalseNegativesEloquent(): void

public function testNoFalseNegativesQuery(): void
{
$this->analyse([__DIR__.'/Data/UnnecessaryCollectionCallsQuery.php'], [
$this->analyse([__DIR__.'/data/UnnecessaryCollectionCallsQuery.php'], [
['Called \'max\' on Laravel collection, but could have been retrieved as a query.', 15],
['Called \'isNotEmpty\' on Laravel collection, but could have been retrieved as a query.', 20],
['Called \'pluck\' on Laravel collection, but could have been retrieved as a query.', 26],
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/OctaneCompatibilityRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function getRule(): Rule

public function testNoContainerInjection(): void
{
$this->analyse([__DIR__.'/Data/ContainerInjection.php'], [
$this->analyse([__DIR__.'/data/ContainerInjection.php'], [
['Consider using bind method instead or pass a closure.', 12, 'See: https://laravel.com/docs/octane#dependency-injection-and-octane'],
['Consider using bind method instead or pass a closure.', 16, 'See: https://laravel.com/docs/octane#dependency-injection-and-octane'],
['Consider using bind method instead or pass a closure.', 25, 'See: https://laravel.com/docs/octane#dependency-injection-and-octane'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/RelationExistenceRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function getRule(): Rule

public function testRule(): void
{
$this->analyse([__DIR__.'/Data/relation-existence-rule.php'], [
$this->analyse([__DIR__.'/data/relation-existence-rule.php'], [
[
'Relation \'foo\' is not found in App\User model.',
5,
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/UnusedViewsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UnusedViewsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$viewFileHelper = new ViewFileHelper([__DIR__.'/../Application/resources/views'], $this->getFileHelper());
$viewFileHelper = new ViewFileHelper([__DIR__.'/../application/resources/views'], $this->getFileHelper());

return new UnusedViewsRule(new UsedViewInAnotherViewCollector(
$this->getContainer()->getService('currentPhpVersionSimpleDirectParser'),
Expand Down Expand Up @@ -47,7 +47,7 @@ protected function setUp(): void

public function testRule(): void
{
$this->analyse([__DIR__.'/Data/FooController.php'], [
$this->analyse([__DIR__.'/data/FooController.php'], [
[
'This view is not used in the project.',
00,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testNoFalsePositives(): void
{
$this->analyse(
[
__DIR__.'/../Data/UselessConstructs/CorrectValueFunctionCall.php',
__DIR__.'/data/CorrectValueFunctionCall.php',
],
[]
);
Expand All @@ -25,7 +25,7 @@ public function testUselessWithCalls(): void
{
$this->analyse(
[
__DIR__.'/../Data/UselessConstructs/UselessValueFunctionCall.php',
__DIR__.'/data/UselessValueFunctionCall.php',
],
[
["Calling the helper function 'value()' without a closure as the first argument simply returns the first argument without doing anything", 11],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testNoFalsePositives(): void
{
$this->analyse(
[
__DIR__.'/../Data/UselessConstructs/CorrectWithFunctionCall.php',
__DIR__.'/data/CorrectWithFunctionCall.php',
],
[]
);
Expand All @@ -25,7 +25,7 @@ public function testUselessWithCalls(): void
{
$this->analyse(
[
__DIR__.'/../Data/UselessConstructs/UselessWithFunctionCall.php',
__DIR__.'/data/UselessWithFunctionCall.php',
],
[
["Calling the helper function 'with()' with only one argument simply returns the value itself. If you want to chain methods on a construct, use '(new ClassName())->foo()' instead", 11],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rules\Data\UselessConstructs;
namespace Rules\UselessConstructs\data;

class CorrectValueFunctionCall
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rules\Data\UselessConstructs;
namespace Rules\UselessConstructs\data;

class CorrectWithFunctionCall
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rules\Data\UselessConstructs;
namespace Rules\UselessConstructs\data;

class UselessValueFunctionCall
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Rules\Data\UselessConstructs;
namespace Rules\UselessConstructs\data;

class UselessWithFunctionCall
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Type/data/config-with-migrations.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ includes:
- ../../phpstan-tests.neon
parameters:
databaseMigrationsPath:
- %rootDir%/../../../tests/Application/database/migrations
- %rootDir%/../../../tests/application/database/migrations
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 234c88a

Please sign in to comment.