Compare commits

...
27 Commits
Author SHA1 Message Date
Markus PodarandBarry vd. Heuvel affa55122f [TESTS] Running in CI should not create but rather fail on missing snapshots (#1039)
* tests: running in CI should not create but rather fail on missing snapshots

Otherwise they get created on the CI infrastructure but that's it, the
build won't fail although it was forgotten to add the snapshot.

* Bump minimum phpunit version which correctly accepts the `-d` parameter

The `prefer-lowest` version we get with L6 is 8.0.0 which throws this error:
```
PHP Fatal error:  Uncaught TypeError: ini_set() expects parameter 2 to be string, bool given in /home/runner/work/laravel-ide-helper/laravel-ide-helper/vendor/phpunit/phpunit/src/TextUI/Command.php:379
```

* Update composer.json

Co-authored-by: Barry vd. Heuvel <[email protected]>
2020-09-07 09:36:37 +02:00
Barry vd. HeuvelandMarkus Podar b7d84785b1 GHA Composer v2 (#968)
* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* Update run-tests.yml

* gha: no need for self-update, setup-php `composer:v2` already gives the version we want

Co-authored-by: Markus Podar <[email protected]>
2020-09-07 09:26:20 +02:00
Daniel Mendes 4df96b5e62 Change $this->app->environment() !== 'production' to $this->app->isLocal() (#886)
* README.md: $this->app->environment() !== 'production' to $this->app->isLocal()

* Renamed to README.md

* Remove unrelated changes
2020-09-06 07:58:51 +02:00
domkrmandDominik Krämer 3a22b8daf6 Add better support for macros and mixins (#1006)
Co-authored-by: Dominik Krämer <[email protected]>
2020-09-06 07:58:13 +02:00
edcorewebandMarkus Podar 24596b67f1 New --write-mixin option. (#764)
* New --write-mixin option.

* Keep all tags from the existing docblock.

* Update argument description to be more descriptive

Co-authored-by: Markus Podar <[email protected]>

* Add the new --write-mixin option to the docs

* Add test for the new --write-mixin option

* Update README.md

* composer fix-style

* Adapt test after refactoring recently done

Co-authored-by: Markus Podar <[email protected]>
2020-09-06 07:57:00 +02:00
Markus Podar d978986523 Remove GrumPHP (#1036)
* composer remove --dev phpro/grumphp

* Remove remains of grumphp
2020-09-04 19:05:00 +02:00
Markus Podar 3ea232dc3a Add initial changelog (#1035)
At least until 2.6.6; quite a chore ;)

The idea is to keep it updated; ideally each PR updates the changelog
otherwise we/I will keep track of the "notable" changes.

The goal would be that once the next release is about to happen, the
changes collected here so far can just be copy-pasted to the release
notes and the top link has to be bumped.

I would define "notable" as user-facing, thus many internal changes
(readme, test suite, etc.) have not been added to give end-users a
clearer focus what may have changed/improved _for them_.
2020-09-03 06:00:59 +02:00
Markus Podar 007d3adb68 Run composer fix-style and vendor/bin/phpunit -d --update-snapshots to solve failed build (#1032) 2020-09-01 19:50:05 +02:00
Markus PodarandBarry vd. Heuvel 764bc02b84 [CODESTYLE] Replace phpcs with php-cs-fixer (#1030)
* composer require --dev friendsofphp/php-cs-fixer:^2

* php-cs-fixer: ignore cache and custom local config file

* php-cs-fixer: initial config

* php-cs-fixer: replace commands in composer

* php-cs-fixer: add PSR12 "as good as it currently gets"

* php-cs-fixer: apply PSR12 to codebase

* tests: add workaround to keep unused imports for snapshot testing

* php-cs-fixer: apply no_unused_imports

* php-cs-fixer: apply array_syntax short

* php-cs-fixer: apply single_quote

* php-cs-fixer: switch ordered_imports sort_algorithm to alpha

Let's be opinionated here for consistency

* php-cs-fixer: split between non-tests and tests and share config

* php-cs-fixer: apply declare_strict_types for tests

* php-cs-fixer: apply fully_qualified_strict_types

* php-cs-fixer: apply space_after_semicolon

* php-cs-fixer: apply trailing_comma_in_multiline_array

* php-cs-fixer: apply trim_array_spaces

* php-cs-fixer: apply unary_operator_spaces

* php-cs-fixer: apply whitespace_after_comma_in_array

* php-cs-fixer: apply native_function_invocation

* php-cs-fixer: apply concat_space

* grumphp: reflect we're using phpcsfixer now

* composer remove --dev squizlabs/php_codesniffer

* gha: simplify fix-style approach

Not really necessary to remove packages and then manually prevent
unrelated commits creeping in

Co-authored-by: Barry vd. Heuvel <[email protected]>
2020-09-01 11:32:31 +02:00
edvordo a96add6981 update(config/model command): add option to force usage of FQN + tests (#1031) 2020-09-01 09:11:12 +02:00
Markus Podar 4a6d127440 Improve gitignore a bit (#1029)
- build isn't used AFAIK?
- add `/` prefix were we know they're only expected to be in the root anyway
  except `.phpunit.result.cache` which may appear anywhere it's run from
2020-08-31 20:33:07 +02:00
Markus Podar 1ca875fbca Make createLocalViewFactory compatible with Laravel 8 (#1026)
* Make createLocalViewFactory compatible with Laravel 8

Fixes https://github.com/barryvdh/laravel-ide-helper/issues/1024

* tests: move up mockFilesystem so it get be re-used in other tests

Note: removed `$this->mockOutput = '';` as it was a no-op, that property
doesn't exist (it was probably a typo, but I guess we don't need it
anyway)

* tests: show basic features for ide-helper:meta working
2020-08-31 06:20:02 +02:00
Markus Podar 462989abd5 Fix type for new meta command 🤷‍♀️ (#997) 2020-08-30 21:33:19 +02:00
Markus Podar bd5b6ecee7 Remove unused use vars (#1027) 2020-08-30 21:32:47 +02:00
Markus Podar 3b66fea925 tests: no need for < 6 check, as we don't test < L6 anymore (#1025) 2020-08-30 21:32:15 +02:00
Markus Podar 707ec990e7 tests: remove L5.5 workaround (#1023) 2020-08-29 08:12:11 +02:00
Barry vd. Heuvelandbarryvdh a49cb46fdf Bump Laravel versions (#1022)
* Bump Laravel versions

* Test Laravel 8

* Update composer.json

* Update composer.json

* normalize composer.json

* Tweak MethodTest for Laravel 8

Co-authored-by: barryvdh <[email protected]>
2020-08-28 22:26:05 +02:00
Barry vd. Heuvel a12f902b33 Avoid duplicate tests (#1021) 2020-08-28 16:12:41 +02:00
Danny van der Sluijs 8287f02afa Fix typos; Optimise if-else branches (#1009) 2020-08-28 09:15:43 +02:00
David 1d9e82f2b7 Update README.md (#1020) 2020-08-28 09:13:34 +02:00
Barry vd. Heuvel 9599cfbbc9 Simplify test by mocking filesystem always (#1019) 2020-08-25 17:43:39 +02:00
Barry vd. Heuvel c852650d7e Test dynamic relationships (#1017)
* Test dynamic

* Try/catch relationships

* Update snapshot

* Test output
2020-08-25 08:01:16 +02:00
Markus Podar ac6fbffac3 tests: ensure output mocking is disabled so we can actually catch the output (#1018)
Discovered via https://github.com/barryvdh/laravel-ide-helper/pull/1017#issuecomment-679318764

This only happens if you run an artisan command _before_ `runCommand`,
but since every of these tests performs migrations, using artisan,
the mocked output instance is left behind and also affected us.

The call added in `runCommand` explicitly unregisters
`\Illuminate\Console\OutputStyle` and thus also throwing away possibly
mocked versions.
2020-08-25 06:29:44 +02:00
Markus Podar 1ad23fd14c gha: use separate workflow file only on push for fixing the code style (#1013) 2020-08-21 06:49:24 +02:00
Markus Podar 444325205e getDoctrineSchemaManager doesn't take an argument (#1011)
AFAIK never had.

See https://github.com/laravel/framework/blob/c1ec18723e763120aa4e816072beca396d298db1/src/Illuminate/Database/Connection.php#L892
2020-08-20 21:58:36 +02:00
Markus Podar c760c9aa0c readme: be clear that models require FQN (#1012)
I've tested this and yes, it *always* requires a FQN.

Therefore I removed the extra note regarding namespace/wrapping because
even by default Laravel has the `App\` namesapce, which requires this.

Fixes https://github.com/barryvdh/laravel-ide-helper/issues/995
2020-08-20 21:57:11 +02:00
Danny van der Sluijs ce4186c1c7 Migrate PHPUnit configuration (#1010) 2020-08-19 21:45:21 +02:00
72 changed files with 1556 additions and 1087 deletions
+34
View File
@@ -0,0 +1,34 @@
name: Fix Code Style
on:
push:
jobs:
fix-style:
name: Fix Code Style
timeout-minutes: 15
runs-on: ubuntu-latest
env:
COMPOSER_NO_INTERACTION: 1
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer:v2
- name: Install dependencies
run: composer update --prefer-dist --no-progress
- run: composer fix-style
continue-on-error: true
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: composer fix-style
commit_author: laravel-ide-helper <[email protected]>
+16 -41
View File
@@ -1,6 +1,14 @@
name: Tests
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- "*"
schedule:
- cron: '0 0 * * *'
jobs:
php-tests:
@@ -12,11 +20,11 @@ jobs:
strategy:
matrix:
php: [7.4, 7.3, 7.2]
laravel: [7.*, 6.*, 5.5.*]
laravel: [8.*, 7.*, 6.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: 5.5.*
php: 7.4
- laravel: 8.*
php: 7.2
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
@@ -29,46 +37,13 @@ jobs:
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2
- name: Install dependencies
run: |
composer remove phpro/grumphp vimeo/psalm --no-update --dev
composer remove vimeo/psalm --no-update --dev
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
composer update --${{ matrix.dependency-version }} --prefer-dist --no-suggest --no-progress
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
- name: Execute Unit Tests
run: composer test
fix-style:
name: Fix Code Style
timeout-minutes: 15
runs-on: ubuntu-latest
env:
COMPOSER_NO_INTERACTION: 1
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer:v2
- name: Install dependencies
run: |
composer remove phpro/grumphp vimeo/psalm --no-update --dev
composer update --prefer-dist --no-suggest --no-progress
- run: composer fix-style
continue-on-error: true
# Revert modifications so they don't get commited 💥
- run: git checkout -- composer.json
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: composer fix-style
commit_author: laravel-ide-helper <[email protected]>
run: composer test-ci
+7 -4
View File
@@ -1,5 +1,8 @@
build
vendor
composer.lock
.idea
.phpunit.result.cache
/.idea
/.php_cs
/.php_cs.cache
/.php_cs.tests.cache
/composer.lock
/vendor
+65
View File
@@ -0,0 +1,65 @@
<?php
// Share common rules between non-test and test files
return [
// PSR12 from https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4943
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'braces' => [
// Not-yet-implemented
// 'allow_single_line_anonymous_class_with_empty_body' => true,
],
'compact_nullable_typehint' => true,
'declare_equal_normalize' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'new_with_braces' => true,
'no_blank_lines_after_class_opening' => true,
'no_leading_import_slash' => true,
'no_whitespace_in_blank_line' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
// Further quality-of-life improvements
'array_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'fully_qualified_strict_types' => true,
'native_function_invocation' => [
'include' => [],
'strict' => true,
],
'no_unused_imports' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
];
+14
View File
@@ -0,0 +1,14 @@
<?php
require __DIR__ . '/vendor/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('tests');
$config = require __DIR__ . '/.php_cs.common.php';
return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.cache');
+22
View File
@@ -0,0 +1,22 @@
<?php
require __DIR__ . '/vendor/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/tests')
->exclude('__snapshots__');
$config = require __DIR__ . '/.php_cs.common.php';
// Additional rules for tests
$config = array_merge(
$config,
[
'declare_strict_types' => true,
]
);
return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.tests.cache');
+60
View File
@@ -0,0 +1,60 @@
# Changelog
All notable changes to this project will be documented in this file.
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.8.0...master)
--------------
### Added
- Support Laravel 8 [\#1022 / barryvdh](https://github.com/barryvdh/laravel-ide-helper/pull/1022)
- Add option to force usage of FQN [\#1031 / edvordo](https://github.com/barryvdh/laravel-ide-helper/pull/1031)
- Add support for macros of all macroable classes [\#1006 / domkrm](https://github.com/barryvdh/laravel-ide-helper/pull/1006)
2020-08-11, 2.8.0
-----------------
### Added
- Add static return type to builder methods [\#924 / dmason30](https://github.com/barryvdh/laravel-ide-helper/pull/924)
- Add `optonal` to meta generator for PhpStorm [\#932 / halaei](https://github.com/barryvdh/laravel-ide-helper/pull/932)
- Decimal columns as string in Models [\#948 / fgibaux](https://github.com/barryvdh/laravel-ide-helper/pull/948)
- Simplify full namespaces for already included resources [\#954 / LANGERGabriel](https://github.com/barryvdh/laravel-ide-helper/pull/954)
- Make writing relation count properties optional [\#969 / AegirLeet](https://github.com/barryvdh/laravel-ide-helper/pull/969)
- Add more methods able to resolve container instances [\#996 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/996)
### Fixed
- Test `auth` is bound before detect Auth driver [\#946 / zhwei](https://github.com/barryvdh/laravel-ide-helper/pull/946)
- Fix inline doc-block for final models [\#944 / Gummibeer](https://github.com/barryvdh/laravel-ide-helper/pull/955)
2020-04-22, 2.7.0
-----------------
### Added
- Add `ignored_models` as config option [\#890 / pataar](https://github.com/barryvdh/laravel-ide-helper/pull/890)
- Infer return type from reflection if no phpdoc given [\#906 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/906)
- Add custom collection support for get and all methods [\#903 / dmason30](https://github.com/barryvdh/laravel-ide-helper/pull/903)
- if a model implements interfaces, include them in the stub [\#920 / mr-feek](https://github.com/barryvdh/laravel-ide-helper/pull/920)
- Generate noinspections PHPStorm tags [\#905 / mzglinski](https://github.com/barryvdh/laravel-ide-helper/pull/905)
- Added support for Laravel 7 custom casts [\#913 / belamov](https://github.com/barryvdh/laravel-ide-helper/pull/913)
- Ability to use patterns for model_locations [\#921 / 4n70w4](https://github.com/barryvdh/laravel-ide-helper/pull/921)
### Fixed
- MorphToMany relations with query not working [\#894 / UksusoFF](https://github.com/barryvdh/laravel-ide-helper/pull/894)
- Fix camelCase duplicated properties generator [\#881 / bop10](https://github.com/barryvdh/laravel-ide-helper/pull/881)
- Prevent generation of invalid code for certain parameter default values [\#901 / loilo](https://github.com/barryvdh/laravel-ide-helper/pull/901)
- Make hasOne and morphOne nullable [\#864 / leo108](https://github.com/barryvdh/laravel-ide-helper/pull/864)
- Remove unnecessary and wrong definition of SoftDelete methods [\#918 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/918)
- Unregister meta command custom autoloader when it is no longer needed [\#919 / mr-feek](https://github.com/barryvdh/laravel-ide-helper/pull/919)
2020-02-25, 2.6.7
-----------------
### Added
- Support for Laravel 7 [commit by barryvdh](https://github.com/barryvdh/laravel-ide-helper/commit/edd69c5e0508972c81f1f7173236de2459c45814)
2019-12-02, 2.6.6
-----------------
### Added
- Add splat operator (...) support [\#860 / ngmy](https://github.com/barryvdh/laravel-ide-helper/pull/860)
- Add support for custom date class via Date::use() [\#859 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/859)
### Fixed
- Prevent undefined property errors [\#877 / matt-allan](https://github.com/barryvdh/laravel-ide-helper/pull/877)
----
Missing an older changelog? Feel free to submit a PR!
+30 -8
View File
@@ -39,7 +39,7 @@ If for some reason you want manually control this:
"extra": {
"laravel": {
"dont-discover": [
"barryvdh/laravel-ide-helper",
"barryvdh/laravel-ide-helper"
]
}
}
@@ -52,7 +52,7 @@ If for some reason you want manually control this:
```php
public function register()
{
if ($this->app->environment() !== 'production') {
if ($this->app->isLocal()) {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
// ...
@@ -110,6 +110,18 @@ You can use an in-memory SQLite driver by adding the `-M` option.
You can choose to include helper files. This is not enabled by default, but you can override it with the `--helpers (-H)` option.
The `Illuminate/Support/helpers.php` is already set up, but you can add/remove your own files in the config file.
### Automatic PHPDoc generation for macros and mixins
This package can generate PHPDocs for macros and mixins which will be added to the `_ide_helper.php` file.
But this only works if you use type hinting when declaring a macro.
```php
Str::macro('concat', function(string $str1, string $str2) : string {
return $str1 . $str2;
});
```
### Automatic PHPDocs for models
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
@@ -121,6 +133,10 @@ By default, you are asked to overwrite or write to a separate file (`_ide_helper
You can write the comments directly to your Model file, using the `--write (-W)` option, or
force to not write with `--nowrite (-N)`.
Alternatively using the `--write-mixin (-M)` option will only add a mixin tag to your Model file,
writing the rest in (`_ide_helper_models.php`).
The class name will be different from the model, avoiding the IDE duplicate annoyance.
> Please make sure to back up your models, before writing the info.
Writing to the models should keep the existing comments and only append new properties/methods.
@@ -128,7 +144,7 @@ The existing PHPDoc is replaced, or added if not found.
With the `--reset (-R)` option, the existing PHPDocs are ignored, and only the newly found columns/relations are saved as PHPDocs.
```bash
php artisan ide-helper:models Post
php artisan ide-helper:models "App\Models\Post"
```
```php
@@ -151,10 +167,18 @@ php artisan ide-helper:models Post
*/
```
With the `--write-mixin (-M)` option
```php
/**
* …
* @mixin IdeHelperPost
*/
```
By default, models in `app/models` are scanned. The optional argument tells what models to use (also outside app/models).
```bash
php artisan ide-helper:models Post User
php artisan ide-helper:models "App\Models\Post" "App\Models\User"
```
You can also scan a different directory, using the `--dir` option (relative from the base path):
@@ -168,20 +192,18 @@ You can publish the config file (`php artisan vendor:publish`) and set the defau
Models can be ignored using the `--ignore (-I)` option
```bash
php artisan ide-helper:models --ignore="Post,User"
php artisan ide-helper:models --ignore="App\Models\Post,App\Models\User"
```
Or can be ignored by setting the `ignored_models` config
```php
'ignored_models' => [
Post::class,
App\Post::class,
Api\User::class
],
```
> Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`).
#### Magic `where*` methods
Eloquent allows calling `where<Attribute>` on your modes, e.g. `Post::whereTitle(…)` and automatically translates this to e.g. `Post::where('title', '=', '…')`.
+21 -11
View File
@@ -21,22 +21,23 @@
],
"require": {
"php": ">=7.2",
"ext-json": "*",
"barryvdh/reflection-docblock": "^2.0.6",
"composer/composer": "^1.6 || ^2.0@dev",
"doctrine/dbal": "~2.3",
"illuminate/console": "^5.5 || ^6 || ^7",
"illuminate/filesystem": "^5.5 || ^6 || ^7",
"illuminate/support": "^5.5 || ^6 || ^7",
"illuminate/console": "^6 || ^7 || ^8",
"illuminate/filesystem": "^6 || ^7 || ^8",
"illuminate/support": "^6 || ^7 || ^8",
"phpdocumentor/type-resolver": "^1.1.0"
},
"require-dev": {
"illuminate/config": "^5.5 || ^6 || ^7",
"illuminate/view": "^5.5 || ^6 || ^7",
"friendsofphp/php-cs-fixer": "^2",
"illuminate/config": "^6 || ^7 || ^8",
"illuminate/view": "^6 || ^7 || ^8",
"mockery/mockery": "^1.3",
"orchestra/testbench": "^3.5 || ^4 || ^5",
"phpro/grumphp": "^0.19.0",
"orchestra/testbench": "^4 || ^5 || ^6",
"phpunit/phpunit": "^8.5 || ^9",
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.12"
},
"config": {
@@ -44,7 +45,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
"dev-master": "2.8-dev"
},
"laravel": {
"providers": [
@@ -62,11 +63,20 @@
"Barryvdh\\LaravelIdeHelper\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"analyze": "psalm",
"check-style": "phpcs -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
"fix-style": "phpcbf -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
"check-style": [
"php-cs-fixer fix --diff --diff-format=udiff --dry-run",
"php-cs-fixer fix --diff --diff-format=udiff --dry-run --config=.php_cs.tests.php"
],
"fix-style": [
"php-cs-fixer fix",
"php-cs-fixer fix --config=.php_cs.tests.php"
],
"test": "phpunit",
"test-ci": "phpunit -d --without-creating-snapshots",
"test-regenerate": "phpunit -d --update-snapshots"
}
}
+30 -19
View File
@@ -1,6 +1,6 @@
<?php
return array(
return [
/*
|--------------------------------------------------------------------------
@@ -98,9 +98,9 @@ return array(
'include_helpers' => false,
'helper_files' => array(
'helper_files' => [
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
),
],
/*
|--------------------------------------------------------------------------
@@ -115,9 +115,9 @@ return array(
|
*/
'model_locations' => array(
'model_locations' => [
'app',
),
],
/*
|--------------------------------------------------------------------------
@@ -128,9 +128,9 @@ return array(
|
*/
'ignored_models' => array(
'ignored_models' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -141,12 +141,12 @@ return array(
|
*/
'extra' => array(
'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
'Session' => array('Illuminate\Session\Store'),
),
'extra' => [
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
'Session' => ['Illuminate\Session\Store'],
],
'magic' => array(),
'magic' => [],
/*
|--------------------------------------------------------------------------
@@ -158,9 +158,9 @@ return array(
|
*/
'interfaces' => array(
'interfaces' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -188,9 +188,9 @@ return array(
| ),
|
*/
'custom_db_types' => array(
'custom_db_types' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -226,10 +226,10 @@ return array(
| Cast the given "real type" to the given "type".
|
*/
'type_overrides' => array(
'type_overrides' => [
'integer' => 'int',
'boolean' => 'bool',
),
],
/*
|--------------------------------------------------------------------------
@@ -242,4 +242,15 @@ return array(
*/
'include_class_docblocks' => false,
);
/*
|--------------------------------------------------------------------------
| Force FQN usage
|--------------------------------------------------------------------------
|
| Use the fully qualified (class) name in docBlock,
| event if class exists in a given file
| or there is an import (use className) of a given class
|
*/
'force_fqn' => false,
];
-17
View File
@@ -1,17 +0,0 @@
grumphp:
tasks:
phpunit:
script: test
triggered_by: [php]
metadata:
task: composer_script
phpcs:
script: check-style
triggered_by: [php]
metadata:
task: composer_script
static analysis:
script: analyze
triggered_by: [php]
metadata:
task: composer_script
+7 -5
View File
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
@@ -14,9 +16,9 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
+31 -34
View File
@@ -11,13 +11,13 @@
namespace Barryvdh\LaravelIdeHelper;
use Closure;
use ReflectionClass;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
use Illuminate\Config\Repository as ConfigRepository;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
use Closure;
use Illuminate\Config\Repository as ConfigRepository;
use ReflectionClass;
class Alias
{
@@ -31,12 +31,12 @@ class Alias
protected $short;
protected $namespace = '__root';
protected $root = null;
protected $classes = array();
protected $methods = array();
protected $usedMethods = array();
protected $classes = [];
protected $methods = [];
protected $usedMethods = [];
protected $valid = false;
protected $magicMethods = array();
protected $interfaces = array();
protected $magicMethods = [];
protected $interfaces = [];
protected $phpdoc = null;
/** @var ConfigRepository */
@@ -50,7 +50,7 @@ class Alias
* @param array $magicMethods
* @param array $interfaces
*/
public function __construct($config, $alias, $facade, $magicMethods = array(), $interfaces = array())
public function __construct($config, $alias, $facade, $magicMethods = [], $interfaces = [])
{
$this->alias = $alias;
$this->magicMethods = $magicMethods;
@@ -63,12 +63,12 @@ class Alias
$this->detectRoot();
if ((!$this->isTrait() && $this->root)) {
$this->valid = true;
} else {
if (!$this->root || $this->isTrait()) {
return;
}
$this->valid = true;
$this->addClass($this->root);
$this->detectFake();
$this->detectNamespace();
@@ -82,7 +82,7 @@ class Alias
if ($facade === '\Illuminate\Database\Eloquent\Model') {
$this->usedMethods = array('decrement', 'increment');
$this->usedMethods = ['decrement', 'increment'];
}
}
@@ -289,12 +289,12 @@ class Alias
//When the database connection is not set, some classes will be skipped
} catch (\PDOException $e) {
$this->error(
"PDOException: " . $e->getMessage() .
'PDOException: ' . $e->getMessage() .
"\nPlease configure your database connection correctly, or use the sqlite memory driver (-M)." .
" Skipping $facade."
);
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nSkipping $facade.");
$this->error('Exception: ' . $e->getMessage() . "\nSkipping $facade.");
}
}
@@ -306,10 +306,7 @@ class Alias
protected function isTrait()
{
// Check if the facade is not a Trait
if (function_exists('trait_exists') && trait_exists($this->facade)) {
return true;
}
return false;
return trait_exists($this->facade);
}
/**
@@ -416,22 +413,22 @@ class Alias
{
$serializer = new DocBlockSerializer(1, $prefix);
if ($this->phpdoc) {
if ($this->config->get('ide-helper.include_class_docblocks')) {
// if a class doesn't expose any DocBlock tags
// we can perform reflection on the class and
// add in the original class DocBlock
if (count($this->phpdoc->getTags()) === 0) {
$class = new ReflectionClass($this->root);
$this->phpdoc = new DocBlock($class->getDocComment());
}
}
$this->removeDuplicateMethodsFromPhpDoc();
return $serializer->getDocComment($this->phpdoc);
if (!$this->phpdoc) {
return '';
}
return '';
if ($this->config->get('ide-helper.include_class_docblocks')) {
// if a class doesn't expose any DocBlock tags
// we can perform reflection on the class and
// add in the original class DocBlock
if (count($this->phpdoc->getTags()) === 0) {
$class = new ReflectionClass($this->root);
$this->phpdoc = new DocBlock($class->getDocComment());
}
}
$this->removeDuplicateMethodsFromPhpDoc();
return $serializer->getDocComment($this->phpdoc);
}
/**
+51 -50
View File
@@ -15,8 +15,8 @@ use Barryvdh\LaravelIdeHelper\Eloquent;
use Barryvdh\LaravelIdeHelper\Generator;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* A command to generate autocomplete information for your IDE
@@ -25,7 +25,6 @@ use Symfony\Component\Console\Input\InputArgument;
*/
class GeneratorCommand extends Command
{
/**
* The console command name.
*
@@ -59,7 +58,8 @@ class GeneratorCommand extends Command
* @param \Illuminate\View\Factory $view
*/
public function __construct(
/*ConfigRepository */ $config,
/*ConfigRepository */
$config,
Filesystem $files,
/* Illuminate\View\Factory */
$view
@@ -85,46 +85,47 @@ class GeneratorCommand extends Command
$this->error(
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
);
return;
}
$filename = $this->argument('filename');
$format = $this->option('format');
// Strip the php extension
if (substr($filename, -4, 4) === '.php') {
$filename = substr($filename, 0, -4);
}
$filename .= '.' . $format;
if ($this->option('memory')) {
$this->useMemoryDriver();
}
$helpers = '';
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
foreach ($this->config->get('ide-helper.helper_files', []) as $helper) {
if (file_exists($helper)) {
$helpers .= str_replace(['<?php', '?>'], '', $this->files->get($helper));
}
}
} else {
$filename = $this->argument('filename');
$format = $this->option('format');
// Strip the php extension
if (substr($filename, -4, 4) == '.php') {
$filename = substr($filename, 0, -4);
}
$filename .= '.' . $format;
if ($this->option('memory')) {
$this->useMemoryDriver();
}
$helpers = '';
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
foreach ($this->config->get('ide-helper.helper_files', array()) as $helper) {
if (file_exists($helper)) {
$helpers .= str_replace(array('<?php', '?>'), '', $this->files->get($helper));
}
}
} else {
$helpers = '';
}
}
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate($format);
$written = $this->files->put($filename, $content);
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate($format);
$written = $this->files->put($filename, $content);
if ($written !== false) {
$this->info("A new helper file was written to $filename");
if ($written !== false) {
$this->info("A new helper file was written to $filename");
if ($this->option('write_mixins')) {
Eloquent::writeEloquentModelHelper($this, $this->files);
}
} else {
$this->error("The helper file could not be created at $filename");
if ($this->option('write_mixins')) {
Eloquent::writeEloquentModelHelper($this, $this->files);
}
} else {
$this->error("The helper file could not be created at $filename");
}
}
@@ -133,10 +134,10 @@ class GeneratorCommand extends Command
//Use a sqlite database in memory, to avoid connection errors on Database facades
$this->config->set(
'database.connections.sqlite',
array(
[
'driver' => 'sqlite',
'database' => ':memory:',
)
]
);
$this->config->set('database.default', 'sqlite');
}
@@ -150,11 +151,11 @@ class GeneratorCommand extends Command
{
$filename = $this->config->get('ide-helper.filename');
return array(
array(
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
),
);
return [
[
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename,
],
];
}
/**
@@ -167,11 +168,11 @@ class GeneratorCommand extends Command
$format = $this->config->get('ide-helper.format');
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
return array(
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
array('write_mixins', "W", InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins),
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
);
return [
['format', 'F', InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format],
['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins],
['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'],
['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'],
];
}
}
+5 -6
View File
@@ -23,7 +23,6 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class MetaCommand extends Command
{
/**
* The console command name.
*
@@ -58,7 +57,7 @@ class MetaCommand extends Command
'\App::makeWith(0)',
'\app(0)',
'\resolve(0)',
'\Psr\Container\ContainerInterface::get',
'\Psr\Container\ContainerInterface::get(0)',
];
/**
@@ -87,7 +86,7 @@ class MetaCommand extends Command
$this->registerClassAutoloadExceptions();
$bindings = array();
$bindings = [];
foreach ($this->getAbstracts() as $abstract) {
// Validator and seeder cause problems
if (in_array($abstract, ['validator', 'seeder'])) {
@@ -161,9 +160,9 @@ class MetaCommand extends Command
{
$filename = $this->config->get('ide-helper.meta_filename');
return array(
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
);
return [
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename],
];
}
/**
+165 -140
View File
@@ -58,10 +58,11 @@ class ModelsCommand extends Command
protected $write_model_magic_where;
protected $write_model_relation_count_properties;
protected $properties = array();
protected $methods = array();
protected $properties = [];
protected $methods = [];
protected $write = false;
protected $dirs = array();
protected $write_mixin = false;
protected $dirs = [];
protected $reset;
protected $keep_text;
protected $phpstorm_noinspections;
@@ -71,7 +72,7 @@ class ModelsCommand extends Command
protected $nullableColumns = [];
/**
* During initializtion we use Laravels Date Facade to
* During initialization we use Laravels Date Facade to
* determine the actual date class and store it here.
*
* @var string
@@ -96,8 +97,9 @@ class ModelsCommand extends Command
{
$filename = $this->option('filename');
$this->write = $this->option('write');
$this->write_mixin = $this->option('write-mixin');
$this->dirs = array_merge(
$this->laravel['config']->get('ide-helper.model_locations'),
$this->laravel['config']->get('ide-helper.model_locations', []),
$this->option('dir')
);
$model = $this->argument('model');
@@ -111,6 +113,7 @@ class ModelsCommand extends Command
$this->write_model_relation_count_properties =
$this->laravel['config']->get('ide-helper.write_model_relation_count_properties', true);
$this->write = $this->write_mixin ? true : $this->write;
//If filename is default and Write is not specified, ask what to do
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
if (
@@ -128,7 +131,7 @@ class ModelsCommand extends Command
$content = $this->generateDocs($model, $ignore);
if (!$this->write) {
if (!$this->write || $this->write_mixin) {
$written = $this->files->put($filename, $content);
if ($written !== false) {
$this->info("Model information was written to $filename");
@@ -146,9 +149,9 @@ class ModelsCommand extends Command
*/
protected function getArguments()
{
return array(
array('model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', array()),
);
return [
['model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', []],
];
}
/**
@@ -158,20 +161,23 @@ class ModelsCommand extends Command
*/
protected function getOptions()
{
return array(
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename),
array('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'The model dir, supports glob patterns', array()),
array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
array('phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
return [
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename],
['dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'The model dir, supports glob patterns', [], ],
['write', 'W', InputOption::VALUE_NONE, 'Write to Model file'],
['write-mixin', 'M', InputOption::VALUE_NONE,
"Write models to {$this->filename} and adds @mixin to each model, avoiding IDE duplicate declaration warnings",
],
['nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'],
['reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'],
['smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'],
['phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
'Add PhpFullyQualifiedNameUsageInspection and PhpUnnecessaryFullyQualifiedNameInspection PHPStorm ' .
'noinspection tags'
),
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
);
'noinspection tags',
],
['ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''],
];
}
protected function generateDocs($loadModels, $ignore = '')
@@ -195,7 +201,7 @@ class ModelsCommand extends Command
if (empty($loadModels)) {
$models = $this->loadModels();
} else {
$models = array();
$models = [];
foreach ($loadModels as $model) {
$models = array_merge($models, explode(',', $model));
}
@@ -203,7 +209,7 @@ class ModelsCommand extends Command
$ignore = array_merge(
explode(',', $ignore),
$this->laravel['config']->get('ide-helper.ignored_models', array())
$this->laravel['config']->get('ide-helper.ignored_models', [])
);
foreach ($models as $name) {
@@ -213,8 +219,8 @@ class ModelsCommand extends Command
}
continue;
}
$this->properties = array();
$this->methods = array();
$this->properties = [];
$this->methods = [];
if (class_exists($name)) {
try {
// handle abstract classes, interfaces, ...
@@ -224,9 +230,7 @@ class ModelsCommand extends Command
continue;
}
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->comment("Loading model '$name'");
}
$this->comment("Loading model '$name'", OutputInterface::VERBOSITY_VERBOSE);
if (!$reflectionClass->IsInstantiable()) {
// ignore abstract class or interface
@@ -250,7 +254,7 @@ class ModelsCommand extends Command
$ignore[] = $name;
$this->nullableColumns = [];
} catch (\Throwable $e) {
$this->error("Exception: " . $e->getMessage() .
$this->error('Exception: ' . $e->getMessage() .
"\nCould not analyze class $name.\n\nTrace:\n" .
$e->getTraceAsString());
}
@@ -270,9 +274,17 @@ class ModelsCommand extends Command
protected function loadModels()
{
$models = array();
$models = [];
foreach ($this->dirs as $dir) {
$dir = base_path() . '/' . $dir;
if (is_dir(base_path($dir))) {
$dir = base_path($dir);
}
if (!is_dir($dir)) {
$this->error("Cannot locate directory '{'$dir}'");
continue;
}
$dirs = glob($dir, GLOB_ONLYDIR);
foreach ($dirs as $dir) {
if (file_exists($dir)) {
@@ -338,29 +350,29 @@ class ModelsCommand extends Command
if (!isset($this->properties[$name])) {
continue;
} else {
$realType = $this->checkForCustomLaravelCasts($realType);
$realType = $this->getTypeOverride($realType);
$this->properties[$name]['type'] = $this->getTypeInModel($model, $realType);
}
if (isset($this->nullableColumns[$name])) {
$this->properties[$name]['type'] .= '|null';
}
$realType = $this->checkForCustomLaravelCasts($realType);
$realType = $this->getTypeOverride($realType);
$this->properties[$name]['type'] = $this->getTypeInModel($model, $realType);
if (isset($this->nullableColumns[$name])) {
$this->properties[$name]['type'] .= '|null';
}
}
}
/**
* Returns the overide type for the give type.
* Returns the override type for the give type.
*
* @param string $type
* @return string|null
*/
protected function getTypeOverride($type)
{
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', array());
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', []);
return isset($typeOverrides[$type]) ? $typeOverrides[$type] : $type;
return $typeOverrides[$type] ?? $type;
}
/**
@@ -371,12 +383,12 @@ class ModelsCommand extends Command
protected function getPropertiesFromTable($model)
{
$table = $model->getConnection()->getTablePrefix() . $model->getTable();
$schema = $model->getConnection()->getDoctrineSchemaManager($table);
$schema = $model->getConnection()->getDoctrineSchemaManager();
$databasePlatform = $schema->getDatabasePlatform();
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
$platformName = $databasePlatform->getName();
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", array());
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []);
foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
}
@@ -388,70 +400,72 @@ class ModelsCommand extends Command
$columns = $schema->listTableColumns($table, $database);
if ($columns) {
foreach ($columns as $column) {
$name = $column->getName();
if (in_array($name, $model->getDates())) {
$type = $this->dateClass;
} else {
$type = $column->getType()->getName();
switch ($type) {
case 'string':
case 'text':
case 'date':
case 'time':
case 'guid':
case 'datetimetz':
case 'datetime':
case 'decimal':
$type = 'string';
break;
case 'integer':
case 'bigint':
case 'smallint':
$type = 'integer';
break;
case 'boolean':
switch (config('database.default')) {
case 'sqlite':
case 'mysql':
$type = 'integer';
break;
default:
$type = 'boolean';
break;
}
break;
case 'float':
$type = 'float';
break;
default:
$type = 'mixed';
break;
}
}
if (!$columns) {
return;
}
$comment = $column->getComment();
if (!$column->getNotnull()) {
$this->nullableColumns[$name] = true;
foreach ($columns as $column) {
$name = $column->getName();
if (in_array($name, $model->getDates())) {
$type = $this->dateClass;
} else {
$type = $column->getType()->getName();
switch ($type) {
case 'string':
case 'text':
case 'date':
case 'time':
case 'guid':
case 'datetimetz':
case 'datetime':
case 'decimal':
$type = 'string';
break;
case 'integer':
case 'bigint':
case 'smallint':
$type = 'integer';
break;
case 'boolean':
switch (config('database.default')) {
case 'sqlite':
case 'mysql':
$type = 'integer';
break;
default:
$type = 'boolean';
break;
}
break;
case 'float':
$type = 'float';
break;
default:
$type = 'mixed';
break;
}
$this->setProperty(
$name,
$this->getTypeInModel($model, $type),
true,
true,
$comment,
!$column->getNotnull()
}
$comment = $column->getComment();
if (!$column->getNotnull()) {
$this->nullableColumns[$name] = true;
}
$this->setProperty(
$name,
$this->getTypeInModel($model, $type),
true,
true,
$comment,
!$column->getNotnull()
);
if ($this->write_model_magic_where) {
$this->setMethod(
Str::camel('where_' . $name),
$this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class)
. '|'
. $this->getClassNameInDestinationFile($model, get_class($model)),
['$value']
);
if ($this->write_model_magic_where) {
$this->setMethod(
Str::camel("where_" . $name),
$this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class)
. '|'
. $this->getClassNameInDestinationFile($model, get_class($model)),
array('$value')
);
}
}
}
}
@@ -513,7 +527,7 @@ class ModelsCommand extends Command
$this->setMethod(
$method,
$builder . "|" . $this->getClassNameInDestinationFile($model, get_class($model))
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model))
);
} elseif (
!method_exists('Illuminate\Database\Eloquent\Model', $method)
@@ -544,7 +558,7 @@ class ModelsCommand extends Command
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
foreach (
array(
[
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
@@ -555,8 +569,8 @@ class ModelsCommand extends Command
'morphTo' => '\Illuminate\Database\Eloquent\Relations\MorphTo',
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
) as $relation => $impl
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
] as $relation => $impl
) {
$search = '$this->' . $relation . '(';
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
@@ -570,7 +584,11 @@ class ModelsCommand extends Command
// can cause errors. Since we don't need constraints we can
// disable them when we fetch the relation to avoid errors.
$relationObj = Relation::noConstraints(function () use ($model, $method) {
return $model->$method();
try {
return $model->$method();
} catch (\Throwable $e) {
return null;
}
});
if ($relationObj instanceof Relation) {
@@ -609,7 +627,7 @@ class ModelsCommand extends Command
false
);
}
} elseif ($relation === "morphTo") {
} elseif ($relation === 'morphTo') {
// Model isn't specified because relation is polymorphic
$this->setProperty(
$method,
@@ -676,7 +694,7 @@ class ModelsCommand extends Command
protected function setProperty($name, $type = null, $read = null, $write = null, $comment = '', $nullable = false)
{
if (!isset($this->properties[$name])) {
$this->properties[$name] = array();
$this->properties[$name] = [];
$this->properties[$name]['type'] = 'mixed';
$this->properties[$name]['read'] = false;
$this->properties[$name]['write'] = false;
@@ -697,12 +715,12 @@ class ModelsCommand extends Command
}
}
protected function setMethod($name, $type = '', $arguments = array())
protected function setMethod($name, $type = '', $arguments = [])
{
$methods = array_change_key_case($this->methods, CASE_LOWER);
if (!isset($methods[strtolower($name)])) {
$this->methods[$name] = array();
$this->methods[$name] = [];
$this->methods[$name]['type'] = $type;
$this->methods[$name]['arguments'] = $arguments;
}
@@ -740,13 +758,13 @@ class ModelsCommand extends Command
$phpdoc->setText($class);
}
$properties = array();
$methods = array();
$properties = [];
$methods = [];
foreach ($phpdoc->getTags() as $tag) {
$name = $tag->getName();
if ($name == "property" || $name == "property-read" || $name == "property-write") {
if ($name == 'property' || $name == 'property-read' || $name == 'property-write') {
$properties[] = $tag->getVariableName();
} elseif ($name == "method") {
} elseif ($name == 'method') {
$methods[] = $tag->getMethodName();
}
}
@@ -785,37 +803,54 @@ class ModelsCommand extends Command
$phpdoc->appendTag($tag);
}
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
$phpdoc->appendTag(Tag::createInstance("@mixin " . $eloquentClassNameInModel, $phpdoc));
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
}
if ($this->phpstorm_noinspections) {
/**
* Facades, Eloquent API
* @see https://www.jetbrains.com/help/phpstorm/php-fully-qualified-name-usage.html
*/
$phpdoc->appendTag(Tag::createInstance("@noinspection PhpFullyQualifiedNameUsageInspection", $phpdoc));
$phpdoc->appendTag(Tag::createInstance('@noinspection PhpFullyQualifiedNameUsageInspection', $phpdoc));
/**
* Relations, other models in the same namespace
* @see https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html
*/
$phpdoc->appendTag(
Tag::createInstance("@noinspection PhpUnnecessaryFullyQualifiedNameInspection", $phpdoc)
Tag::createInstance('@noinspection PhpUnnecessaryFullyQualifiedNameInspection', $phpdoc)
);
}
$serializer = new DocBlockSerializer();
$serializer->getDocComment($phpdoc);
$docComment = $serializer->getDocComment($phpdoc);
if ($this->write_mixin) {
$phpdocMixin = new DocBlock($reflection, new Context($namespace));
// remove all mixin tags prefixed with IdeHelper
foreach ($phpdocMixin->getTagsByName('mixin') as $tag) {
if (Str::startsWith($tag->getContent(), 'IdeHelper')) {
$phpdocMixin->deleteTag($tag);
}
}
$mixinClassName = "IdeHelper{$classname}";
$phpdocMixin->appendTag(Tag::createInstance("@mixin {$mixinClassName}", $phpdocMixin));
$mixinDocComment = $serializer->getDocComment($phpdocMixin);
// remove blank lines if there's no text
if (!$phpdocMixin->getText()) {
$mixinDocComment = preg_replace("/\s\*\s*\n/", '', $mixinDocComment);
}
}
if ($this->write) {
$modelDocComment = $this->write_mixin ? $mixinDocComment : $docComment;
$filename = $reflection->getFileName();
$contents = $this->files->get($filename);
if ($originalDoc) {
$contents = str_replace($originalDoc, $docComment, $contents);
$contents = str_replace($originalDoc, $modelDocComment, $contents);
} else {
$replace = "{$docComment}\n";
$replace = "{$modelDocComment}\n";
$pos = strpos($contents, "final class {$classname}") ?: strpos($contents, "class {$classname}");
if ($pos !== false) {
$contents = substr_replace($contents, $replace, $pos, 0);
@@ -826,6 +861,7 @@ class ModelsCommand extends Command
}
}
$classname = $this->write_mixin ? $mixinClassName : $classname;
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent ";
if ($interfaceNames) {
@@ -844,14 +880,12 @@ class ModelsCommand extends Command
*/
public function getParameters($method)
{
//Loop through the default values for paremeters, and make the correct output string
$params = array();
$paramsWithDefault = array();
//Loop through the default values for parameters, and make the correct output string
$paramsWithDefault = [];
/** @var \ReflectionParameter $param */
foreach ($method->getParameters() as $param) {
$paramClass = $param->getClass();
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
$params[] = $paramStr;
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
$default = $param->getDefaultValue();
if (is_bool($default)) {
@@ -1034,11 +1068,6 @@ class ModelsCommand extends Command
return $type;
}
/**
* @param object|ReflectionClass $model
* @param string $type
* @return string
*/
protected function getTypeInModel(object $model, ?string $type): ?string
{
if ($type === null) {
@@ -1052,11 +1081,6 @@ class ModelsCommand extends Command
return $type;
}
/**
* @param object|ReflectionClass $model
* @param string $className
* @return string
*/
protected function getClassNameInDestinationFile(object $model, string $className): string
{
$reflection = $model instanceof ReflectionClass
@@ -1067,8 +1091,9 @@ class ModelsCommand extends Command
$className = trim($className, '\\');
$writingToExternalFile = !$this->write;
$classIsNotInExternalFile = $reflection->getName() !== $className;
$forceFQCN = $this->laravel['config']->get('ide-helper.force_fqn', false);
if ($writingToExternalFile && $classIsNotInExternalFile) {
if (($writingToExternalFile && $classIsNotInExternalFile) || $forceFQCN) {
return '\\' . $className;
}
+24 -20
View File
@@ -8,12 +8,12 @@
namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class Eloquent
{
@@ -85,25 +85,29 @@ class Eloquent
}
$filename = $reflection->getFileName();
if ($filename) {
$contents = $files->get($filename);
if ($contents) {
$count = 0;
$contents = str_replace($originalDoc, $docComment, $contents, $count);
if ($count > 0) {
if ($files->put($filename, $contents)) {
$command->info('Wrote expected docblock to ' . $filename);
} else {
$command->error('File write failed to ' . $filename);
}
} else {
$command->error('Content did not change ' . $contents);
}
} else {
$command->error('No file contents found ' . $filename);
}
} else {
if (!$filename) {
$command->error('Filename not found ' . $class);
return;
}
$contents = $files->get($filename);
if (!$contents) {
$command->error('No file contents found ' . $filename);
return;
}
$count = 0;
$contents = str_replace($originalDoc, $docComment, $contents, $count);
if ($count <= 0) {
$command->error('Content did not change ' . $contents);
return;
}
if (!$files->put($filename, $contents)) {
$command->error('File write failed to ' . $filename);
return;
}
$command->info('Wrote expected docblock to ' . $filename);
}
}
-1
View File
@@ -8,7 +8,6 @@ use ReflectionClass;
class Factories
{
public static function all()
{
$factories = [];
+80 -22
View File
@@ -11,9 +11,10 @@
namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,9 +29,9 @@ class Generator
/** @var \Symfony\Component\Console\Output\OutputInterface */
protected $output;
protected $extra = array();
protected $magic = array();
protected $interfaces = array();
protected $extra = [];
protected $magic = [];
protected $interfaces = [];
protected $helpers;
/**
@@ -40,8 +41,10 @@ class Generator
* @param string $helpers
*/
public function __construct(
/*ConfigRepository */ $config,
/* Illuminate\View\Factory */ $view,
/*ConfigRepository */
$config,
/* Illuminate\View\Factory */
$view,
OutputInterface $output = null,
$helpers = ''
) {
@@ -93,16 +96,16 @@ class Generator
public function generateJsonHelper()
{
$classes = array();
$classes = [];
foreach ($this->getValidAliases() as $aliases) {
foreach ($aliases as $alias) {
$functions = array();
$functions = [];
foreach ($alias->getMethods() as $method) {
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
}
$classes[$alias->getAlias()] = array(
$classes[$alias->getAlias()] = [
'functions' => $functions,
);
];
}
}
@@ -111,11 +114,11 @@ class Generator
$flags |= JSON_PRETTY_PRINT;
}
return json_encode(array(
'php' => array(
return json_encode([
'php' => [
'classes' => $classes,
),
), $flags);
],
], $flags);
}
protected function detectDrivers()
@@ -129,7 +132,7 @@ class Generator
&& app()->bound('auth')
) {
$class = get_class(\Auth::guard());
$this->extra['Auth'] = array($class);
$this->extra['Auth'] = [$class];
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
}
} catch (\Exception $e) {
@@ -138,7 +141,7 @@ class Generator
try {
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
$class = get_class(\DB::connection());
$this->extra['DB'] = array($class);
$this->extra['DB'] = [$class];
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
}
} catch (\Exception $e) {
@@ -148,7 +151,7 @@ class Generator
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
$driver = get_class(\Cache::driver());
$store = get_class(\Cache::getStore());
$this->extra['Cache'] = array($driver, $store);
$this->extra['Cache'] = [$driver, $store];
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
}
} catch (\Exception $e) {
@@ -157,7 +160,7 @@ class Generator
try {
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
$class = get_class(\Queue::connection());
$this->extra['Queue'] = array($class);
$this->extra['Queue'] = [$class];
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
}
} catch (\Exception $e) {
@@ -166,7 +169,7 @@ class Generator
try {
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)) {
$class = get_class(\SSH::connection());
$this->extra['SSH'] = array($class);
$this->extra['SSH'] = [$class];
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
}
} catch (\Exception $e) {
@@ -175,7 +178,7 @@ class Generator
try {
if (class_exists('Storage') && is_a('Storage', '\Illuminate\Support\Facades\Storage', true)) {
$class = get_class(\Storage::disk());
$this->extra['Storage'] = array($class);
$this->extra['Storage'] = [$class];
$this->interfaces['\Illuminate\Contracts\Filesystem\Filesystem'] = $class;
}
} catch (\Exception $e) {
@@ -198,7 +201,7 @@ class Generator
continue;
}
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : [];
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
if ($alias->isValid()) {
//Add extra methods, from other classes (magic static calls)
@@ -220,7 +223,11 @@ class Generator
*/
protected function getAliasesByExtendsNamespace()
{
return $this->getValidAliases()->groupBy(function (Alias $alias) {
$aliases = $this->getValidAliases();
$this->addMacroableClasses($aliases);
return $aliases->groupBy(function (Alias $alias) {
return $alias->getExtendsNamespace();
});
}
@@ -291,4 +298,55 @@ class Generator
echo $string . "\r\n";
}
}
/**
* Add all macroable classes which are not already loaded as an alias and have defined macros.
*
* @param Collection $aliases
*/
protected function addMacroableClasses(Collection $aliases)
{
$macroable = $this->getMacroableClasses($aliases);
foreach ($macroable as $class) {
$reflection = new ReflectionClass($class);
if (!$reflection->getStaticProperties()['macros']) {
continue;
}
$aliases[] = new Alias($this->config, $class, $class, [], $this->interfaces);
}
}
/**
* Get all loaded macroable classes which are not loaded as an alias.
*
* @param Collection $aliases
* @return Collection
*/
protected function getMacroableClasses(Collection $aliases)
{
return (new Collection(get_declared_classes()))
->filter(function ($class) {
$reflection = new ReflectionClass($class);
// Filter out internal classes and class aliases
return !$reflection->isInternal() && $reflection->getName() === $class;
})
->filter(function ($class) {
$traits = class_uses($class);
// Filter only classes with the macroable trait
return isset($traits[Macroable::class]);
})
->filter(function ($class) use ($aliases) {
$class = Str::start($class, '\\');
// Filter out aliases
return !$aliases->first(function (Alias $alias) use ($class) {
return $alias->getExtends() === $class;
});
});
}
}
+8 -4
View File
@@ -15,6 +15,7 @@ use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Illuminate\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Engines\PhpEngine;
@@ -23,7 +24,6 @@ use Illuminate\View\FileViewFinder;
class IdeHelperServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
@@ -86,7 +86,7 @@ class IdeHelperServiceProvider extends ServiceProvider
$this->app->singleton(
'command.ide-helper.eloquent',
function ($app) use ($localViewFactory) {
function ($app) {
return new EloquentCommand($app['files']);
}
);
@@ -106,7 +106,7 @@ class IdeHelperServiceProvider extends ServiceProvider
*/
public function provides()
{
return array('command.ide-helper.generate', 'command.ide-helper.models');
return ['command.ide-helper.generate', 'command.ide-helper.models'];
}
/**
@@ -116,7 +116,11 @@ class IdeHelperServiceProvider extends ServiceProvider
{
$resolver = new EngineResolver();
$resolver->register('php', function () {
return new PhpEngine();
if ((int) Application::VERSION < 8) {
return new PhpEngine();
}
return new PhpEngine($this->app['files']);
});
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
$factory = new Factory($resolver, $finder, $this->app['events']);
+21 -2
View File
@@ -21,7 +21,7 @@ class Macro extends Method
$alias,
$class,
$methodName = null,
$interfaces = array()
$interfaces = []
) {
parent::__construct($method, $alias, $class, $methodName, $interfaces);
}
@@ -31,7 +31,26 @@ class Macro extends Method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method);
$this->phpdoc = new DocBlock('/** */');
// Add macro parameters
foreach ($method->getParameters() as $parameter) {
$type = $parameter->hasType() ? $parameter->getType()->getName() : 'mixed';
$type .= $parameter->hasType() && $parameter->getType()->allowsNull() ? '|null' : '';
$name = $parameter->isVariadic() ? '...' : '';
$name .= '$' . $parameter->getName();
$this->phpdoc->appendTag(Tag::createInstance("@param {$type} {$name}"));
}
// Add macro return type
if ($method->hasReturnType()) {
$type = $method->getReturnType()->getName();
$type .= $method->getReturnType()->allowsNull() ? '|null' : '';
$this->phpdoc->appendTag(Tag::createInstance("@return {$type}"));
}
}
/**
+39 -37
View File
@@ -13,10 +13,10 @@ namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
@@ -32,9 +32,9 @@ class Method
protected $declaringClassName;
protected $name;
protected $namespace;
protected $params = array();
protected $params_with_default = array();
protected $interfaces = array();
protected $params = [];
protected $params_with_default = [];
protected $interfaces = [];
protected $real_name;
protected $return = null;
protected $root;
@@ -46,7 +46,7 @@ class Method
* @param string|null $methodName
* @param array $interfaces
*/
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
public function __construct($method, $alias, $class, $methodName = null, $interfaces = [])
{
$this->method = $method;
$this->interfaces = $interfaces;
@@ -119,7 +119,7 @@ class Method
*/
public function isInstanceCall()
{
return ! ($this->method->isClosure() || $this->method->isStatic());
return !($this->method->isClosure() || $this->method->isStatic());
}
/**
@@ -251,35 +251,37 @@ class Method
*/
protected function normalizeReturn(DocBlock $phpdoc)
{
//Get the return type and adjust them for beter autocomplete
//Get the return type and adjust them for better autocomplete
$returnTags = $phpdoc->getTagsByName('return');
if ($returnTags) {
/** @var ReturnTag $tag */
$tag = reset($returnTags);
// Get the expanded type
$returnValue = $tag->getType();
// Replace the interfaces
foreach ($this->interfaces as $interface => $real) {
$returnValue = str_replace($interface, $real, $returnValue);
}
// Set the changed content
$tag->setContent($returnValue . ' ' . $tag->getDescription());
$this->return = $returnValue;
if ($tag->getType() === '$this') {
Str::contains($this->root, Builder::class)
? $tag->setType($this->root . '|static')
: $tag->setType($this->root);
}
} else {
if (count($returnTags) === 0) {
$this->return = null;
return;
}
/** @var ReturnTag $tag */
$tag = reset($returnTags);
// Get the expanded type
$returnValue = $tag->getType();
// Replace the interfaces
foreach ($this->interfaces as $interface => $real) {
$returnValue = str_replace($interface, $real, $returnValue);
}
// Set the changed content
$tag->setContent($returnValue . ' ' . $tag->getDescription());
$this->return = $returnValue;
if ($tag->getType() === '$this') {
Str::contains($this->root, Builder::class)
? $tag->setType($this->root . '|static')
: $tag->setType($this->root);
}
}
/**
* Convert keywwords that are incorrect.
* Convert keywords that are incorrect.
*
* @param string $string
* @return string
@@ -300,7 +302,7 @@ class Method
*/
public function shouldReturn()
{
if ($this->return !== "void" && $this->method->name !== "__construct") {
if ($this->return !== 'void' && $this->method->name !== '__construct') {
return true;
}
@@ -311,13 +313,13 @@ class Method
* Get the parameters and format them correctly
*
* @param \ReflectionMethod $method
* @return array
* @return void
*/
public function getParameters($method)
{
//Loop through the default values for paremeters, and make the correct output string
$params = array();
$paramsWithDefault = array();
//Loop through the default values for parameters, and make the correct output string
$params = [];
$paramsWithDefault = [];
foreach ($method->getParameters() as $param) {
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
$params[] = $paramStr;
@@ -366,9 +368,9 @@ class Method
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
//Not at the end yet, try another parent/interface..
return $this->getInheritDoc($method);
} else {
return $phpdoc;
}
return $phpdoc;
}
}
}
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\MetaCommand;
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
use Illuminate\Filesystem\Filesystem;
use Mockery\MockInterface;
class MetaCommandTest extends TestCase
{
public function testCommand(): void
{
$this->mockFilesystem();
/** @var Filesystem|MockInterface $mockFileSystem */
$mockFileSystem = $this->app->make(Filesystem::class);
$this->instance('files', $mockFileSystem);
$mockFileSystem
->shouldReceive('getRequire')
->andReturnUsing(function ($__path, $__data) {
return (static function () use ($__path, $__data) {
extract($__data, EXTR_SKIP);
return require $__path;
})();
});
$this->artisan('ide-helper:meta');
// We're not testing the whole file, just some basic structure elements
self::assertStringContainsString("namespace PHPSTORM_META {\n", $this->mockFilesystemOutput);
self::assertStringContainsString("PhpStorm Meta file, to provide autocomplete information for PhpStorm\n", $this->mockFilesystemOutput);
self::assertStringContainsString('override(', $this->mockFilesystemOutput);
}
/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [IdeHelperServiceProvider::class];
}
}
@@ -4,8 +4,9 @@ declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
use Illuminate\Foundation\Application;
abstract class AbstractModelsCommand extends TestCase
{
@@ -13,14 +14,21 @@ abstract class AbstractModelsCommand extends TestCase
{
parent::setUp();
// Skip older Laravel version for these tests
if (version_compare(Application::VERSION, '6.0', '<')) {
$this->markTestSkipped('This test requires Laravel 6.0 or higher');
return;
}
$this->loadMigrationsFrom(__DIR__ . '/migrations');
$this->artisan('migrate');
$this->mockFilesystem();
}
/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [IdeHelperServiceProvider::class];
}
protected function getEnvironmentSetUp($app)
@@ -35,5 +43,18 @@ abstract class AbstractModelsCommand extends TestCase
'database' => ':memory:',
'prefix' => '',
]);
// Load the Models from the Test dir
$config->set('ide-helper.model_locations', [
dirname((new \ReflectionClass(static::class))->getFileName()) . '/Models',
]);
// Don't override integer -> int for tests
$config->set('ide-helper.type_overrides', []);
}
protected function assertMatchesMockedSnapshot()
{
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
}
}
@@ -1,10 +1,11 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections;
use Illuminate\Database\Eloquent\Collection;
class SimpleCollection extends Collection
{
}
@@ -6,44 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/CustomCollection/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -51,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -7,10 +7,8 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Carbon\CarbonImmutable;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -28,38 +26,8 @@ class Test extends AbstractModelsCommand
parent::tearDown();
}
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/CustomDate/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/CustomDate.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -67,7 +35,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
class Dynamic extends Model
{
/** @var \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\OtherModels\Account */
protected $account;
// Regular relations
public function regularHasMany(): HasMany
{
return $this->hasMany(Dynamic::class);
}
// Dynamic relations
public function dynamicHasMany(): HasMany
{
return $this->hasMany(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
public function dynamicHasOne(): HasOne
{
return $this->hasOne(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
public function dynamicBelongsTo(): BelongsTo
{
return $this->belongsTo(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
}
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\OtherModels;
use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
public function test(): void
{
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic
*
* @property-read \Illuminate\Database\Eloquent\Collection|Dynamic[] $regularHasMany
* @property-read int|null $regular_has_many_count
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic query()
* @mixin \Eloquent
*/
class Dynamic extends Model
{
/** @var \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\OtherModels\Account */
protected $account;
// Regular relations
public function regularHasMany(): HasMany
{
return $this->hasMany(Dynamic::class);
}
// Dynamic relations
public function dynamicHasMany(): HasMany
{
return $this->hasMany(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
public function dynamicHasOne(): HasOne
{
return $this->hasOne(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
public function dynamicBelongsTo(): BelongsTo
{
return $this->belongsTo(Dynamic::class)->where('date', '>=', $this->account->created_at);
}
}
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdoc/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -15,36 +13,11 @@ class Test extends AbstractModelsCommand
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models',
],
// Activate the camel_case mode
'model_camel_case_properties' => true,
]);
$app['config']->set('ide-helper.model_camel_case_properties', true);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -52,7 +25,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
use SoftDeletes;
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
public function scopeNull($query, string $unusedParam)
{
return $query;
}
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper.force_fqn', true);
}
public function test(): void
{
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,184 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post
*
* @property integer $id
* @property string|null $char_nullable
* @property string $char_not_nullable
* @property string|null $string_nullable
* @property string $string_not_nullable
* @property string|null $text_nullable
* @property string $text_not_nullable
* @property string|null $medium_text_nullable
* @property string $medium_text_not_nullable
* @property string|null $long_text_nullable
* @property string $long_text_not_nullable
* @property integer|null $integer_nullable
* @property integer $integer_not_nullable
* @property integer|null $tiny_integer_nullable
* @property integer $tiny_integer_not_nullable
* @property integer|null $small_integer_nullable
* @property integer $small_integer_not_nullable
* @property integer|null $medium_integer_nullable
* @property integer $medium_integer_not_nullable
* @property integer|null $big_integer_nullable
* @property integer $big_integer_not_nullable
* @property integer|null $unsigned_integer_nullable
* @property integer $unsigned_integer_not_nullable
* @property integer|null $unsigned_tiny_integer_nullable
* @property integer $unsigned_tiny_integer_not_nullable
* @property integer|null $unsigned_small_integer_nullable
* @property integer $unsigned_small_integer_not_nullable
* @property integer|null $unsigned_medium_integer_nullable
* @property integer $unsigned_medium_integer_not_nullable
* @property integer|null $unsigned_big_integer_nullable
* @property integer $unsigned_big_integer_not_nullable
* @property float|null $float_nullable
* @property float $float_not_nullable
* @property float|null $double_nullable
* @property float $double_not_nullable
* @property string|null $decimal_nullable
* @property string $decimal_not_nullable
* @property string|null $unsigned_decimal_nullable
* @property string $unsigned_decimal_not_nullable
* @property integer|null $boolean_nullable
* @property integer $boolean_not_nullable
* @property string|null $enum_nullable
* @property string $enum_not_nullable
* @property string|null $json_nullable
* @property string $json_not_nullable
* @property string|null $jsonb_nullable
* @property string $jsonb_not_nullable
* @property string|null $date_nullable
* @property string $date_not_nullable
* @property string|null $datetime_nullable
* @property string $datetime_not_nullable
* @property string|null $datetimetz_nullable
* @property string $datetimetz_not_nullable
* @property string|null $time_nullable
* @property string $time_not_nullable
* @property string|null $timetz_nullable
* @property string $timetz_not_nullable
* @property string|null $timestamp_nullable
* @property string $timestamp_not_nullable
* @property string|null $timestamptz_nullable
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
* @property string $ipaddress_not_nullable
* @property string|null $macaddress_nullable
* @property string $macaddress_not_nullable
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post[] $posts
* @property-read int|null $posts_count
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null($unusedParam)
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post query()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBinaryNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBinaryNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBooleanNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBooleanNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereCharNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereCharNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDateNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDateNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDatetimeNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDatetimeNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDatetimetzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDatetimetzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDecimalNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDecimalNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDoubleNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereDoubleNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereEnumNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereEnumNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereFloatNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereFloatNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereIpaddressNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereIpaddressNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereJsonNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereJsonNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereJsonbNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereJsonbNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereLongTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereLongTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMacaddressNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMacaddressNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMediumIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMediumIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMediumTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereMediumTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereSmallIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereSmallIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereStringNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereStringNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimeNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimeNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimestampNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimestampNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimestamptzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimestamptzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimetzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTimetzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTinyIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTinyIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedBigIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedDecimalNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedDecimalNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedMediumIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedMediumIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedSmallIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedSmallIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedTinyIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedTinyIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUuidNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNullable($value)
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withTrashed()
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withoutTrashed()
* @mixin \Eloquent
*/
class Post extends Model
{
use SoftDeletes;
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
public function scopeNull($query, string $unusedParam)
{
return $query;
}
}
@@ -6,5 +6,4 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
final class CastType
{
}
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
use Eloquent;
use Illuminate\Database\Eloquent\{
Builder as EloquentBuilder,
Collection,
SoftDeletes
};
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Carbon;
@@ -20,6 +18,18 @@ class Post extends Model
{
use SoftDeletes;
/**
* Special hack to avoid code style fixer removing unused imports
* which play a role when generating the snapshot
*/
private $hack = [
Carbon::class,
Collection::class,
Eloquent::class,
EloquentBuilder::class,
QueryBuilder::class,
];
protected $casts = [
'char_not_nullable' => CastType::class,
];
@@ -6,47 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -54,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
use Eloquent;
use Illuminate\Database\Eloquent\{
Builder as EloquentBuilder,
Collection,
SoftDeletes
};
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Carbon;
@@ -180,6 +178,18 @@ class Post extends Model
{
use SoftDeletes;
/**
* Special hack to avoid code style fixer removing unused imports
* which play a role when generating the snapshot
*/
private $hack = [
Carbon::class,
Collection::class,
Eloquent::class,
EloquentBuilder::class,
QueryBuilder::class,
];
protected $casts = [
'char_not_nullable' => CastType::class,
];
@@ -8,5 +8,4 @@ use Illuminate\Database\Eloquent\Builder;
class EMaterialQueryBuilder extends Builder
{
}
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithMixin\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property $someProp
* @method someMethod(string $method)
*/
class Post extends Model
{
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithMixin;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
public function test(): void
{
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write-mixin' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,188 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithMixin\Models;
use Illuminate\Database\Eloquent\Model;
/**
* @property $someProp
* @method someMethod(string $method)
* @mixin IdeHelperPost
*/
class Post extends Model
{
}
<?php
// @formatter:off
/**
* A helper file for your Eloquent Models
* Copy the phpDocs from this file to the correct Model,
* And remove them from this file, to prevent double declarations.
*
* @author Barry vd. Heuvel <barryvdh@gmail.com>
*/
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithMixin\Models{
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithMixin\Models\Post
*
* @property $someProp
* @method someMethod(string $method)
* @property integer $id
* @property string|null $char_nullable
* @property string $char_not_nullable
* @property string|null $string_nullable
* @property string $string_not_nullable
* @property string|null $text_nullable
* @property string $text_not_nullable
* @property string|null $medium_text_nullable
* @property string $medium_text_not_nullable
* @property string|null $long_text_nullable
* @property string $long_text_not_nullable
* @property integer|null $integer_nullable
* @property integer $integer_not_nullable
* @property integer|null $tiny_integer_nullable
* @property integer $tiny_integer_not_nullable
* @property integer|null $small_integer_nullable
* @property integer $small_integer_not_nullable
* @property integer|null $medium_integer_nullable
* @property integer $medium_integer_not_nullable
* @property integer|null $big_integer_nullable
* @property integer $big_integer_not_nullable
* @property integer|null $unsigned_integer_nullable
* @property integer $unsigned_integer_not_nullable
* @property integer|null $unsigned_tiny_integer_nullable
* @property integer $unsigned_tiny_integer_not_nullable
* @property integer|null $unsigned_small_integer_nullable
* @property integer $unsigned_small_integer_not_nullable
* @property integer|null $unsigned_medium_integer_nullable
* @property integer $unsigned_medium_integer_not_nullable
* @property integer|null $unsigned_big_integer_nullable
* @property integer $unsigned_big_integer_not_nullable
* @property float|null $float_nullable
* @property float $float_not_nullable
* @property float|null $double_nullable
* @property float $double_not_nullable
* @property string|null $decimal_nullable
* @property string $decimal_not_nullable
* @property string|null $unsigned_decimal_nullable
* @property string $unsigned_decimal_not_nullable
* @property integer|null $boolean_nullable
* @property integer $boolean_not_nullable
* @property string|null $enum_nullable
* @property string $enum_not_nullable
* @property string|null $json_nullable
* @property string $json_not_nullable
* @property string|null $jsonb_nullable
* @property string $jsonb_not_nullable
* @property string|null $date_nullable
* @property string $date_not_nullable
* @property string|null $datetime_nullable
* @property string $datetime_not_nullable
* @property string|null $datetimetz_nullable
* @property string $datetimetz_not_nullable
* @property string|null $time_nullable
* @property string $time_not_nullable
* @property string|null $timetz_nullable
* @property string $timetz_not_nullable
* @property string|null $timestamp_nullable
* @property string $timestamp_not_nullable
* @property string|null $timestamptz_nullable
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
* @property string $ipaddress_not_nullable
* @property string|null $macaddress_nullable
* @property string $macaddress_not_nullable
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @mixin \Eloquent
*/
class IdeHelperPost extends \Eloquent {}
}
+2 -34
View File
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/Getter/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
use DateTime;
use Illuminate\Database\Eloquent\Model;
class Ignored extends Model
+4 -31
View File
@@ -7,8 +7,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\Ignored;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -16,38 +14,13 @@ class Test extends AbstractModelsCommand
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/Ignored/Models',
],
'ignored_models' => [
Ignored::class
]
$app['config']->set('ide-helper.ignored_models', [
Ignored::class,
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Ignored.php'))
->andReturn(file_get_contents(__DIR__ . '/Models/NotIgnored.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -55,7 +28,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,40 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
final class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/Interfaces/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -47,7 +18,7 @@ final class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
class CastedProperty
{
}
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -6,13 +6,10 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCas
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function setUp(): void
{
parent::setUp();
@@ -22,38 +19,8 @@ class Test extends AbstractModelsCommand
}
}
protected function getEnvironmentSetUp($app)
public function test(): void
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/LaravelCustomCasts/Models',
],
]);
}
public function test_it_parses_casted_properties_correctly(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/CustomCast.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -61,7 +28,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -15,35 +13,11 @@ class Test extends AbstractModelsCommand
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/MagicWhere/Models',
],
'write_model_magic_where' => false
]);
$app['config']->set('ide-helper.write_model_magic_where', false);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -51,8 +25,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,45 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspec
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
use function file_get_contents;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/PHPStormNoInspection/Models',
],
]);
}
public function testNoinspectionNotPresent(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -52,29 +18,12 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
public function testNoinspectionPresent(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -83,7 +32,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,10 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\RelationCountPro
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -17,35 +13,11 @@ class Test extends AbstractModelsCommand
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/RelationCountProperties/Models',
],
'write_model_relation_count_properties' => false
]);
$app['config']->set('ide-helper.write_model_relation_count_properties', false);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -53,8 +25,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
+2 -34
View File
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/Relations/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartRes
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/ResetAndSmartReset/Models',
],
]);
}
public function testNoReset(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,29 +18,12 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
public function testReset(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -81,29 +32,12 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
public function testSmartReset(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -112,7 +46,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/SoftDeletes/Models',
],
]);
}
public function test(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
->once();
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::capture($actualContent)
)
->andReturn(1) // Simulate we wrote _something_ to the file
->once();
$this->instance(Filesystem::class, $mockFilesystem);
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
+22 -10
View File
@@ -1,12 +1,15 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use Barryvdh\LaravelIdeHelper\Method;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Application;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
class MethodTest extends TestCase
{
/**
* Test that we can actually instantiate the class
@@ -31,14 +34,16 @@ class ExampleTest extends TestCase
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
$output = '/**
$output = <<<'DOC'
/**
*
*
* @param string $last
* @param string $first
* @param string $middle
* @static
*/';
*/
DOC;
$this->assertSame($output, $method->getDocComment(''));
$this->assertSame('setName', $method->getName());
$this->assertSame('\\' . ExampleClass::class, $method->getDeclaringClass());
@@ -54,25 +59,32 @@ class ExampleTest extends TestCase
*/
public function testEloquentBuilderOutput()
{
if ((int) Application::VERSION < 8) {
$this->markTestSkipped('This test requires Laravel 8.0 or higher');
}
$reflectionClass = new \ReflectionClass(Builder::class);
$reflectionMethod = $reflectionClass->getMethod('with');
$method = new Method($reflectionMethod, 'Builder', $reflectionClass);
$output = '/**
$output = <<<'DOC'
/**
* Set the relationships that should be eager loaded.
*
* @param mixed $relations
* @param string|array $relations
* @param string|\Closure|null $callback
* @return \Illuminate\Database\Eloquent\Builder|static
* @static
*/';
*/
DOC;
$this->assertSame($output, $method->getDocComment(''));
$this->assertSame('with', $method->getName());
$this->assertSame('\\' . Builder::class, $method->getDeclaringClass());
$this->assertSame('$relations', $method->getParams(true));
$this->assertSame(['$relations'], $method->getParams(false));
$this->assertSame('$relations', $method->getParamsWithDefault(true));
$this->assertSame(['$relations'], $method->getParamsWithDefault(false));
$this->assertSame('$relations, $callback', $method->getParams(true));
$this->assertSame(['$relations', '$callback'], $method->getParams(false));
$this->assertSame('$relations, $callback = null', $method->getParamsWithDefault(true));
$this->assertSame(['$relations', '$callback = null'], $method->getParamsWithDefault(false));
$this->assertSame(true, $method->shouldReturn());
}
+3 -1
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use PHPUnit\Framework\Assert;
@@ -9,7 +11,7 @@ class SnapshotPhpDriver implements Driver
{
public function serialize($data): string
{
return $data;
return (string) $data;
}
public function extension(): string
+3 -1
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use PHPUnit\Framework\Assert;
@@ -9,7 +11,7 @@ class SnapshotTxtDriver implements Driver
{
public function serialize($data): string
{
return $data;
return (string) $data;
}
public function extension(): string
+32
View File
@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Mockery;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Spatie\Snapshots\MatchesSnapshots;
use Symfony\Component\Console\Tester\CommandTester;
@@ -13,6 +15,8 @@ abstract class TestCase extends BaseTestCase
{
use MatchesSnapshots;
protected $mockFilesystemOutput;
/**
* The `CommandTester` is directly returned, use methods like
* `->getDisplay()` or `->getStatusCode()` on it.
@@ -29,6 +33,8 @@ abstract class TestCase extends BaseTestCase
*/
protected function runCommand(Command $command, array $arguments = [], array $interactiveInput = []): CommandTester
{
$this->withoutMockingConsoleOutput();
$command->setLaravel($this->app);
$tester = new CommandTester($command);
@@ -48,4 +54,30 @@ abstract class TestCase extends BaseTestCase
{
$this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver());
}
protected function mockFilesystem()
{
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturnUsing(function ($file) {
return file_get_contents($file);
});
$mockFilesystem
->shouldReceive('put')
->with(
Mockery::any(),
Mockery::any()
)
->andReturnUsing(function ($path, $contents) {
$this->mockFilesystemOutput .= $contents;
return strlen($contents);
});
$this->instance(Filesystem::class, $mockFilesystem);
$this->instance('files', $mockFilesystem);
}
}