mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
affa55122f | ||
|
|
b7d84785b1 | ||
|
|
4df96b5e62 | ||
|
|
3a22b8daf6 | ||
|
|
24596b67f1 | ||
|
|
d978986523 | ||
|
|
3ea232dc3a | ||
|
|
007d3adb68 | ||
|
|
764bc02b84 | ||
|
|
a96add6981 | ||
|
|
4a6d127440 | ||
|
|
1ca875fbca | ||
|
|
462989abd5 | ||
|
|
bd5b6ecee7 | ||
|
|
3b66fea925 | ||
|
|
707ec990e7 | ||
|
|
a49cb46fdf | ||
|
|
a12f902b33 | ||
|
|
8287f02afa | ||
|
|
1d9e82f2b7 | ||
|
|
9599cfbbc9 | ||
|
|
c852650d7e | ||
|
|
ac6fbffac3 | ||
|
|
1ad23fd14c | ||
|
|
444325205e | ||
|
|
c760c9aa0c | ||
|
|
ce4186c1c7 |
@@ -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]>
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
name: Tests
|
name: Tests
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "*"
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
php-tests:
|
php-tests:
|
||||||
@@ -12,11 +20,11 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php: [7.4, 7.3, 7.2]
|
php: [7.4, 7.3, 7.2]
|
||||||
laravel: [7.*, 6.*, 5.5.*]
|
laravel: [8.*, 7.*, 6.*]
|
||||||
dependency-version: [prefer-lowest, prefer-stable]
|
dependency-version: [prefer-lowest, prefer-stable]
|
||||||
exclude:
|
exclude:
|
||||||
- laravel: 5.5.*
|
- laravel: 8.*
|
||||||
php: 7.4
|
php: 7.2
|
||||||
|
|
||||||
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
|
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
|
||||||
|
|
||||||
@@ -29,46 +37,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
php-version: ${{ matrix.php }}
|
php-version: ${{ matrix.php }}
|
||||||
coverage: none
|
coverage: none
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
composer remove phpro/grumphp 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
|
|
||||||
|
|
||||||
- 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
|
tools: composer:v2
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
composer remove phpro/grumphp vimeo/psalm --no-update --dev
|
composer remove vimeo/psalm --no-update --dev
|
||||||
composer update --prefer-dist --no-suggest --no-progress
|
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
|
||||||
|
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
|
||||||
|
|
||||||
- run: composer fix-style
|
- name: Execute Unit Tests
|
||||||
continue-on-error: true
|
run: composer test-ci
|
||||||
|
|
||||||
# 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]>
|
|
||||||
|
|||||||
+7
-4
@@ -1,5 +1,8 @@
|
|||||||
build
|
|
||||||
vendor
|
|
||||||
composer.lock
|
|
||||||
.idea
|
|
||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
|
|
||||||
|
/.idea
|
||||||
|
/.php_cs
|
||||||
|
/.php_cs.cache
|
||||||
|
/.php_cs.tests.cache
|
||||||
|
/composer.lock
|
||||||
|
/vendor
|
||||||
|
|||||||
@@ -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,
|
||||||
|
];
|
||||||
@@ -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');
|
||||||
@@ -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');
|
||||||
@@ -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!
|
||||||
@@ -39,7 +39,7 @@ If for some reason you want manually control this:
|
|||||||
"extra": {
|
"extra": {
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"dont-discover": [
|
"dont-discover": [
|
||||||
"barryvdh/laravel-ide-helper",
|
"barryvdh/laravel-ide-helper"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ If for some reason you want manually control this:
|
|||||||
```php
|
```php
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
if ($this->app->environment() !== 'production') {
|
if ($this->app->isLocal()) {
|
||||||
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
$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.
|
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.
|
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
|
### 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
|
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
|
You can write the comments directly to your Model file, using the `--write (-W)` option, or
|
||||||
force to not write with `--nowrite (-N)`.
|
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.
|
> 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.
|
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.
|
With the `--reset (-R)` option, the existing PHPDocs are ignored, and only the newly found columns/relations are saved as PHPDocs.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php artisan ide-helper:models Post
|
php artisan ide-helper:models "App\Models\Post"
|
||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```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).
|
By default, models in `app/models` are scanned. The optional argument tells what models to use (also outside app/models).
|
||||||
|
|
||||||
```bash
|
```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):
|
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
|
Models can be ignored using the `--ignore (-I)` option
|
||||||
|
|
||||||
```bash
|
```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
|
Or can be ignored by setting the `ignored_models` config
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'ignored_models' => [
|
'ignored_models' => [
|
||||||
Post::class,
|
App\Post::class,
|
||||||
Api\User::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
|
#### 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', '=', '…')`.
|
Eloquent allows calling `where<Attribute>` on your modes, e.g. `Post::whereTitle(…)` and automatically translates this to e.g. `Post::where('title', '=', '…')`.
|
||||||
|
|||||||
+21
-11
@@ -21,22 +21,23 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2",
|
"php": ">=7.2",
|
||||||
|
"ext-json": "*",
|
||||||
"barryvdh/reflection-docblock": "^2.0.6",
|
"barryvdh/reflection-docblock": "^2.0.6",
|
||||||
"composer/composer": "^1.6 || ^2.0@dev",
|
"composer/composer": "^1.6 || ^2.0@dev",
|
||||||
"doctrine/dbal": "~2.3",
|
"doctrine/dbal": "~2.3",
|
||||||
"illuminate/console": "^5.5 || ^6 || ^7",
|
"illuminate/console": "^6 || ^7 || ^8",
|
||||||
"illuminate/filesystem": "^5.5 || ^6 || ^7",
|
"illuminate/filesystem": "^6 || ^7 || ^8",
|
||||||
"illuminate/support": "^5.5 || ^6 || ^7",
|
"illuminate/support": "^6 || ^7 || ^8",
|
||||||
"phpdocumentor/type-resolver": "^1.1.0"
|
"phpdocumentor/type-resolver": "^1.1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/config": "^5.5 || ^6 || ^7",
|
"friendsofphp/php-cs-fixer": "^2",
|
||||||
"illuminate/view": "^5.5 || ^6 || ^7",
|
"illuminate/config": "^6 || ^7 || ^8",
|
||||||
|
"illuminate/view": "^6 || ^7 || ^8",
|
||||||
"mockery/mockery": "^1.3",
|
"mockery/mockery": "^1.3",
|
||||||
"orchestra/testbench": "^3.5 || ^4 || ^5",
|
"orchestra/testbench": "^4 || ^5 || ^6",
|
||||||
"phpro/grumphp": "^0.19.0",
|
"phpunit/phpunit": "^8.5 || ^9",
|
||||||
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
|
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
|
||||||
"squizlabs/php_codesniffer": "^3.5",
|
|
||||||
"vimeo/psalm": "^3.12"
|
"vimeo/psalm": "^3.12"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.7-dev"
|
"dev-master": "2.8-dev"
|
||||||
},
|
},
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
@@ -62,11 +63,20 @@
|
|||||||
"Barryvdh\\LaravelIdeHelper\\Tests\\": "tests"
|
"Barryvdh\\LaravelIdeHelper\\Tests\\": "tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"analyze": "psalm",
|
"analyze": "psalm",
|
||||||
"check-style": "phpcs -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
|
"check-style": [
|
||||||
"fix-style": "phpcbf -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
|
"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": "phpunit",
|
||||||
|
"test-ci": "phpunit -d --without-creating-snapshots",
|
||||||
"test-regenerate": "phpunit -d --update-snapshots"
|
"test-regenerate": "phpunit -d --update-snapshots"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-19
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -98,9 +98,9 @@ return array(
|
|||||||
|
|
||||||
'include_helpers' => false,
|
'include_helpers' => false,
|
||||||
|
|
||||||
'helper_files' => array(
|
'helper_files' => [
|
||||||
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
|
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
|
||||||
),
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -115,9 +115,9 @@ return array(
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'model_locations' => array(
|
'model_locations' => [
|
||||||
'app',
|
'app',
|
||||||
),
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -128,9 +128,9 @@ return array(
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'ignored_models' => array(
|
'ignored_models' => [
|
||||||
|
|
||||||
),
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -141,12 +141,12 @@ return array(
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'extra' => array(
|
'extra' => [
|
||||||
'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
|
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
|
||||||
'Session' => array('Illuminate\Session\Store'),
|
'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".
|
| Cast the given "real type" to the given "type".
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
'type_overrides' => array(
|
'type_overrides' => [
|
||||||
'integer' => 'int',
|
'integer' => 'int',
|
||||||
'boolean' => 'bool',
|
'boolean' => 'bool',
|
||||||
),
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -242,4 +242,15 @@ return array(
|
|||||||
*/
|
*/
|
||||||
'include_class_docblocks' => false,
|
'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
@@ -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
@@ -1,5 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
backupStaticAttributes="false"
|
||||||
colors="true"
|
colors="true"
|
||||||
@@ -14,9 +16,9 @@
|
|||||||
<directory>tests</directory>
|
<directory>tests</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
<coverage>
|
||||||
<whitelist>
|
<include>
|
||||||
<directory suffix=".php">src/</directory>
|
<directory suffix=".php">src/</directory>
|
||||||
</whitelist>
|
</include>
|
||||||
</filter>
|
</coverage>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
+21
-24
@@ -11,13 +11,13 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use ReflectionClass;
|
|
||||||
use Barryvdh\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use Barryvdh\Reflection\DocBlock\Context;
|
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\Serializer as DocBlockSerializer;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Config\Repository as ConfigRepository;
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
class Alias
|
class Alias
|
||||||
{
|
{
|
||||||
@@ -31,12 +31,12 @@ class Alias
|
|||||||
protected $short;
|
protected $short;
|
||||||
protected $namespace = '__root';
|
protected $namespace = '__root';
|
||||||
protected $root = null;
|
protected $root = null;
|
||||||
protected $classes = array();
|
protected $classes = [];
|
||||||
protected $methods = array();
|
protected $methods = [];
|
||||||
protected $usedMethods = array();
|
protected $usedMethods = [];
|
||||||
protected $valid = false;
|
protected $valid = false;
|
||||||
protected $magicMethods = array();
|
protected $magicMethods = [];
|
||||||
protected $interfaces = array();
|
protected $interfaces = [];
|
||||||
protected $phpdoc = null;
|
protected $phpdoc = null;
|
||||||
|
|
||||||
/** @var ConfigRepository */
|
/** @var ConfigRepository */
|
||||||
@@ -50,7 +50,7 @@ class Alias
|
|||||||
* @param array $magicMethods
|
* @param array $magicMethods
|
||||||
* @param array $interfaces
|
* @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->alias = $alias;
|
||||||
$this->magicMethods = $magicMethods;
|
$this->magicMethods = $magicMethods;
|
||||||
@@ -63,12 +63,12 @@ class Alias
|
|||||||
|
|
||||||
$this->detectRoot();
|
$this->detectRoot();
|
||||||
|
|
||||||
if ((!$this->isTrait() && $this->root)) {
|
if (!$this->root || $this->isTrait()) {
|
||||||
$this->valid = true;
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->valid = true;
|
||||||
|
|
||||||
$this->addClass($this->root);
|
$this->addClass($this->root);
|
||||||
$this->detectFake();
|
$this->detectFake();
|
||||||
$this->detectNamespace();
|
$this->detectNamespace();
|
||||||
@@ -82,7 +82,7 @@ class Alias
|
|||||||
|
|
||||||
|
|
||||||
if ($facade === '\Illuminate\Database\Eloquent\Model') {
|
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
|
//When the database connection is not set, some classes will be skipped
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
$this->error(
|
$this->error(
|
||||||
"PDOException: " . $e->getMessage() .
|
'PDOException: ' . $e->getMessage() .
|
||||||
"\nPlease configure your database connection correctly, or use the sqlite memory driver (-M)." .
|
"\nPlease configure your database connection correctly, or use the sqlite memory driver (-M)." .
|
||||||
" Skipping $facade."
|
" Skipping $facade."
|
||||||
);
|
);
|
||||||
} catch (\Exception $e) {
|
} 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()
|
protected function isTrait()
|
||||||
{
|
{
|
||||||
// Check if the facade is not a Trait
|
// Check if the facade is not a Trait
|
||||||
if (function_exists('trait_exists') && trait_exists($this->facade)) {
|
return trait_exists($this->facade);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -416,7 +413,10 @@ class Alias
|
|||||||
{
|
{
|
||||||
$serializer = new DocBlockSerializer(1, $prefix);
|
$serializer = new DocBlockSerializer(1, $prefix);
|
||||||
|
|
||||||
if ($this->phpdoc) {
|
if (!$this->phpdoc) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->config->get('ide-helper.include_class_docblocks')) {
|
if ($this->config->get('ide-helper.include_class_docblocks')) {
|
||||||
// if a class doesn't expose any DocBlock tags
|
// if a class doesn't expose any DocBlock tags
|
||||||
// we can perform reflection on the class and
|
// we can perform reflection on the class and
|
||||||
@@ -431,9 +431,6 @@ class Alias
|
|||||||
return $serializer->getDocComment($this->phpdoc);
|
return $serializer->getDocComment($this->phpdoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes method tags from the doc comment that already appear as functions inside the class.
|
* Removes method tags from the doc comment that already appear as functions inside the class.
|
||||||
* This prevents duplicate function errors in the IDE.
|
* This prevents duplicate function errors in the IDE.
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use Barryvdh\LaravelIdeHelper\Eloquent;
|
|||||||
use Barryvdh\LaravelIdeHelper\Generator;
|
use Barryvdh\LaravelIdeHelper\Generator;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
@@ -25,7 +25,6 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
*/
|
*/
|
||||||
class GeneratorCommand extends Command
|
class GeneratorCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* The console command name.
|
||||||
*
|
*
|
||||||
@@ -59,7 +58,8 @@ class GeneratorCommand extends Command
|
|||||||
* @param \Illuminate\View\Factory $view
|
* @param \Illuminate\View\Factory $view
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/*ConfigRepository */ $config,
|
/*ConfigRepository */
|
||||||
|
$config,
|
||||||
Filesystem $files,
|
Filesystem $files,
|
||||||
/* Illuminate\View\Factory */
|
/* Illuminate\View\Factory */
|
||||||
$view
|
$view
|
||||||
@@ -85,12 +85,14 @@ class GeneratorCommand extends Command
|
|||||||
$this->error(
|
$this->error(
|
||||||
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
|
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
|
||||||
);
|
);
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$filename = $this->argument('filename');
|
$filename = $this->argument('filename');
|
||||||
$format = $this->option('format');
|
$format = $this->option('format');
|
||||||
|
|
||||||
// Strip the php extension
|
// Strip the php extension
|
||||||
if (substr($filename, -4, 4) == '.php') {
|
if (substr($filename, -4, 4) === '.php') {
|
||||||
$filename = substr($filename, 0, -4);
|
$filename = substr($filename, 0, -4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +105,9 @@ class GeneratorCommand extends Command
|
|||||||
|
|
||||||
$helpers = '';
|
$helpers = '';
|
||||||
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
|
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
|
||||||
foreach ($this->config->get('ide-helper.helper_files', array()) as $helper) {
|
foreach ($this->config->get('ide-helper.helper_files', []) as $helper) {
|
||||||
if (file_exists($helper)) {
|
if (file_exists($helper)) {
|
||||||
$helpers .= str_replace(array('<?php', '?>'), '', $this->files->get($helper));
|
$helpers .= str_replace(['<?php', '?>'], '', $this->files->get($helper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -126,17 +128,16 @@ class GeneratorCommand extends Command
|
|||||||
$this->error("The helper file could not be created at $filename");
|
$this->error("The helper file could not be created at $filename");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected function useMemoryDriver()
|
protected function useMemoryDriver()
|
||||||
{
|
{
|
||||||
//Use a sqlite database in memory, to avoid connection errors on Database facades
|
//Use a sqlite database in memory, to avoid connection errors on Database facades
|
||||||
$this->config->set(
|
$this->config->set(
|
||||||
'database.connections.sqlite',
|
'database.connections.sqlite',
|
||||||
array(
|
[
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => ':memory:',
|
'database' => ':memory:',
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
$this->config->set('database.default', 'sqlite');
|
$this->config->set('database.default', 'sqlite');
|
||||||
}
|
}
|
||||||
@@ -150,11 +151,11 @@ class GeneratorCommand extends Command
|
|||||||
{
|
{
|
||||||
$filename = $this->config->get('ide-helper.filename');
|
$filename = $this->config->get('ide-helper.filename');
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
array(
|
[
|
||||||
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
|
'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');
|
$format = $this->config->get('ide-helper.format');
|
||||||
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
|
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
|
['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),
|
['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins],
|
||||||
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
|
['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'],
|
||||||
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*/
|
*/
|
||||||
class MetaCommand extends Command
|
class MetaCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* The console command name.
|
||||||
*
|
*
|
||||||
@@ -58,7 +57,7 @@ class MetaCommand extends Command
|
|||||||
'\App::makeWith(0)',
|
'\App::makeWith(0)',
|
||||||
'\app(0)',
|
'\app(0)',
|
||||||
'\resolve(0)',
|
'\resolve(0)',
|
||||||
'\Psr\Container\ContainerInterface::get',
|
'\Psr\Container\ContainerInterface::get(0)',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +86,7 @@ class MetaCommand extends Command
|
|||||||
|
|
||||||
$this->registerClassAutoloadExceptions();
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
$bindings = array();
|
$bindings = [];
|
||||||
foreach ($this->getAbstracts() as $abstract) {
|
foreach ($this->getAbstracts() as $abstract) {
|
||||||
// Validator and seeder cause problems
|
// Validator and seeder cause problems
|
||||||
if (in_array($abstract, ['validator', 'seeder'])) {
|
if (in_array($abstract, ['validator', 'seeder'])) {
|
||||||
@@ -161,9 +160,9 @@ class MetaCommand extends Command
|
|||||||
{
|
{
|
||||||
$filename = $this->config->get('ide-helper.meta_filename');
|
$filename = $this->config->get('ide-helper.meta_filename');
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
|
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+102
-77
@@ -58,10 +58,11 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
protected $write_model_magic_where;
|
protected $write_model_magic_where;
|
||||||
protected $write_model_relation_count_properties;
|
protected $write_model_relation_count_properties;
|
||||||
protected $properties = array();
|
protected $properties = [];
|
||||||
protected $methods = array();
|
protected $methods = [];
|
||||||
protected $write = false;
|
protected $write = false;
|
||||||
protected $dirs = array();
|
protected $write_mixin = false;
|
||||||
|
protected $dirs = [];
|
||||||
protected $reset;
|
protected $reset;
|
||||||
protected $keep_text;
|
protected $keep_text;
|
||||||
protected $phpstorm_noinspections;
|
protected $phpstorm_noinspections;
|
||||||
@@ -71,7 +72,7 @@ class ModelsCommand extends Command
|
|||||||
protected $nullableColumns = [];
|
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.
|
* determine the actual date class and store it here.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
@@ -96,8 +97,9 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
$this->write = $this->option('write');
|
$this->write = $this->option('write');
|
||||||
|
$this->write_mixin = $this->option('write-mixin');
|
||||||
$this->dirs = array_merge(
|
$this->dirs = array_merge(
|
||||||
$this->laravel['config']->get('ide-helper.model_locations'),
|
$this->laravel['config']->get('ide-helper.model_locations', []),
|
||||||
$this->option('dir')
|
$this->option('dir')
|
||||||
);
|
);
|
||||||
$model = $this->argument('model');
|
$model = $this->argument('model');
|
||||||
@@ -111,6 +113,7 @@ class ModelsCommand extends Command
|
|||||||
$this->write_model_relation_count_properties =
|
$this->write_model_relation_count_properties =
|
||||||
$this->laravel['config']->get('ide-helper.write_model_relation_count_properties', true);
|
$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 filename is default and Write is not specified, ask what to do
|
||||||
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
||||||
if (
|
if (
|
||||||
@@ -128,7 +131,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$content = $this->generateDocs($model, $ignore);
|
$content = $this->generateDocs($model, $ignore);
|
||||||
|
|
||||||
if (!$this->write) {
|
if (!$this->write || $this->write_mixin) {
|
||||||
$written = $this->files->put($filename, $content);
|
$written = $this->files->put($filename, $content);
|
||||||
if ($written !== false) {
|
if ($written !== false) {
|
||||||
$this->info("Model information was written to $filename");
|
$this->info("Model information was written to $filename");
|
||||||
@@ -146,9 +149,9 @@ class ModelsCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function getArguments()
|
protected function getArguments()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', array()),
|
['model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', []],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -158,20 +161,23 @@ class ModelsCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename),
|
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename],
|
||||||
array('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
['dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
||||||
'The model dir, supports glob patterns', array()),
|
'The model dir, supports glob patterns', [], ],
|
||||||
array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
|
['write', 'W', InputOption::VALUE_NONE, 'Write to Model file'],
|
||||||
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
|
['write-mixin', 'M', InputOption::VALUE_NONE,
|
||||||
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
|
"Write models to {$this->filename} and adds @mixin to each model, avoiding IDE duplicate declaration warnings",
|
||||||
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
|
],
|
||||||
array('phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
|
['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 ' .
|
'Add PhpFullyQualifiedNameUsageInspection and PhpUnnecessaryFullyQualifiedNameInspection PHPStorm ' .
|
||||||
'noinspection tags'
|
'noinspection tags',
|
||||||
),
|
],
|
||||||
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
|
['ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateDocs($loadModels, $ignore = '')
|
protected function generateDocs($loadModels, $ignore = '')
|
||||||
@@ -195,7 +201,7 @@ class ModelsCommand extends Command
|
|||||||
if (empty($loadModels)) {
|
if (empty($loadModels)) {
|
||||||
$models = $this->loadModels();
|
$models = $this->loadModels();
|
||||||
} else {
|
} else {
|
||||||
$models = array();
|
$models = [];
|
||||||
foreach ($loadModels as $model) {
|
foreach ($loadModels as $model) {
|
||||||
$models = array_merge($models, explode(',', $model));
|
$models = array_merge($models, explode(',', $model));
|
||||||
}
|
}
|
||||||
@@ -203,7 +209,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$ignore = array_merge(
|
$ignore = array_merge(
|
||||||
explode(',', $ignore),
|
explode(',', $ignore),
|
||||||
$this->laravel['config']->get('ide-helper.ignored_models', array())
|
$this->laravel['config']->get('ide-helper.ignored_models', [])
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($models as $name) {
|
foreach ($models as $name) {
|
||||||
@@ -213,8 +219,8 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->properties = array();
|
$this->properties = [];
|
||||||
$this->methods = array();
|
$this->methods = [];
|
||||||
if (class_exists($name)) {
|
if (class_exists($name)) {
|
||||||
try {
|
try {
|
||||||
// handle abstract classes, interfaces, ...
|
// handle abstract classes, interfaces, ...
|
||||||
@@ -224,9 +230,7 @@ class ModelsCommand extends Command
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
$this->comment("Loading model '$name'", OutputInterface::VERBOSITY_VERBOSE);
|
||||||
$this->comment("Loading model '$name'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$reflectionClass->IsInstantiable()) {
|
if (!$reflectionClass->IsInstantiable()) {
|
||||||
// ignore abstract class or interface
|
// ignore abstract class or interface
|
||||||
@@ -250,7 +254,7 @@ class ModelsCommand extends Command
|
|||||||
$ignore[] = $name;
|
$ignore[] = $name;
|
||||||
$this->nullableColumns = [];
|
$this->nullableColumns = [];
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->error("Exception: " . $e->getMessage() .
|
$this->error('Exception: ' . $e->getMessage() .
|
||||||
"\nCould not analyze class $name.\n\nTrace:\n" .
|
"\nCould not analyze class $name.\n\nTrace:\n" .
|
||||||
$e->getTraceAsString());
|
$e->getTraceAsString());
|
||||||
}
|
}
|
||||||
@@ -270,9 +274,17 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
protected function loadModels()
|
protected function loadModels()
|
||||||
{
|
{
|
||||||
$models = array();
|
$models = [];
|
||||||
foreach ($this->dirs as $dir) {
|
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);
|
$dirs = glob($dir, GLOB_ONLYDIR);
|
||||||
foreach ($dirs as $dir) {
|
foreach ($dirs as $dir) {
|
||||||
if (file_exists($dir)) {
|
if (file_exists($dir)) {
|
||||||
@@ -338,7 +350,8 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
if (!isset($this->properties[$name])) {
|
if (!isset($this->properties[$name])) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$realType = $this->checkForCustomLaravelCasts($realType);
|
$realType = $this->checkForCustomLaravelCasts($realType);
|
||||||
$realType = $this->getTypeOverride($realType);
|
$realType = $this->getTypeOverride($realType);
|
||||||
$this->properties[$name]['type'] = $this->getTypeInModel($model, $realType);
|
$this->properties[$name]['type'] = $this->getTypeInModel($model, $realType);
|
||||||
@@ -348,19 +361,18 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the overide type for the give type.
|
* Returns the override type for the give type.
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
protected function getTypeOverride($type)
|
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)
|
protected function getPropertiesFromTable($model)
|
||||||
{
|
{
|
||||||
$table = $model->getConnection()->getTablePrefix() . $model->getTable();
|
$table = $model->getConnection()->getTablePrefix() . $model->getTable();
|
||||||
$schema = $model->getConnection()->getDoctrineSchemaManager($table);
|
$schema = $model->getConnection()->getDoctrineSchemaManager();
|
||||||
$databasePlatform = $schema->getDatabasePlatform();
|
$databasePlatform = $schema->getDatabasePlatform();
|
||||||
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
|
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
|
||||||
|
|
||||||
$platformName = $databasePlatform->getName();
|
$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) {
|
foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
|
||||||
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
|
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
|
||||||
}
|
}
|
||||||
@@ -388,7 +400,10 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$columns = $schema->listTableColumns($table, $database);
|
$columns = $schema->listTableColumns($table, $database);
|
||||||
|
|
||||||
if ($columns) {
|
if (!$columns) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($columns as $column) {
|
foreach ($columns as $column) {
|
||||||
$name = $column->getName();
|
$name = $column->getName();
|
||||||
if (in_array($name, $model->getDates())) {
|
if (in_array($name, $model->getDates())) {
|
||||||
@@ -445,16 +460,15 @@ class ModelsCommand extends Command
|
|||||||
);
|
);
|
||||||
if ($this->write_model_magic_where) {
|
if ($this->write_model_magic_where) {
|
||||||
$this->setMethod(
|
$this->setMethod(
|
||||||
Str::camel("where_" . $name),
|
Str::camel('where_' . $name),
|
||||||
$this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class)
|
$this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class)
|
||||||
. '|'
|
. '|'
|
||||||
. $this->getClassNameInDestinationFile($model, get_class($model)),
|
. $this->getClassNameInDestinationFile($model, get_class($model)),
|
||||||
array('$value')
|
['$value']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
@@ -513,7 +527,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$this->setMethod(
|
$this->setMethod(
|
||||||
$method,
|
$method,
|
||||||
$builder . "|" . $this->getClassNameInDestinationFile($model, get_class($model))
|
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model))
|
||||||
);
|
);
|
||||||
} elseif (
|
} elseif (
|
||||||
!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
||||||
@@ -544,7 +558,7 @@ class ModelsCommand extends Command
|
|||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||||
|
|
||||||
foreach (
|
foreach (
|
||||||
array(
|
[
|
||||||
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
||||||
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
||||||
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
||||||
@@ -555,8 +569,8 @@ class ModelsCommand extends Command
|
|||||||
'morphTo' => '\Illuminate\Database\Eloquent\Relations\MorphTo',
|
'morphTo' => '\Illuminate\Database\Eloquent\Relations\MorphTo',
|
||||||
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
||||||
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||||
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||||
) as $relation => $impl
|
] as $relation => $impl
|
||||||
) {
|
) {
|
||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
|
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
|
// can cause errors. Since we don't need constraints we can
|
||||||
// disable them when we fetch the relation to avoid errors.
|
// disable them when we fetch the relation to avoid errors.
|
||||||
$relationObj = Relation::noConstraints(function () use ($model, $method) {
|
$relationObj = Relation::noConstraints(function () use ($model, $method) {
|
||||||
|
try {
|
||||||
return $model->$method();
|
return $model->$method();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($relationObj instanceof Relation) {
|
if ($relationObj instanceof Relation) {
|
||||||
@@ -609,7 +627,7 @@ class ModelsCommand extends Command
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} elseif ($relation === "morphTo") {
|
} elseif ($relation === 'morphTo') {
|
||||||
// Model isn't specified because relation is polymorphic
|
// Model isn't specified because relation is polymorphic
|
||||||
$this->setProperty(
|
$this->setProperty(
|
||||||
$method,
|
$method,
|
||||||
@@ -676,7 +694,7 @@ class ModelsCommand extends Command
|
|||||||
protected function setProperty($name, $type = null, $read = null, $write = null, $comment = '', $nullable = false)
|
protected function setProperty($name, $type = null, $read = null, $write = null, $comment = '', $nullable = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->properties[$name])) {
|
if (!isset($this->properties[$name])) {
|
||||||
$this->properties[$name] = array();
|
$this->properties[$name] = [];
|
||||||
$this->properties[$name]['type'] = 'mixed';
|
$this->properties[$name]['type'] = 'mixed';
|
||||||
$this->properties[$name]['read'] = false;
|
$this->properties[$name]['read'] = false;
|
||||||
$this->properties[$name]['write'] = 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);
|
$methods = array_change_key_case($this->methods, CASE_LOWER);
|
||||||
|
|
||||||
if (!isset($methods[strtolower($name)])) {
|
if (!isset($methods[strtolower($name)])) {
|
||||||
$this->methods[$name] = array();
|
$this->methods[$name] = [];
|
||||||
$this->methods[$name]['type'] = $type;
|
$this->methods[$name]['type'] = $type;
|
||||||
$this->methods[$name]['arguments'] = $arguments;
|
$this->methods[$name]['arguments'] = $arguments;
|
||||||
}
|
}
|
||||||
@@ -740,13 +758,13 @@ class ModelsCommand extends Command
|
|||||||
$phpdoc->setText($class);
|
$phpdoc->setText($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
$properties = array();
|
$properties = [];
|
||||||
$methods = array();
|
$methods = [];
|
||||||
foreach ($phpdoc->getTags() as $tag) {
|
foreach ($phpdoc->getTags() as $tag) {
|
||||||
$name = $tag->getName();
|
$name = $tag->getName();
|
||||||
if ($name == "property" || $name == "property-read" || $name == "property-write") {
|
if ($name == 'property' || $name == 'property-read' || $name == 'property-write') {
|
||||||
$properties[] = $tag->getVariableName();
|
$properties[] = $tag->getVariableName();
|
||||||
} elseif ($name == "method") {
|
} elseif ($name == 'method') {
|
||||||
$methods[] = $tag->getMethodName();
|
$methods[] = $tag->getMethodName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -785,37 +803,54 @@ class ModelsCommand extends Command
|
|||||||
$phpdoc->appendTag($tag);
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
|
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
|
||||||
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
|
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
|
||||||
$phpdoc->appendTag(Tag::createInstance("@mixin " . $eloquentClassNameInModel, $phpdoc));
|
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
|
||||||
}
|
}
|
||||||
if ($this->phpstorm_noinspections) {
|
if ($this->phpstorm_noinspections) {
|
||||||
/**
|
/**
|
||||||
* Facades, Eloquent API
|
* Facades, Eloquent API
|
||||||
* @see https://www.jetbrains.com/help/phpstorm/php-fully-qualified-name-usage.html
|
* @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
|
* Relations, other models in the same namespace
|
||||||
* @see https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html
|
* @see https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html
|
||||||
*/
|
*/
|
||||||
$phpdoc->appendTag(
|
$phpdoc->appendTag(
|
||||||
Tag::createInstance("@noinspection PhpUnnecessaryFullyQualifiedNameInspection", $phpdoc)
|
Tag::createInstance('@noinspection PhpUnnecessaryFullyQualifiedNameInspection', $phpdoc)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$serializer = new DocBlockSerializer();
|
$serializer = new DocBlockSerializer();
|
||||||
$serializer->getDocComment($phpdoc);
|
|
||||||
$docComment = $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) {
|
if ($this->write) {
|
||||||
|
$modelDocComment = $this->write_mixin ? $mixinDocComment : $docComment;
|
||||||
$filename = $reflection->getFileName();
|
$filename = $reflection->getFileName();
|
||||||
$contents = $this->files->get($filename);
|
$contents = $this->files->get($filename);
|
||||||
if ($originalDoc) {
|
if ($originalDoc) {
|
||||||
$contents = str_replace($originalDoc, $docComment, $contents);
|
$contents = str_replace($originalDoc, $modelDocComment, $contents);
|
||||||
} else {
|
} else {
|
||||||
$replace = "{$docComment}\n";
|
$replace = "{$modelDocComment}\n";
|
||||||
$pos = strpos($contents, "final class {$classname}") ?: strpos($contents, "class {$classname}");
|
$pos = strpos($contents, "final class {$classname}") ?: strpos($contents, "class {$classname}");
|
||||||
if ($pos !== false) {
|
if ($pos !== false) {
|
||||||
$contents = substr_replace($contents, $replace, $pos, 0);
|
$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 ";
|
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent ";
|
||||||
|
|
||||||
if ($interfaceNames) {
|
if ($interfaceNames) {
|
||||||
@@ -844,14 +880,12 @@ class ModelsCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function getParameters($method)
|
public function getParameters($method)
|
||||||
{
|
{
|
||||||
//Loop through the default values for paremeters, and make the correct output string
|
//Loop through the default values for parameters, and make the correct output string
|
||||||
$params = array();
|
$paramsWithDefault = [];
|
||||||
$paramsWithDefault = array();
|
|
||||||
/** @var \ReflectionParameter $param */
|
/** @var \ReflectionParameter $param */
|
||||||
foreach ($method->getParameters() as $param) {
|
foreach ($method->getParameters() as $param) {
|
||||||
$paramClass = $param->getClass();
|
$paramClass = $param->getClass();
|
||||||
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
|
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
|
||||||
$params[] = $paramStr;
|
|
||||||
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
|
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
|
||||||
$default = $param->getDefaultValue();
|
$default = $param->getDefaultValue();
|
||||||
if (is_bool($default)) {
|
if (is_bool($default)) {
|
||||||
@@ -1034,11 +1068,6 @@ class ModelsCommand extends Command
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param object|ReflectionClass $model
|
|
||||||
* @param string $type
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getTypeInModel(object $model, ?string $type): ?string
|
protected function getTypeInModel(object $model, ?string $type): ?string
|
||||||
{
|
{
|
||||||
if ($type === null) {
|
if ($type === null) {
|
||||||
@@ -1052,11 +1081,6 @@ class ModelsCommand extends Command
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param object|ReflectionClass $model
|
|
||||||
* @param string $className
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getClassNameInDestinationFile(object $model, string $className): string
|
protected function getClassNameInDestinationFile(object $model, string $className): string
|
||||||
{
|
{
|
||||||
$reflection = $model instanceof ReflectionClass
|
$reflection = $model instanceof ReflectionClass
|
||||||
@@ -1067,8 +1091,9 @@ class ModelsCommand extends Command
|
|||||||
$className = trim($className, '\\');
|
$className = trim($className, '\\');
|
||||||
$writingToExternalFile = !$this->write;
|
$writingToExternalFile = !$this->write;
|
||||||
$classIsNotInExternalFile = $reflection->getName() !== $className;
|
$classIsNotInExternalFile = $reflection->getName() !== $className;
|
||||||
|
$forceFQCN = $this->laravel['config']->get('ide-helper.force_fqn', false);
|
||||||
|
|
||||||
if ($writingToExternalFile && $classIsNotInExternalFile) {
|
if (($writingToExternalFile && $classIsNotInExternalFile) || $forceFQCN) {
|
||||||
return '\\' . $className;
|
return '\\' . $className;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-16
@@ -8,12 +8,12 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Barryvdh\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use Barryvdh\Reflection\DocBlock\Context;
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
use Barryvdh\Reflection\DocBlock\Tag;
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
class Eloquent
|
class Eloquent
|
||||||
{
|
{
|
||||||
@@ -85,25 +85,29 @@ class Eloquent
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filename = $reflection->getFileName();
|
$filename = $reflection->getFileName();
|
||||||
if ($filename) {
|
if (!$filename) {
|
||||||
|
$command->error('Filename not found ' . $class);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$contents = $files->get($filename);
|
$contents = $files->get($filename);
|
||||||
if ($contents) {
|
if (!$contents) {
|
||||||
|
$command->error('No file contents found ' . $filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
||||||
if ($count > 0) {
|
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);
|
$command->error('Content did not change ' . $contents);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$command->error('No file contents found ' . $filename);
|
if (!$files->put($filename, $contents)) {
|
||||||
}
|
$command->error('File write failed to ' . $filename);
|
||||||
} else {
|
return;
|
||||||
$command->error('Filename not found ' . $class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$command->info('Wrote expected docblock to ' . $filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use ReflectionClass;
|
|||||||
|
|
||||||
class Factories
|
class Factories
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function all()
|
public static function all()
|
||||||
{
|
{
|
||||||
$factories = [];
|
$factories = [];
|
||||||
|
|||||||
+80
-22
@@ -11,9 +11,10 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
use Illuminate\Foundation\AliasLoader;
|
use Illuminate\Foundation\AliasLoader;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Traits\Macroable;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@@ -28,9 +29,9 @@ class Generator
|
|||||||
/** @var \Symfony\Component\Console\Output\OutputInterface */
|
/** @var \Symfony\Component\Console\Output\OutputInterface */
|
||||||
protected $output;
|
protected $output;
|
||||||
|
|
||||||
protected $extra = array();
|
protected $extra = [];
|
||||||
protected $magic = array();
|
protected $magic = [];
|
||||||
protected $interfaces = array();
|
protected $interfaces = [];
|
||||||
protected $helpers;
|
protected $helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +41,10 @@ class Generator
|
|||||||
* @param string $helpers
|
* @param string $helpers
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/*ConfigRepository */ $config,
|
/*ConfigRepository */
|
||||||
/* Illuminate\View\Factory */ $view,
|
$config,
|
||||||
|
/* Illuminate\View\Factory */
|
||||||
|
$view,
|
||||||
OutputInterface $output = null,
|
OutputInterface $output = null,
|
||||||
$helpers = ''
|
$helpers = ''
|
||||||
) {
|
) {
|
||||||
@@ -93,16 +96,16 @@ class Generator
|
|||||||
|
|
||||||
public function generateJsonHelper()
|
public function generateJsonHelper()
|
||||||
{
|
{
|
||||||
$classes = array();
|
$classes = [];
|
||||||
foreach ($this->getValidAliases() as $aliases) {
|
foreach ($this->getValidAliases() as $aliases) {
|
||||||
foreach ($aliases as $alias) {
|
foreach ($aliases as $alias) {
|
||||||
$functions = array();
|
$functions = [];
|
||||||
foreach ($alias->getMethods() as $method) {
|
foreach ($alias->getMethods() as $method) {
|
||||||
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
|
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
|
||||||
}
|
}
|
||||||
$classes[$alias->getAlias()] = array(
|
$classes[$alias->getAlias()] = [
|
||||||
'functions' => $functions,
|
'functions' => $functions,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,11 +114,11 @@ class Generator
|
|||||||
$flags |= JSON_PRETTY_PRINT;
|
$flags |= JSON_PRETTY_PRINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return json_encode(array(
|
return json_encode([
|
||||||
'php' => array(
|
'php' => [
|
||||||
'classes' => $classes,
|
'classes' => $classes,
|
||||||
),
|
],
|
||||||
), $flags);
|
], $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function detectDrivers()
|
protected function detectDrivers()
|
||||||
@@ -129,7 +132,7 @@ class Generator
|
|||||||
&& app()->bound('auth')
|
&& app()->bound('auth')
|
||||||
) {
|
) {
|
||||||
$class = get_class(\Auth::guard());
|
$class = get_class(\Auth::guard());
|
||||||
$this->extra['Auth'] = array($class);
|
$this->extra['Auth'] = [$class];
|
||||||
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -138,7 +141,7 @@ class Generator
|
|||||||
try {
|
try {
|
||||||
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
||||||
$class = get_class(\DB::connection());
|
$class = get_class(\DB::connection());
|
||||||
$this->extra['DB'] = array($class);
|
$this->extra['DB'] = [$class];
|
||||||
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -148,7 +151,7 @@ class Generator
|
|||||||
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
||||||
$driver = get_class(\Cache::driver());
|
$driver = get_class(\Cache::driver());
|
||||||
$store = get_class(\Cache::getStore());
|
$store = get_class(\Cache::getStore());
|
||||||
$this->extra['Cache'] = array($driver, $store);
|
$this->extra['Cache'] = [$driver, $store];
|
||||||
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
|
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -157,7 +160,7 @@ class Generator
|
|||||||
try {
|
try {
|
||||||
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
||||||
$class = get_class(\Queue::connection());
|
$class = get_class(\Queue::connection());
|
||||||
$this->extra['Queue'] = array($class);
|
$this->extra['Queue'] = [$class];
|
||||||
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -166,7 +169,7 @@ class Generator
|
|||||||
try {
|
try {
|
||||||
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)) {
|
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)) {
|
||||||
$class = get_class(\SSH::connection());
|
$class = get_class(\SSH::connection());
|
||||||
$this->extra['SSH'] = array($class);
|
$this->extra['SSH'] = [$class];
|
||||||
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -175,7 +178,7 @@ class Generator
|
|||||||
try {
|
try {
|
||||||
if (class_exists('Storage') && is_a('Storage', '\Illuminate\Support\Facades\Storage', true)) {
|
if (class_exists('Storage') && is_a('Storage', '\Illuminate\Support\Facades\Storage', true)) {
|
||||||
$class = get_class(\Storage::disk());
|
$class = get_class(\Storage::disk());
|
||||||
$this->extra['Storage'] = array($class);
|
$this->extra['Storage'] = [$class];
|
||||||
$this->interfaces['\Illuminate\Contracts\Filesystem\Filesystem'] = $class;
|
$this->interfaces['\Illuminate\Contracts\Filesystem\Filesystem'] = $class;
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -198,7 +201,7 @@ class Generator
|
|||||||
continue;
|
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);
|
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
|
||||||
if ($alias->isValid()) {
|
if ($alias->isValid()) {
|
||||||
//Add extra methods, from other classes (magic static calls)
|
//Add extra methods, from other classes (magic static calls)
|
||||||
@@ -220,7 +223,11 @@ class Generator
|
|||||||
*/
|
*/
|
||||||
protected function getAliasesByExtendsNamespace()
|
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();
|
return $alias->getExtendsNamespace();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -291,4 +298,55 @@ class Generator
|
|||||||
echo $string . "\r\n";
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\View\Engines\EngineResolver;
|
use Illuminate\View\Engines\EngineResolver;
|
||||||
use Illuminate\View\Engines\PhpEngine;
|
use Illuminate\View\Engines\PhpEngine;
|
||||||
@@ -23,7 +24,6 @@ use Illuminate\View\FileViewFinder;
|
|||||||
|
|
||||||
class IdeHelperServiceProvider extends ServiceProvider
|
class IdeHelperServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if loading of the provider is deferred.
|
* Indicates if loading of the provider is deferred.
|
||||||
*
|
*
|
||||||
@@ -86,7 +86,7 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
$this->app->singleton(
|
$this->app->singleton(
|
||||||
'command.ide-helper.eloquent',
|
'command.ide-helper.eloquent',
|
||||||
function ($app) use ($localViewFactory) {
|
function ($app) {
|
||||||
return new EloquentCommand($app['files']);
|
return new EloquentCommand($app['files']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -106,7 +106,7 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function provides()
|
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 = new EngineResolver();
|
||||||
$resolver->register('php', function () {
|
$resolver->register('php', function () {
|
||||||
|
if ((int) Application::VERSION < 8) {
|
||||||
return new PhpEngine();
|
return new PhpEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PhpEngine($this->app['files']);
|
||||||
});
|
});
|
||||||
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
|
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
|
||||||
$factory = new Factory($resolver, $finder, $this->app['events']);
|
$factory = new Factory($resolver, $finder, $this->app['events']);
|
||||||
|
|||||||
+21
-2
@@ -21,7 +21,7 @@ class Macro extends Method
|
|||||||
$alias,
|
$alias,
|
||||||
$class,
|
$class,
|
||||||
$methodName = null,
|
$methodName = null,
|
||||||
$interfaces = array()
|
$interfaces = []
|
||||||
) {
|
) {
|
||||||
parent::__construct($method, $alias, $class, $methodName, $interfaces);
|
parent::__construct($method, $alias, $class, $methodName, $interfaces);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,26 @@ class Macro extends Method
|
|||||||
*/
|
*/
|
||||||
protected function initPhpDoc($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}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+23
-21
@@ -13,10 +13,10 @@ namespace Barryvdh\LaravelIdeHelper;
|
|||||||
|
|
||||||
use Barryvdh\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use Barryvdh\Reflection\DocBlock\Context;
|
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\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\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@@ -32,9 +32,9 @@ class Method
|
|||||||
protected $declaringClassName;
|
protected $declaringClassName;
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $namespace;
|
protected $namespace;
|
||||||
protected $params = array();
|
protected $params = [];
|
||||||
protected $params_with_default = array();
|
protected $params_with_default = [];
|
||||||
protected $interfaces = array();
|
protected $interfaces = [];
|
||||||
protected $real_name;
|
protected $real_name;
|
||||||
protected $return = null;
|
protected $return = null;
|
||||||
protected $root;
|
protected $root;
|
||||||
@@ -46,7 +46,7 @@ class Method
|
|||||||
* @param string|null $methodName
|
* @param string|null $methodName
|
||||||
* @param array $interfaces
|
* @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->method = $method;
|
||||||
$this->interfaces = $interfaces;
|
$this->interfaces = $interfaces;
|
||||||
@@ -119,7 +119,7 @@ class Method
|
|||||||
*/
|
*/
|
||||||
public function isInstanceCall()
|
public function isInstanceCall()
|
||||||
{
|
{
|
||||||
return ! ($this->method->isClosure() || $this->method->isStatic());
|
return !($this->method->isClosure() || $this->method->isStatic());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,9 +251,14 @@ class Method
|
|||||||
*/
|
*/
|
||||||
protected function normalizeReturn(DocBlock $phpdoc)
|
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');
|
$returnTags = $phpdoc->getTagsByName('return');
|
||||||
if ($returnTags) {
|
|
||||||
|
if (count($returnTags) === 0) {
|
||||||
|
$this->return = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var ReturnTag $tag */
|
/** @var ReturnTag $tag */
|
||||||
$tag = reset($returnTags);
|
$tag = reset($returnTags);
|
||||||
// Get the expanded type
|
// Get the expanded type
|
||||||
@@ -273,13 +278,10 @@ class Method
|
|||||||
? $tag->setType($this->root . '|static')
|
? $tag->setType($this->root . '|static')
|
||||||
: $tag->setType($this->root);
|
: $tag->setType($this->root);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$this->return = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert keywwords that are incorrect.
|
* Convert keywords that are incorrect.
|
||||||
*
|
*
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return string
|
* @return string
|
||||||
@@ -300,7 +302,7 @@ class Method
|
|||||||
*/
|
*/
|
||||||
public function shouldReturn()
|
public function shouldReturn()
|
||||||
{
|
{
|
||||||
if ($this->return !== "void" && $this->method->name !== "__construct") {
|
if ($this->return !== 'void' && $this->method->name !== '__construct') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,13 +313,13 @@ class Method
|
|||||||
* Get the parameters and format them correctly
|
* Get the parameters and format them correctly
|
||||||
*
|
*
|
||||||
* @param \ReflectionMethod $method
|
* @param \ReflectionMethod $method
|
||||||
* @return array
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getParameters($method)
|
public function getParameters($method)
|
||||||
{
|
{
|
||||||
//Loop through the default values for paremeters, and make the correct output string
|
//Loop through the default values for parameters, and make the correct output string
|
||||||
$params = array();
|
$params = [];
|
||||||
$paramsWithDefault = array();
|
$paramsWithDefault = [];
|
||||||
foreach ($method->getParameters() as $param) {
|
foreach ($method->getParameters() as $param) {
|
||||||
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
|
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
|
||||||
$params[] = $paramStr;
|
$params[] = $paramStr;
|
||||||
@@ -366,9 +368,9 @@ class Method
|
|||||||
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
||||||
//Not at the end yet, try another parent/interface..
|
//Not at the end yet, try another parent/interface..
|
||||||
return $this->getInheritDoc($method);
|
return $this->getInheritDoc($method);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return $phpdoc;
|
return $phpdoc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
|
||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
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;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
|
|
||||||
abstract class AbstractModelsCommand extends TestCase
|
abstract class AbstractModelsCommand extends TestCase
|
||||||
{
|
{
|
||||||
@@ -13,14 +14,21 @@ abstract class AbstractModelsCommand extends TestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
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->loadMigrationsFrom(__DIR__ . '/migrations');
|
||||||
$this->artisan('migrate');
|
$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)
|
protected function getEnvironmentSetUp($app)
|
||||||
@@ -35,5 +43,18 @@ abstract class AbstractModelsCommand extends TestCase
|
|||||||
'database' => ':memory:',
|
'database' => ':memory:',
|
||||||
'prefix' => '',
|
'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
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
class SimpleCollection extends Collection
|
class SimpleCollection extends Collection
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,44 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
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
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
@@ -28,38 +26,8 @@ class Test extends AbstractModelsCommand
|
|||||||
parent::tearDown();
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -67,7 +35,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$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\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
@@ -15,36 +13,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.model_camel_case_properties', true);
|
||||||
'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,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -52,7 +25,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$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();
|
||||||
|
}
|
||||||
|
}
|
||||||
+184
@@ -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
|
final class CastType
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
use Illuminate\Database\Eloquent\{
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
Builder as EloquentBuilder,
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
Collection,
|
|
||||||
SoftDeletes
|
|
||||||
};
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
@@ -20,6 +18,18 @@ class Post extends Model
|
|||||||
{
|
{
|
||||||
use SoftDeletes;
|
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 = [
|
protected $casts = [
|
||||||
'char_not_nullable' => CastType::class,
|
'char_not_nullable' => CastType::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -6,47 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
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
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -54,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
use Illuminate\Database\Eloquent\{
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
Builder as EloquentBuilder,
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
Collection,
|
|
||||||
SoftDeletes
|
|
||||||
};
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
@@ -180,6 +178,18 @@ class Post extends Model
|
|||||||
{
|
{
|
||||||
use SoftDeletes;
|
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 = [
|
protected $casts = [
|
||||||
'char_not_nullable' => CastType::class,
|
'char_not_nullable' => CastType::class,
|
||||||
];
|
];
|
||||||
|
|||||||
-1
@@ -8,5 +8,4 @@ use Illuminate\Database\Eloquent\Builder;
|
|||||||
|
|
||||||
class EMaterialQueryBuilder extends Builder
|
class EMaterialQueryBuilder extends Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
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
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$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 {}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter;
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Ignored extends Model
|
class Ignored extends Model
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\Ignored;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\Ignored;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
@@ -16,38 +14,13 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.ignored_models', [
|
||||||
'model_locations' => [
|
Ignored::class,
|
||||||
// This is calculated from the base_path() which points to
|
|
||||||
// vendor/orchestra/testbench-core/laravel
|
|
||||||
'/../../../../tests/Console/ModelsCommand/Ignored/Models',
|
|
||||||
],
|
|
||||||
'ignored_models' => [
|
|
||||||
Ignored::class
|
|
||||||
]
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -55,7 +28,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,40 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces;
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
final class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -47,7 +18,7 @@ final class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
class CastedProperty
|
class CastedProperty
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
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\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -61,7 +28,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere;
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
@@ -15,35 +13,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.write_model_magic_where', false);
|
||||||
'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
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -51,8 +25,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
|
$this->assertMatchesMockedSnapshot();
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,45 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspec
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
use function file_get_contents;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -52,29 +18,12 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoinspectionPresent(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -83,7 +32,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\RelationCountPro
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
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
|
class Test extends AbstractModelsCommand
|
||||||
{
|
{
|
||||||
@@ -17,35 +13,11 @@ class Test extends AbstractModelsCommand
|
|||||||
{
|
{
|
||||||
parent::getEnvironmentSetUp($app);
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
$app['config']->set('ide-helper', [
|
$app['config']->set('ide-helper.write_model_relation_count_properties', false);
|
||||||
'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
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -53,8 +25,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
|
$this->assertMatchesMockedSnapshot();
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations;
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartRes
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,29 +18,12 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReset(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -81,29 +32,12 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSmartReset(): void
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -112,7 +46,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes;
|
|||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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
|
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);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
$tester = $this->runCommand($command, [
|
$tester = $this->runCommand($command, [
|
||||||
@@ -50,7 +18,7 @@ class Test extends AbstractModelsCommand
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertEmpty($tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
$this->assertMatchesPhpSnapshot($actualContent);
|
$this->assertMatchesMockedSnapshot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-10
@@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Method;
|
use Barryvdh\LaravelIdeHelper\Method;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
class MethodTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test that we can actually instantiate the class
|
* Test that we can actually instantiate the class
|
||||||
@@ -31,14 +34,16 @@ class ExampleTest extends TestCase
|
|||||||
|
|
||||||
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
||||||
|
|
||||||
$output = '/**
|
$output = <<<'DOC'
|
||||||
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string $last
|
* @param string $last
|
||||||
* @param string $first
|
* @param string $first
|
||||||
* @param string $middle
|
* @param string $middle
|
||||||
* @static
|
* @static
|
||||||
*/';
|
*/
|
||||||
|
DOC;
|
||||||
$this->assertSame($output, $method->getDocComment(''));
|
$this->assertSame($output, $method->getDocComment(''));
|
||||||
$this->assertSame('setName', $method->getName());
|
$this->assertSame('setName', $method->getName());
|
||||||
$this->assertSame('\\' . ExampleClass::class, $method->getDeclaringClass());
|
$this->assertSame('\\' . ExampleClass::class, $method->getDeclaringClass());
|
||||||
@@ -54,25 +59,32 @@ class ExampleTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testEloquentBuilderOutput()
|
public function testEloquentBuilderOutput()
|
||||||
{
|
{
|
||||||
|
if ((int) Application::VERSION < 8) {
|
||||||
|
$this->markTestSkipped('This test requires Laravel 8.0 or higher');
|
||||||
|
}
|
||||||
|
|
||||||
$reflectionClass = new \ReflectionClass(Builder::class);
|
$reflectionClass = new \ReflectionClass(Builder::class);
|
||||||
$reflectionMethod = $reflectionClass->getMethod('with');
|
$reflectionMethod = $reflectionClass->getMethod('with');
|
||||||
|
|
||||||
$method = new Method($reflectionMethod, 'Builder', $reflectionClass);
|
$method = new Method($reflectionMethod, 'Builder', $reflectionClass);
|
||||||
|
|
||||||
$output = '/**
|
$output = <<<'DOC'
|
||||||
|
/**
|
||||||
* Set the relationships that should be eager loaded.
|
* 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
|
* @return \Illuminate\Database\Eloquent\Builder|static
|
||||||
* @static
|
* @static
|
||||||
*/';
|
*/
|
||||||
|
DOC;
|
||||||
$this->assertSame($output, $method->getDocComment(''));
|
$this->assertSame($output, $method->getDocComment(''));
|
||||||
$this->assertSame('with', $method->getName());
|
$this->assertSame('with', $method->getName());
|
||||||
$this->assertSame('\\' . Builder::class, $method->getDeclaringClass());
|
$this->assertSame('\\' . Builder::class, $method->getDeclaringClass());
|
||||||
$this->assertSame('$relations', $method->getParams(true));
|
$this->assertSame('$relations, $callback', $method->getParams(true));
|
||||||
$this->assertSame(['$relations'], $method->getParams(false));
|
$this->assertSame(['$relations', '$callback'], $method->getParams(false));
|
||||||
$this->assertSame('$relations', $method->getParamsWithDefault(true));
|
$this->assertSame('$relations, $callback = null', $method->getParamsWithDefault(true));
|
||||||
$this->assertSame(['$relations'], $method->getParamsWithDefault(false));
|
$this->assertSame(['$relations', '$callback = null'], $method->getParamsWithDefault(false));
|
||||||
$this->assertSame(true, $method->shouldReturn());
|
$this->assertSame(true, $method->shouldReturn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
@@ -9,7 +11,7 @@ class SnapshotPhpDriver implements Driver
|
|||||||
{
|
{
|
||||||
public function serialize($data): string
|
public function serialize($data): string
|
||||||
{
|
{
|
||||||
return $data;
|
return (string) $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function extension(): string
|
public function extension(): string
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
@@ -9,7 +11,7 @@ class SnapshotTxtDriver implements Driver
|
|||||||
{
|
{
|
||||||
public function serialize($data): string
|
public function serialize($data): string
|
||||||
{
|
{
|
||||||
return $data;
|
return (string) $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function extension(): string
|
public function extension(): string
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace Barryvdh\LaravelIdeHelper\Tests;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
use Orchestra\Testbench\TestCase as BaseTestCase;
|
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||||
use Spatie\Snapshots\MatchesSnapshots;
|
use Spatie\Snapshots\MatchesSnapshots;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
@@ -13,6 +15,8 @@ abstract class TestCase extends BaseTestCase
|
|||||||
{
|
{
|
||||||
use MatchesSnapshots;
|
use MatchesSnapshots;
|
||||||
|
|
||||||
|
protected $mockFilesystemOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `CommandTester` is directly returned, use methods like
|
* The `CommandTester` is directly returned, use methods like
|
||||||
* `->getDisplay()` or `->getStatusCode()` on it.
|
* `->getDisplay()` or `->getStatusCode()` on it.
|
||||||
@@ -29,6 +33,8 @@ abstract class TestCase extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
protected function runCommand(Command $command, array $arguments = [], array $interactiveInput = []): CommandTester
|
protected function runCommand(Command $command, array $arguments = [], array $interactiveInput = []): CommandTester
|
||||||
{
|
{
|
||||||
|
$this->withoutMockingConsoleOutput();
|
||||||
|
|
||||||
$command->setLaravel($this->app);
|
$command->setLaravel($this->app);
|
||||||
|
|
||||||
$tester = new CommandTester($command);
|
$tester = new CommandTester($command);
|
||||||
@@ -48,4 +54,30 @@ abstract class TestCase extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver());
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user