mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f677edc14 | ||
|
|
1b611d7f80 | ||
|
|
a233d5bd5a | ||
|
|
cfa9a81d65 | ||
|
|
dcf76c1a81 | ||
|
|
bef8158d02 | ||
|
|
8381a2ebdd | ||
|
|
6bab45b8c2 | ||
|
|
2617352869 | ||
|
|
ce275a9bf2 | ||
|
|
b7b835bf09 | ||
|
|
b0481aef33 | ||
|
|
f80887914b | ||
|
|
f4ae4c4b45 | ||
|
|
6a27c5df68 | ||
|
|
7be6afbe5f | ||
|
|
b72689755b | ||
|
|
3cc7d7ccf6 | ||
|
|
18588eacf3 | ||
|
|
da59650fb2 | ||
|
|
fe2890925e | ||
|
|
1d1484025c | ||
|
|
0692626c41 | ||
|
|
90437012b8 | ||
|
|
e743f44011 | ||
|
|
edd69c5e05 | ||
|
|
68d3d19298 | ||
|
|
75149ddb1f | ||
|
|
e020e265a4 | ||
|
|
6af1f32d96 | ||
|
|
972befd7aa | ||
|
|
805c4e9a2a | ||
|
|
c0bb9ee1fd | ||
|
|
d9a731daba | ||
|
|
d3b24ffeae | ||
|
|
015cc6c493 | ||
|
|
44f289f76a | ||
|
|
fb0c576806 | ||
|
|
0d1dd2182b | ||
|
|
027e58fd56 | ||
|
|
a46e3b4505 | ||
|
|
e7734d3c20 | ||
|
|
fcf3fae860 | ||
|
|
b91b959364 | ||
|
|
9b0fbb4467 | ||
|
|
6c8e847430 | ||
|
|
25b61c56fe | ||
|
|
428d32cebd | ||
|
|
51a72d7766 | ||
|
|
d200f2284b | ||
|
|
8faae38655 |
+1
-2
@@ -6,5 +6,4 @@
|
|||||||
/.gitignore export-ignore
|
/.gitignore export-ignore
|
||||||
/.travis.yml export-ignore
|
/.travis.yml export-ignore
|
||||||
/phpunit.xml.dist export-ignore
|
/phpunit.xml.dist export-ignore
|
||||||
/.scrutinizer.yml export-ignore
|
/tests export-ignore
|
||||||
/tests export-ignore
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: barryvdh
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
@@ -2,3 +2,4 @@ build
|
|||||||
vendor
|
vendor
|
||||||
composer.lock
|
composer.lock
|
||||||
.idea
|
.idea
|
||||||
|
.phpunit.result.cache
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
filter:
|
|
||||||
excluded_paths: [tests/*]
|
|
||||||
|
|
||||||
checks:
|
|
||||||
php:
|
|
||||||
remove_extra_empty_lines: true
|
|
||||||
remove_php_closing_tag: true
|
|
||||||
remove_trailing_whitespace: true
|
|
||||||
fix_use_statements:
|
|
||||||
remove_unused: true
|
|
||||||
preserve_multiple: false
|
|
||||||
preserve_blanklines: true
|
|
||||||
order_alphabetically: true
|
|
||||||
fix_php_opening_tag: true
|
|
||||||
fix_linefeed: true
|
|
||||||
fix_line_ending: true
|
|
||||||
fix_identation_4spaces: true
|
|
||||||
fix_doc_comments: true
|
|
||||||
|
|
||||||
tools:
|
|
||||||
external_code_coverage:
|
|
||||||
timeout: 600
|
|
||||||
runs: 3
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
preset: psr2
|
|
||||||
+53
-13
@@ -1,27 +1,67 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
|
||||||
- 7.0
|
|
||||||
- 7.1
|
|
||||||
- 7.2
|
|
||||||
|
|
||||||
# This triggers builds to run on the new TravisCI infrastructure.
|
|
||||||
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
## Cache composer
|
## Cache composer
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.composer/cache
|
- $HOME/.composer/cache
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- RUN_PHPCS=0
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 7.0
|
- php: '7.2'
|
||||||
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.2'
|
||||||
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.2'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.2'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.2'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.2'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.3'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='5.5.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-lowest'
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='^6.0' COMPOSER_FLAGS='--prefer-stable' RUN_PHPCS=1
|
||||||
|
- php: '7.4'
|
||||||
|
env: LARAVEL='^7.0' COMPOSER_FLAGS='--prefer-stable' RUN_PHPCS=1
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- travis_wait 20 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
|
- phpenv config-rm xdebug.ini || true
|
||||||
|
|
||||||
|
install:
|
||||||
|
- travis_retry composer remove phpro/grumphp --no-interaction --no-update --dev
|
||||||
|
- composer require "illuminate/support:${LARAVEL}" --no-interaction --no-update
|
||||||
|
- composer require "illuminate/console:${LARAVEL}" --no-interaction --no-update
|
||||||
|
- composer require "illuminate/filesystem:${LARAVEL}" --no-interaction --no-update
|
||||||
|
- composer require --dev "illuminate/config:${LARAVEL}" --no-interaction --no-update
|
||||||
|
- composer require --dev "illuminate/view:${LARAVEL}" --no-interaction --no-update
|
||||||
|
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist --no-suggest
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpcs --standard=psr2 src/
|
|
||||||
- vendor/bin/phpunit
|
- vendor/bin/phpunit
|
||||||
|
- if [[ $RUN_PHPCS = 1 ]]; then vendor/bin/phpcs --standard=psr2 src/; fi
|
||||||
|
|||||||
+11
-11
@@ -10,21 +10,21 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7",
|
"php": ">=7.2",
|
||||||
"illuminate/support": "^5.5|^6",
|
"illuminate/support": "^5.5|^6|^7",
|
||||||
"illuminate/console": "^5.5|^6",
|
"illuminate/console": "^5.5|^6|^7",
|
||||||
"illuminate/filesystem": "^5.5|^6",
|
"illuminate/filesystem": "^5.5|^6|^7",
|
||||||
"barryvdh/reflection-docblock": "^2.0.6",
|
"barryvdh/reflection-docblock": "^2.0.6",
|
||||||
"composer/composer": "^1.6",
|
"composer/composer": "^1.6",
|
||||||
"doctrine/dbal": "~2.3"
|
"doctrine/dbal": "~2.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/config": "^5.5|^6",
|
"illuminate/config": "^5.5|^6|^7",
|
||||||
"illuminate/view": "^5.5|^6",
|
"illuminate/view": "^5.5|^6|^7",
|
||||||
"phpro/grumphp": "^0.14",
|
"phpro/grumphp": "^0.17.1",
|
||||||
"phpunit/phpunit" : "4.*",
|
"squizlabs/php_codesniffer": "^3",
|
||||||
"scrutinizer/ocular": "~1.1",
|
"orchestra/testbench": "^3|^4|^5",
|
||||||
"squizlabs/php_codesniffer": "^3"
|
"mockery/mockery": "^1.3"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Barryvdh\\LaravelIdeHelper\\": "tests"
|
"Barryvdh\\LaravelIdeHelper\\Tests\\": "tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+25
-1
@@ -13,7 +13,7 @@ return array(
|
|||||||
|
|
||||||
'filename' => '_ide_helper',
|
'filename' => '_ide_helper',
|
||||||
'format' => 'php',
|
'format' => 'php',
|
||||||
|
|
||||||
'meta_filename' => '.phpstorm.meta.php',
|
'meta_filename' => '.phpstorm.meta.php',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -27,6 +27,18 @@ return array(
|
|||||||
|
|
||||||
'include_fluent' => false,
|
'include_fluent' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Factory Builders
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Set to true to generate factory generators for better factory()
|
||||||
|
| method auto-completion.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'include_factory_builders' => false,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Write Model Magic methods
|
| Write Model Magic methods
|
||||||
@@ -83,6 +95,18 @@ return array(
|
|||||||
'app',
|
'app',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Models to ignore
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Define which models should be ignored.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'ignored_models' => array(
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
+5
-2
@@ -11,5 +11,8 @@ parameters:
|
|||||||
standard: PSR2
|
standard: PSR2
|
||||||
warning_severity: ~
|
warning_severity: ~
|
||||||
ignore_patterns:
|
ignore_patterns:
|
||||||
- tests/
|
- tests/
|
||||||
triggered_by: [php]
|
triggered_by: [php]
|
||||||
|
whitelist_patterns:
|
||||||
|
- /^src\/.*/
|
||||||
|
- /^config\/.*/
|
||||||
|
|||||||
@@ -7,6 +7,19 @@
|
|||||||
|
|
||||||
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
||||||
|
|
||||||
|
* [Complete phpDocs, directly from the source](#complete-phpdocs--directly-from-the-source)
|
||||||
|
* [Install](#install)
|
||||||
|
* [Automatic phpDoc generation for Laravel Facades](#automatic-phpdoc-generation-for-laravel-facades)
|
||||||
|
* [Automatic phpDocs for models](#automatic-phpdocs-for-models)
|
||||||
|
* [Automatic phpDocs generation for Laravel Fluent methods](#automatic-phpdocs-generation-for-laravel-fluent-methods)
|
||||||
|
* [Auto-completion for factory builders](#auto-completion-for-factory-builders)
|
||||||
|
- [PhpStorm Meta for Container instances](#phpstorm-meta-for-container-instances)
|
||||||
|
- [Lumen Install](#lumen-install)
|
||||||
|
+ [Enabling Facades](#enabling-facades)
|
||||||
|
+ [Adding the Service Provider](#adding-the-service-provider)
|
||||||
|
+ [Adding Additional Facades](#adding-additional-facades)
|
||||||
|
* [License](#license)
|
||||||
|
|
||||||
### Complete phpDocs, directly from the source
|
### Complete phpDocs, directly from the source
|
||||||
|
|
||||||
_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
||||||
@@ -69,8 +82,8 @@ You can configure your composer.json to do this after each commit:
|
|||||||
"scripts":{
|
"scripts":{
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
||||||
"php artisan ide-helper:generate",
|
"@php artisan ide-helper:generate",
|
||||||
"php artisan ide-helper:meta"
|
"@php artisan ide-helper:meta"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
@@ -91,13 +104,6 @@ The `Illuminate/Support/helpers.php` is already set up, but you can add/remove y
|
|||||||
|
|
||||||
### Automatic phpDocs for models
|
### Automatic phpDocs for models
|
||||||
|
|
||||||
> You need to add `doctrine/dbal: ~2.3` to require-dev in your own composer.json to get database columns.
|
|
||||||
|
|
||||||
|
|
||||||
```bash
|
|
||||||
composer require --dev doctrine/dbal
|
|
||||||
```
|
|
||||||
|
|
||||||
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
|
||||||
phpDocs, based on table columns, relations and getters/setters. You can write the comments directly to your Model file, using the `--write (-W)` option. By default, you are asked to overwrite or write to a separate file (`_ide_helper_models.php`). You can force No with `--nowrite (-N)`.
|
phpDocs, based on table columns, relations and getters/setters. You can write the comments directly to your Model file, using the `--write (-W)` option. By default, you are asked to overwrite or write to a separate file (`_ide_helper_models.php`). You can force No with `--nowrite (-N)`.
|
||||||
Please make sure to backup your models, before writing the info.
|
Please make sure to backup your models, before writing the info.
|
||||||
@@ -143,6 +149,14 @@ Models can be ignored using the `--ignore (-I)` option
|
|||||||
php artisan ide-helper:models --ignore="Post,User"
|
php artisan ide-helper:models --ignore="Post,User"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or can be ignored by setting the `ignored_models` config
|
||||||
|
```php
|
||||||
|
'ignored_models' => array(
|
||||||
|
Post::class,
|
||||||
|
Api\User::class
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
||||||
|
|
||||||
For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add
|
For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add
|
||||||
@@ -163,6 +177,18 @@ After publishing vendor, simply change the `include_fluent` line your `config/id
|
|||||||
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE.
|
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE.
|
||||||
|
|
||||||
|
|
||||||
|
### Auto-completion for factory builders
|
||||||
|
|
||||||
|
If you would like the `factory()->create()` and `factory()->make()` methods to return the correct model class,
|
||||||
|
you can enable custom factory builders with the `include_factory_builders` line your `config/ide-helper.php` file.
|
||||||
|
|
||||||
|
```php
|
||||||
|
'include_factory_builders' => true,
|
||||||
|
```
|
||||||
|
|
||||||
|
For this to work, you must also publish the PhpStorm Meta file (see below).
|
||||||
|
|
||||||
|
|
||||||
## PhpStorm Meta for Container instances
|
## PhpStorm Meta for Container instances
|
||||||
|
|
||||||
It's possible to generate a PhpStorm meta file to [add support for factory design pattern](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata). For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, `events` will return an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
It's possible to generate a PhpStorm meta file to [add support for factory design pattern](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata). For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, `events` will return an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
||||||
@@ -243,14 +269,10 @@ The Laravel IDE Helper Generator is open-sourced software licensed under the [MI
|
|||||||
[ico-version]: https://img.shields.io/packagist/v/barryvdh/laravel-ide-helper.svg?style=flat-square
|
[ico-version]: https://img.shields.io/packagist/v/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
||||||
[ico-travis]: https://img.shields.io/travis/barryvdh/laravel-ide-helper/master.svg?style=flat-square
|
[ico-travis]: https://img.shields.io/travis/barryvdh/laravel-ide-helper/master.svg?style=flat-square
|
||||||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/barryvdh/laravel-ide-helper.svg?style=flat-square
|
|
||||||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/barryvdh/laravel-ide-helper.svg?style=flat-square
|
|
||||||
[ico-downloads]: https://img.shields.io/packagist/dt/barryvdh/laravel-ide-helper.svg?style=flat-square
|
[ico-downloads]: https://img.shields.io/packagist/dt/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
|
|
||||||
[link-packagist]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
[link-packagist]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
||||||
[link-travis]: https://travis-ci.org/barryvdh/laravel-ide-helper
|
[link-travis]: https://travis-ci.org/barryvdh/laravel-ide-helper
|
||||||
[link-scrutinizer]: https://scrutinizer-ci.com/g/barryvdh/laravel-ide-helper/code-structure
|
|
||||||
[link-code-quality]: https://scrutinizer-ci.com/g/barryvdh/laravel-ide-helper
|
|
||||||
[link-downloads]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
[link-downloads]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
||||||
[link-author]: https://github.com/barryvdh
|
[link-author]: https://github.com/barryvdh
|
||||||
[link-contributors]: ../../contributors
|
[link-contributors]: ../../contributors
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper file for Laravel 5, to provide autocomplete information to your IDE
|
* A helper file for Laravel, to provide autocomplete information to your IDE
|
||||||
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d H:i:s") ?>.
|
* Generated for Laravel <?= $version ?> on <?= date("Y-m-d H:i:s") ?>.
|
||||||
*
|
*
|
||||||
* This file should not be included in your code, only analyzed by your IDE!
|
* This file should not be included in your code, only analyzed by your IDE!
|
||||||
@@ -105,3 +105,13 @@ namespace Illuminate\Support {
|
|||||||
class Fluent {}
|
class Fluent {}
|
||||||
}
|
}
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<?php foreach ($factories as $factory): ?>
|
||||||
|
namespace <?=$factory->getNamespaceName()?> {
|
||||||
|
/**
|
||||||
|
* @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> create($attributes = [])
|
||||||
|
* @method \Illuminate\Database\Eloquent\Collection|<?=$factory->getShortName()?>[]|<?=$factory->getShortName()?> make($attributes = [])
|
||||||
|
*/
|
||||||
|
class <?=$factory->getShortName()?>FactoryBuilder extends \Illuminate\Database\Eloquent\FactoryBuilder {}
|
||||||
|
}
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -20,6 +20,15 @@ namespace PHPSTORM_META {
|
|||||||
]));
|
]));
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php if (count($factories)): ?>
|
||||||
|
override(\factory(0), map([
|
||||||
|
'' => '@FactoryBuilder',
|
||||||
|
<?php foreach($factories as $factory): ?>
|
||||||
|
'<?= $factory->getName() ?>' => \<?= $factory->getName() ?>FactoryBuilder::class,
|
||||||
|
<?php endforeach; ?>
|
||||||
|
]));
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
override(\Illuminate\Support\Arr::add(0), type(0));
|
override(\Illuminate\Support\Arr::add(0), type(0));
|
||||||
override(\Illuminate\Support\Arr::except(0), type(0));
|
override(\Illuminate\Support\Arr::except(0), type(0));
|
||||||
override(\Illuminate\Support\Arr::first(0), elementType(0));
|
override(\Illuminate\Support\Arr::first(0), elementType(0));
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Factories;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@@ -77,6 +78,9 @@ class MetaCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
// Needs to run before exception handler is registered
|
||||||
|
$factories = $this->config->get('ide-helper.include_factory_builders') ? Factories::all() : [];
|
||||||
|
|
||||||
$this->registerClassAutoloadExceptions();
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
$bindings = array();
|
$bindings = array();
|
||||||
@@ -99,9 +103,12 @@ class MetaCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->unregisterClassAutoloadExceptions();
|
||||||
|
|
||||||
$content = $this->view->make('meta', [
|
$content = $this->view->make('meta', [
|
||||||
'bindings' => $bindings,
|
'bindings' => $bindings,
|
||||||
'methods' => $this->methods,
|
'methods' => $this->methods,
|
||||||
|
'factories' => $factories,
|
||||||
])->render();
|
])->render();
|
||||||
|
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
@@ -154,4 +161,14 @@ class MetaCommand extends Command
|
|||||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
|
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove our custom autoloader that we pushed onto the autoload stack
|
||||||
|
*/
|
||||||
|
private function unregisterClassAutoloadExceptions()
|
||||||
|
{
|
||||||
|
$autoloadFunctions = spl_autoload_functions();
|
||||||
|
$ourAutoloader = array_pop($autoloadFunctions);
|
||||||
|
spl_autoload_unregister($ourAutoloader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+190
-40
@@ -10,19 +10,20 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||||
|
|
||||||
use Composer\Autoload\ClassMapGenerator;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use ReflectionClass;
|
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
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\Serializer as DocBlockSerializer;
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
use Composer\Autoload\ClassMapGenerator;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use ReflectionClass;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
@@ -58,11 +59,20 @@ class ModelsCommand extends Command
|
|||||||
protected $dirs = array();
|
protected $dirs = array();
|
||||||
protected $reset;
|
protected $reset;
|
||||||
protected $keep_text;
|
protected $keep_text;
|
||||||
|
protected $phpstorm_noinspections;
|
||||||
/**
|
/**
|
||||||
* @var bool[string]
|
* @var bool[string]
|
||||||
*/
|
*/
|
||||||
protected $nullableColumns = [];
|
protected $nullableColumns = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* During initializtion we use Laravels Date Facade to
|
||||||
|
* determine the actual date class and store it here.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $dateClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Filesystem $files
|
* @param Filesystem $files
|
||||||
*/
|
*/
|
||||||
@@ -88,6 +98,7 @@ class ModelsCommand extends Command
|
|||||||
$model = $this->argument('model');
|
$model = $this->argument('model');
|
||||||
$ignore = $this->option('ignore');
|
$ignore = $this->option('ignore');
|
||||||
$this->reset = $this->option('reset');
|
$this->reset = $this->option('reset');
|
||||||
|
$this->phpstorm_noinspections = $this->option('phpstorm-noinspections');
|
||||||
if ($this->option('smart-reset')) {
|
if ($this->option('smart-reset')) {
|
||||||
$this->keep_text = $this->reset = true;
|
$this->keep_text = $this->reset = true;
|
||||||
}
|
}
|
||||||
@@ -103,6 +114,10 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->dateClass = class_exists(\Illuminate\Support\Facades\Date::class)
|
||||||
|
? '\\' . get_class(\Illuminate\Support\Facades\Date::now())
|
||||||
|
: '\Illuminate\Support\Carbon';
|
||||||
|
|
||||||
$content = $this->generateDocs($model, $ignore);
|
$content = $this->generateDocs($model, $ignore);
|
||||||
|
|
||||||
if (!$this->write) {
|
if (!$this->write) {
|
||||||
@@ -142,6 +157,10 @@ class ModelsCommand extends Command
|
|||||||
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
|
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
|
||||||
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
|
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
|
||||||
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
|
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
|
||||||
|
array('phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
|
||||||
|
'Add PhpFullyQualifiedNameUsageInspection and PhpUnnecessaryFullyQualifiedNameInspection PHPStorm ' .
|
||||||
|
'noinspection tags'
|
||||||
|
),
|
||||||
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
|
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -173,7 +192,10 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ignore = explode(',', $ignore);
|
$ignore = array_merge(
|
||||||
|
explode(',', $ignore),
|
||||||
|
$this->laravel['config']->get('ide-helper.ignored_models', array())
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($models as $name) {
|
foreach ($models as $name) {
|
||||||
if (in_array($name, $ignore)) {
|
if (in_array($name, $ignore)) {
|
||||||
@@ -214,11 +236,14 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$this->getPropertiesFromMethods($model);
|
$this->getPropertiesFromMethods($model);
|
||||||
$this->getSoftDeleteMethods($model);
|
$this->getSoftDeleteMethods($model);
|
||||||
|
$this->getCollectionMethods($model);
|
||||||
$output .= $this->createPhpDocs($name);
|
$output .= $this->createPhpDocs($name);
|
||||||
$ignore[] = $name;
|
$ignore[] = $name;
|
||||||
$this->nullableColumns = [];
|
$this->nullableColumns = [];
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
$this->error("Exception: " . $e->getMessage() .
|
||||||
|
"\nCould not analyze class $name.\n\nTrace:\n" .
|
||||||
|
$e->getTraceAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,9 +264,12 @@ class ModelsCommand extends Command
|
|||||||
$models = array();
|
$models = array();
|
||||||
foreach ($this->dirs as $dir) {
|
foreach ($this->dirs as $dir) {
|
||||||
$dir = base_path() . '/' . $dir;
|
$dir = base_path() . '/' . $dir;
|
||||||
if (file_exists($dir)) {
|
$dirs = glob($dir, GLOB_ONLYDIR);
|
||||||
foreach (ClassMapGenerator::createMap($dir) as $model => $path) {
|
foreach ($dirs as $dir) {
|
||||||
$models[] = $model;
|
if (file_exists($dir)) {
|
||||||
|
foreach (ClassMapGenerator::createMap($dir) as $model => $path) {
|
||||||
|
$models[] = $model;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,7 +312,7 @@ class ModelsCommand extends Command
|
|||||||
break;
|
break;
|
||||||
case 'date':
|
case 'date':
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
$realType = '\Illuminate\Support\Carbon';
|
$realType = $this->dateClass;
|
||||||
break;
|
break;
|
||||||
case 'collection':
|
case 'collection':
|
||||||
$realType = '\Illuminate\Support\Collection';
|
$realType = '\Illuminate\Support\Collection';
|
||||||
@@ -297,6 +325,8 @@ class ModelsCommand extends Command
|
|||||||
if (!isset($this->properties[$name])) {
|
if (!isset($this->properties[$name])) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
$realType = $this->checkForCustomLaravelCasts($realType);
|
||||||
|
|
||||||
$this->properties[$name]['type'] = $this->getTypeOverride($realType);
|
$this->properties[$name]['type'] = $this->getTypeOverride($realType);
|
||||||
|
|
||||||
if (isset($this->nullableColumns[$name])) {
|
if (isset($this->nullableColumns[$name])) {
|
||||||
@@ -348,7 +378,7 @@ class ModelsCommand extends Command
|
|||||||
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())) {
|
||||||
$type = '\Illuminate\Support\Carbon';
|
$type = $this->dateClass;
|
||||||
} else {
|
} else {
|
||||||
$type = $column->getType()->getName();
|
$type = $column->getType()->getName();
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
@@ -421,7 +451,7 @@ class ModelsCommand extends Command
|
|||||||
$name = Str::snake(substr($method, 3, -9));
|
$name = Str::snake(substr($method, 3, -9));
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$reflection = new \ReflectionMethod($model, $method);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
$type = $this->getReturnTypeFromDocBlock($reflection);
|
$type = $this->getReturnType($reflection);
|
||||||
$this->setProperty($name, $type, true, null);
|
$this->setProperty($name, $type, true, null);
|
||||||
}
|
}
|
||||||
} elseif (Str::startsWith($method, 'set') && Str::endsWith(
|
} elseif (Str::startsWith($method, 'set') && Str::endsWith(
|
||||||
@@ -455,8 +485,15 @@ class ModelsCommand extends Command
|
|||||||
) {
|
) {
|
||||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||||
$reflection = new \ReflectionMethod($model, $method);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
// php 7.x type or fallback to docblock
|
|
||||||
$type = (string) ($reflection->getReturnType() ?: $this->getReturnTypeFromDocBlock($reflection));
|
if ($returnType = $reflection->getReturnType()) {
|
||||||
|
$type = $returnType instanceof \ReflectionNamedType
|
||||||
|
? $returnType->getName()
|
||||||
|
: (string)$returnType;
|
||||||
|
} else {
|
||||||
|
// php 7.x type or fallback to docblock
|
||||||
|
$type = (string)$this->getReturnTypeFromDocBlock($reflection);
|
||||||
|
}
|
||||||
|
|
||||||
$file = new \SplFileObject($reflection->getFileName());
|
$file = new \SplFileObject($reflection->getFileName());
|
||||||
$file->seek($reflection->getStartLine() - 1);
|
$file->seek($reflection->getStartLine() - 1);
|
||||||
@@ -473,6 +510,7 @@ class ModelsCommand extends Command
|
|||||||
foreach (array(
|
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',
|
||||||
'belongsToMany' => '\Illuminate\Database\Eloquent\Relations\BelongsToMany',
|
'belongsToMany' => '\Illuminate\Database\Eloquent\Relations\BelongsToMany',
|
||||||
'hasOne' => '\Illuminate\Database\Eloquent\Relations\HasOne',
|
'hasOne' => '\Illuminate\Database\Eloquent\Relations\HasOne',
|
||||||
'belongsTo' => '\Illuminate\Database\Eloquent\Relations\BelongsTo',
|
'belongsTo' => '\Illuminate\Database\Eloquent\Relations\BelongsTo',
|
||||||
@@ -483,14 +521,19 @@ class ModelsCommand extends Command
|
|||||||
'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) || stripos($impl, (string)$type) !== false) {
|
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
|
||||||
//Resolve the relation's model to a Relation object.
|
//Resolve the relation's model to a Relation object.
|
||||||
$methodReflection = new \ReflectionMethod($model, $method);
|
$methodReflection = new \ReflectionMethod($model, $method);
|
||||||
if ($methodReflection->getNumberOfParameters()) {
|
if ($methodReflection->getNumberOfParameters()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relationObj = $model->$method();
|
// Adding constraints requires reading model properties which
|
||||||
|
// can cause errors. Since we don't need constraints we can
|
||||||
|
// disable them when we fetch the relation to avoid errors.
|
||||||
|
$relationObj = Relation::noConstraints(function () use ($model, $method) {
|
||||||
|
return $model->$method();
|
||||||
|
});
|
||||||
|
|
||||||
if ($relationObj instanceof Relation) {
|
if ($relationObj instanceof Relation) {
|
||||||
$relatedModel = '\\' . get_class($relationObj->getRelated());
|
$relatedModel = '\\' . get_class($relationObj->getRelated());
|
||||||
@@ -533,7 +576,7 @@ class ModelsCommand extends Command
|
|||||||
true,
|
true,
|
||||||
null,
|
null,
|
||||||
'',
|
'',
|
||||||
$this->isRelationForeignKeyNullable($relationObj)
|
$this->isRelationNullable($relation, $relationObj)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -545,22 +588,32 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the foreign key of the relation is nullable
|
* Check if the relation is nullable
|
||||||
*
|
*
|
||||||
* @param Relation $relation
|
* @param string $relation
|
||||||
|
* @param Relation $relationObj
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isRelationForeignKeyNullable(Relation $relation)
|
protected function isRelationNullable(string $relation, Relation $relationObj): bool
|
||||||
{
|
{
|
||||||
$reflectionObj = new \ReflectionObject($relation);
|
$reflectionObj = new \ReflectionObject($relationObj);
|
||||||
|
|
||||||
|
if (in_array($relation, ['hasOne', 'hasOneThrough', 'morphOne'], true)) {
|
||||||
|
$defaultProp = $reflectionObj->getProperty('withDefault');
|
||||||
|
$defaultProp->setAccessible(true);
|
||||||
|
|
||||||
|
return !$defaultProp->getValue($relationObj);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$reflectionObj->hasProperty('foreignKey')) {
|
if (!$reflectionObj->hasProperty('foreignKey')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fkProp = $reflectionObj->getProperty('foreignKey');
|
$fkProp = $reflectionObj->getProperty('foreignKey');
|
||||||
$fkProp->setAccessible(true);
|
$fkProp->setAccessible(true);
|
||||||
|
|
||||||
return isset($this->nullableColumns[$fkProp->getValue($relation)]);
|
return isset($this->nullableColumns[$fkProp->getValue($relationObj)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -618,6 +671,10 @@ class ModelsCommand extends Command
|
|||||||
$classname = $reflection->getShortName();
|
$classname = $reflection->getShortName();
|
||||||
$originalDoc = $reflection->getDocComment();
|
$originalDoc = $reflection->getDocComment();
|
||||||
$keyword = $this->getClassKeyword($reflection);
|
$keyword = $this->getClassKeyword($reflection);
|
||||||
|
$interfaceNames = array_diff_key(
|
||||||
|
$reflection->getInterfaceNames(),
|
||||||
|
$reflection->getParentClass()->getInterfaceNames()
|
||||||
|
);
|
||||||
|
|
||||||
if ($this->reset) {
|
if ($this->reset) {
|
||||||
$phpdoc = new DocBlock('', new Context($namespace));
|
$phpdoc = new DocBlock('', new Context($namespace));
|
||||||
@@ -647,6 +704,11 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
foreach ($this->properties as $name => $property) {
|
foreach ($this->properties as $name => $property) {
|
||||||
$name = "\$$name";
|
$name = "\$$name";
|
||||||
|
|
||||||
|
if ($this->hasCamelCaseModelProperties()) {
|
||||||
|
$name = Str::camel($name);
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($name, $properties)) {
|
if (in_array($name, $properties)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -658,10 +720,6 @@ class ModelsCommand extends Command
|
|||||||
$attr = 'property-read';
|
$attr = 'property-read';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasCamelCaseModelProperties()) {
|
|
||||||
$name = Str::camel($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}");
|
$tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}");
|
||||||
$tag = Tag::createInstance($tagLine, $phpdoc);
|
$tag = Tag::createInstance($tagLine, $phpdoc);
|
||||||
$phpdoc->appendTag($tag);
|
$phpdoc->appendTag($tag);
|
||||||
@@ -681,6 +739,20 @@ class ModelsCommand extends Command
|
|||||||
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
|
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
|
||||||
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
||||||
}
|
}
|
||||||
|
if ($this->phpstorm_noinspections) {
|
||||||
|
/**
|
||||||
|
* Facades, Eloquent API
|
||||||
|
* @see https://www.jetbrains.com/help/phpstorm/php-fully-qualified-name-usage.html
|
||||||
|
*/
|
||||||
|
$phpdoc->appendTag(Tag::createInstance("@noinspection PhpFullyQualifiedNameUsageInspection", $phpdoc));
|
||||||
|
/**
|
||||||
|
* Relations, other models in the same namespace
|
||||||
|
* @see https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html
|
||||||
|
*/
|
||||||
|
$phpdoc->appendTag(
|
||||||
|
Tag::createInstance("@noinspection PhpUnnecessaryFullyQualifiedNameInspection", $phpdoc)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$serializer = new DocBlockSerializer();
|
$serializer = new DocBlockSerializer();
|
||||||
$serializer->getDocComment($phpdoc);
|
$serializer->getDocComment($phpdoc);
|
||||||
@@ -705,8 +777,14 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent {}\n}\n\n";
|
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent ";
|
||||||
return $output;
|
|
||||||
|
if ($interfaceNames) {
|
||||||
|
$interfaces = implode(', \\', $interfaceNames);
|
||||||
|
$output .= "implements \\{$interfaces} ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output . "{}\n}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -730,7 +808,7 @@ class ModelsCommand extends Command
|
|||||||
if (is_bool($default)) {
|
if (is_bool($default)) {
|
||||||
$default = $default ? 'true' : 'false';
|
$default = $default ? 'true' : 'false';
|
||||||
} elseif (is_array($default)) {
|
} elseif (is_array($default)) {
|
||||||
$default = 'array()';
|
$default = '[]';
|
||||||
} elseif (is_null($default)) {
|
} elseif (is_null($default)) {
|
||||||
$default = 'null';
|
$default = 'null';
|
||||||
} elseif (is_int($default)) {
|
} elseif (is_int($default)) {
|
||||||
@@ -752,7 +830,7 @@ class ModelsCommand extends Command
|
|||||||
* @param string $className
|
* @param string $className
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getCollectionClass($className)
|
protected function getCollectionClass($className)
|
||||||
{
|
{
|
||||||
// Return something in the very very unlikely scenario the model doesn't
|
// Return something in the very very unlikely scenario the model doesn't
|
||||||
// have a newCollection() method.
|
// have a newCollection() method.
|
||||||
@@ -773,6 +851,16 @@ class ModelsCommand extends Command
|
|||||||
return $this->laravel['config']->get('ide-helper.model_camel_case_properties', false);
|
return $this->laravel['config']->get('ide-helper.model_camel_case_properties', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getReturnType(\ReflectionMethod $reflection): ?string
|
||||||
|
{
|
||||||
|
$type = $this->getReturnTypeFromDocBlock($reflection);
|
||||||
|
if ($type) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getReturnTypeFromReflection($reflection);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get method return type based on it DocBlock comment
|
* Get method return type based on it DocBlock comment
|
||||||
*
|
*
|
||||||
@@ -792,6 +880,29 @@ class ModelsCommand extends Command
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getReturnTypeFromReflection(\ReflectionMethod $reflection): ?string
|
||||||
|
{
|
||||||
|
$returnType = $reflection->getReturnType();
|
||||||
|
if (!$returnType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = $returnType instanceof \ReflectionNamedType
|
||||||
|
? $returnType->getName()
|
||||||
|
: (string)$returnType;
|
||||||
|
|
||||||
|
if (!$returnType->isBuiltin()) {
|
||||||
|
$type = '\\' . $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($returnType->allowsNull()) {
|
||||||
|
$type .= '|null';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates methods provided by the SoftDeletes trait
|
* Generates methods provided by the SoftDeletes trait
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
@@ -800,20 +911,31 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
$traits = class_uses(get_class($model), true);
|
$traits = class_uses(get_class($model), true);
|
||||||
if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) {
|
if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) {
|
||||||
$this->setMethod('forceDelete', 'bool|null', []);
|
|
||||||
$this->setMethod('restore', 'bool|null', []);
|
|
||||||
|
|
||||||
$this->setMethod('withTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
$this->setMethod('withTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
$this->setMethod('withoutTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
$this->setMethod('withoutTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
$this->setMethod('onlyTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
$this->setMethod('onlyTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates methods that return collections
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
|
protected function getCollectionMethods($model)
|
||||||
|
{
|
||||||
|
$collectionClass = $this->getCollectionClass(get_class($model));
|
||||||
|
|
||||||
|
if ($collectionClass !== '\\' . \Illuminate\Database\Eloquent\Collection::class) {
|
||||||
|
$this->setMethod('get', $collectionClass . '|static[]', ['$columns = [\'*\']']);
|
||||||
|
$this->setMethod('all', $collectionClass . '|static[]', ['$columns = [\'*\']']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ReflectionClass $reflection
|
* @param ReflectionClass $reflection
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getClassKeyword(ReflectionClass $reflection)
|
protected function getClassKeyword(ReflectionClass $reflection)
|
||||||
{
|
{
|
||||||
if ($reflection->isFinal()) {
|
if ($reflection->isFinal()) {
|
||||||
$keyword = 'final ';
|
$keyword = 'final ';
|
||||||
@@ -825,4 +947,32 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
return $keyword;
|
return $keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @return string|null
|
||||||
|
* @throws \ReflectionException
|
||||||
|
*/
|
||||||
|
protected function checkForCustomLaravelCasts(string $type): ?string
|
||||||
|
{
|
||||||
|
if (!class_exists($type) || !interface_exists(CastsAttributes::class)) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflection = new \ReflectionClass($type);
|
||||||
|
|
||||||
|
if (!$reflection->implementsInterface(CastsAttributes::class)) {
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
$methodReflection = new \ReflectionMethod($type, 'get');
|
||||||
|
|
||||||
|
$type = $this->getReturnTypeFromReflection($methodReflection);
|
||||||
|
|
||||||
|
if ($type === null) {
|
||||||
|
$type = $this->getReturnTypeFromDocBlock($methodReflection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Database\Eloquent\Factory;
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
|
class Factories
|
||||||
|
{
|
||||||
|
|
||||||
|
public static function all()
|
||||||
|
{
|
||||||
|
$factories = [];
|
||||||
|
|
||||||
|
$factory = app(Factory::class);
|
||||||
|
|
||||||
|
$definitions = (new ReflectionClass(Factory::class))->getProperty('definitions');
|
||||||
|
$definitions->setAccessible(true);
|
||||||
|
|
||||||
|
foreach ($definitions->getValue($factory) as $factory_target => $config) {
|
||||||
|
try {
|
||||||
|
$factories[] = new ReflectionClass($factory_target);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $factories;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,7 @@ class Generator
|
|||||||
->with('helpers', $this->helpers)
|
->with('helpers', $this->helpers)
|
||||||
->with('version', $app->version())
|
->with('version', $app->version())
|
||||||
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
||||||
|
->with('factories', $this->config->get('ide-helper.include_factory_builders') ? Factories::all() : [])
|
||||||
->render();
|
->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -314,14 +314,14 @@ class Method
|
|||||||
$params = array();
|
$params = array();
|
||||||
$paramsWithDefault = array();
|
$paramsWithDefault = array();
|
||||||
foreach ($method->getParameters() as $param) {
|
foreach ($method->getParameters() as $param) {
|
||||||
$paramStr = '$' . $param->getName();
|
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
|
||||||
$params[] = $paramStr;
|
$params[] = $paramStr;
|
||||||
if ($param->isOptional()) {
|
if ($param->isOptional() && !$param->isVariadic()) {
|
||||||
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
||||||
if (is_bool($default)) {
|
if (is_bool($default)) {
|
||||||
$default = $default ? 'true' : 'false';
|
$default = $default ? 'true' : 'false';
|
||||||
} elseif (is_array($default)) {
|
} elseif (is_array($default)) {
|
||||||
$default = 'array()';
|
$default = '[]';
|
||||||
} elseif (is_null($default)) {
|
} elseif (is_null($default)) {
|
||||||
$default = 'null';
|
$default = 'null';
|
||||||
} elseif (is_int($default)) {
|
} elseif (is_int($default)) {
|
||||||
@@ -329,7 +329,7 @@ class Method
|
|||||||
} elseif (is_resource($default)) {
|
} elseif (is_resource($default)) {
|
||||||
//skip to not fail
|
//skip to not fail
|
||||||
} else {
|
} else {
|
||||||
$default = "'" . trim($default) . "'";
|
$default = var_export($default, true);
|
||||||
}
|
}
|
||||||
$paramStr .= " = $default";
|
$paramStr .= " = $default";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
|
class EloquentCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCommand()
|
||||||
|
{
|
||||||
|
$modelFilename = $this->getVendorModelFilename();
|
||||||
|
$modelSource = file_get_contents($modelFilename);
|
||||||
|
if (false !== strpos($modelSource, '* @mixin')) {
|
||||||
|
$msg = sprintf('Class %s already contains the @mixin markers', Model::class);
|
||||||
|
$this->markTestSkipped($msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
// We don't care about actual args (filename)
|
||||||
|
->andReturn('abstract class Model implements'); // This is enough to trigger the replacement logic
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(), // First arg is path, we don't care
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
$command = $this->app->make(EloquentCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command);
|
||||||
|
|
||||||
|
$expectedContent = '/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @mixin \Eloquent
|
||||||
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||||
|
* @mixin \Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
abstract class Model implements';
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
|
||||||
|
$display = $tester->getDisplay();
|
||||||
|
$this->assertRegExp(';Unexpected no document on Illuminate\\\Database\\\Eloquent\\\Model;', $display);
|
||||||
|
$this->assertRegExp(';Wrote expected docblock to .*/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php;', $display);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getVendorModelFilename(): string
|
||||||
|
{
|
||||||
|
$class = Model::class;
|
||||||
|
$reflectedClass = new ReflectionClass($class);
|
||||||
|
|
||||||
|
return $reflectedClass->getFileName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
|
||||||
|
abstract class AbstractModelsCommand extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
// Skip older Laravel version for these tests
|
||||||
|
if (version_compare(Application::VERSION, '6.0', '<')) {
|
||||||
|
$this->markTestSkipped('This test requires Laravel 6.0 or higher');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->loadMigrationsFrom(__DIR__ . '/migrations');
|
||||||
|
$this->artisan('migrate');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$config = $app['config'];
|
||||||
|
|
||||||
|
$config->set('database.default', 'sqlite');
|
||||||
|
$config->set('database.connections.sqlite', [
|
||||||
|
'driver' => 'sqlite',
|
||||||
|
'database' => ':memory:',
|
||||||
|
'prefix' => '',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
|
class SimpleCollection extends Collection
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
public function newCollection(array $models = [])
|
||||||
|
{
|
||||||
|
return new SimpleCollection($models);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasMany(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Simple::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/CustomCollection/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple[] $relationHasMany
|
||||||
|
* @property-read int|null $relation_has_many_count
|
||||||
|
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection|static[] all($columns = ['*'])
|
||||||
|
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection|static[] get($columns = ['*'])
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
public function newCollection(array $models = [])
|
||||||
|
{
|
||||||
|
return new SimpleCollection($models);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasMany(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Simple::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class CustomDate extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Date;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Date::use(CarbonImmutable::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
Date::use(Carbon::class);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/CustomDate/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/CustomDate.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate
|
||||||
|
*
|
||||||
|
* @property \Carbon\CarbonImmutable|null $created_at
|
||||||
|
* @property \Carbon\CarbonImmutable|null $updated_at
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate whereCreatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate whereUpdatedAt($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class CustomDate extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdoc/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\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 float|null $decimal_nullable
|
||||||
|
* @property float $decimal_not_nullable
|
||||||
|
* @property float|null $unsigned_decimal_nullable
|
||||||
|
* @property float $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|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBigIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBigIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBinaryNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBinaryNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBooleanNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereBooleanNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereCharNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereCharNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereCreatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDateNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDateNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDatetimeNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDatetimeNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDatetimetzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDatetimetzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDecimalNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDecimalNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDoubleNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereDoubleNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereEnumNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereEnumNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereFloatNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereFloatNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereId($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereIpaddressNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereIpaddressNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereJsonNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereJsonNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereJsonbNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereJsonbNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereLongTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereLongTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMacaddressNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMacaddressNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMediumIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMediumIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMediumTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereMediumTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereSmallIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereSmallIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereStringNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereStringNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimeNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimeNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimestampNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimestampNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimestamptzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimestamptzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimetzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTimetzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTinyIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereTinyIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedBigIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedBigIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedDecimalNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedDecimalNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedMediumIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedMediumIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedSmallIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedSmallIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedTinyIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUnsignedTinyIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUpdatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUuidNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereUuidNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereYearNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post whereYearNullable($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,224 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models',
|
||||||
|
],
|
||||||
|
// Activate the camel_case mode
|
||||||
|
'model_camel_case_properties' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Post.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property string|null $charNullable
|
||||||
|
* @property string $charNotNullable
|
||||||
|
* @property string|null $stringNullable
|
||||||
|
* @property string $stringNotNullable
|
||||||
|
* @property string|null $textNullable
|
||||||
|
* @property string $textNotNullable
|
||||||
|
* @property string|null $mediumTextNullable
|
||||||
|
* @property string $mediumTextNotNullable
|
||||||
|
* @property string|null $longTextNullable
|
||||||
|
* @property string $longTextNotNullable
|
||||||
|
* @property integer|null $integerNullable
|
||||||
|
* @property integer $integerNotNullable
|
||||||
|
* @property integer|null $tinyIntegerNullable
|
||||||
|
* @property integer $tinyIntegerNotNullable
|
||||||
|
* @property integer|null $smallIntegerNullable
|
||||||
|
* @property integer $smallIntegerNotNullable
|
||||||
|
* @property integer|null $mediumIntegerNullable
|
||||||
|
* @property integer $mediumIntegerNotNullable
|
||||||
|
* @property integer|null $bigIntegerNullable
|
||||||
|
* @property integer $bigIntegerNotNullable
|
||||||
|
* @property integer|null $unsignedIntegerNullable
|
||||||
|
* @property integer $unsignedIntegerNotNullable
|
||||||
|
* @property integer|null $unsignedTinyIntegerNullable
|
||||||
|
* @property integer $unsignedTinyIntegerNotNullable
|
||||||
|
* @property integer|null $unsignedSmallIntegerNullable
|
||||||
|
* @property integer $unsignedSmallIntegerNotNullable
|
||||||
|
* @property integer|null $unsignedMediumIntegerNullable
|
||||||
|
* @property integer $unsignedMediumIntegerNotNullable
|
||||||
|
* @property integer|null $unsignedBigIntegerNullable
|
||||||
|
* @property integer $unsignedBigIntegerNotNullable
|
||||||
|
* @property float|null $floatNullable
|
||||||
|
* @property float $floatNotNullable
|
||||||
|
* @property float|null $doubleNullable
|
||||||
|
* @property float $doubleNotNullable
|
||||||
|
* @property float|null $decimalNullable
|
||||||
|
* @property float $decimalNotNullable
|
||||||
|
* @property float|null $unsignedDecimalNullable
|
||||||
|
* @property float $unsignedDecimalNotNullable
|
||||||
|
* @property integer|null $booleanNullable
|
||||||
|
* @property integer $booleanNotNullable
|
||||||
|
* @property string|null $enumNullable
|
||||||
|
* @property string $enumNotNullable
|
||||||
|
* @property string|null $jsonNullable
|
||||||
|
* @property string $jsonNotNullable
|
||||||
|
* @property string|null $jsonbNullable
|
||||||
|
* @property string $jsonbNotNullable
|
||||||
|
* @property string|null $dateNullable
|
||||||
|
* @property string $dateNotNullable
|
||||||
|
* @property string|null $datetimeNullable
|
||||||
|
* @property string $datetimeNotNullable
|
||||||
|
* @property string|null $datetimetzNullable
|
||||||
|
* @property string $datetimetzNotNullable
|
||||||
|
* @property string|null $timeNullable
|
||||||
|
* @property string $timeNotNullable
|
||||||
|
* @property string|null $timetzNullable
|
||||||
|
* @property string $timetzNotNullable
|
||||||
|
* @property string|null $timestampNullable
|
||||||
|
* @property string $timestampNotNullable
|
||||||
|
* @property string|null $timestamptzNullable
|
||||||
|
* @property string $timestamptzNotNullable
|
||||||
|
* @property integer|null $yearNullable
|
||||||
|
* @property integer $yearNotNullable
|
||||||
|
* @property mixed|null $binaryNullable
|
||||||
|
* @property mixed $binaryNotNullable
|
||||||
|
* @property string|null $uuidNullable
|
||||||
|
* @property string $uuidNotNullable
|
||||||
|
* @property string|null $ipaddressNullable
|
||||||
|
* @property string $ipaddressNotNullable
|
||||||
|
* @property string|null $macaddressNullable
|
||||||
|
* @property string $macaddressNotNullable
|
||||||
|
* @property \Illuminate\Support\Carbon|null $createdAt
|
||||||
|
* @property \Illuminate\Support\Carbon|null $updatedAt
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBigIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBigIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBinaryNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBinaryNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBooleanNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereBooleanNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereCharNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereCharNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereCreatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDateNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDateNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDatetimeNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDatetimeNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDatetimetzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDatetimetzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDecimalNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDecimalNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDoubleNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereDoubleNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereEnumNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereEnumNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereFloatNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereFloatNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereId($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereIpaddressNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereIpaddressNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereJsonNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereJsonNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereJsonbNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereJsonbNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereLongTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereLongTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMacaddressNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMacaddressNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMediumIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMediumIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMediumTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereMediumTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereSmallIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereSmallIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereStringNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereStringNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTextNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTextNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimeNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimeNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimestampNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimestampNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimestamptzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimestamptzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimetzNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTimetzNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTinyIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereTinyIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedBigIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedBigIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedDecimalNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedDecimalNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedMediumIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedMediumIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedSmallIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedSmallIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedTinyIntegerNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUnsignedTinyIntegerNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUpdatedAt($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUuidNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereUuidNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereYearNotNullable($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdocCamel\Models\Post whereYearNullable($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnPhpdocAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeWithIntReturnTypeAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnTypeAndPhpdocAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnTypeAndButPhpdocStringAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeWithoutTypeAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return what|ever|we-write/here
|
||||||
|
*/
|
||||||
|
public function getAttributeTakesPhpdocLiteralAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnTypeIntOrNullAttribute(): ?int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsImportedClassAttribute(): DateTime
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsFqnClassAttribute(): \Illuminate\Support\Facades\Date
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsArrayAttribute(): array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableArrayAttribute(): ?array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsStdClassAttribute(): \stdClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableStdClassAttribute(): ?\stdClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsBoolAttribute(): bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableBoolAttribute(): ?bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsFloatAttribute(): bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableFloatAttribute(): ?bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsCallableAttribute(): callable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableCallableAttribute(): ?callable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doesn't make sense, but…
|
||||||
|
*/
|
||||||
|
public function getAttributeReturnsVoidAttribute(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/Getter/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property-read int|null $attribute_return_type_int_or_null
|
||||||
|
* @property-read array $attribute_returns_array
|
||||||
|
* @property-read bool $attribute_returns_bool
|
||||||
|
* @property-read callable $attribute_returns_callable
|
||||||
|
* @property-read bool $attribute_returns_float
|
||||||
|
* @property-read \Illuminate\Support\Facades\Date $attribute_returns_fqn_class
|
||||||
|
* @property-read \DateTime $attribute_returns_imported_class
|
||||||
|
* @property-read array|null $attribute_returns_nullable_array
|
||||||
|
* @property-read bool|null $attribute_returns_nullable_bool
|
||||||
|
* @property-read callable|null $attribute_returns_nullable_callable
|
||||||
|
* @property-read bool|null $attribute_returns_nullable_float
|
||||||
|
* @property-read \stdClass|null $attribute_returns_nullable_std_class
|
||||||
|
* @property-read \stdClass $attribute_returns_std_class
|
||||||
|
* @property-read void $attribute_returns_void
|
||||||
|
* @property-read \what|\ever|\we-write/here $attribute_takes_phpdoc_literal
|
||||||
|
* @property-read int $attribute_with_int_return_phpdoc
|
||||||
|
* @property-read string $attribute_with_int_return_type_and_but_phpdoc_string
|
||||||
|
* @property-read int $attribute_with_int_return_type_and_phpdoc
|
||||||
|
* @property-read int $attribute_with_int_return_type
|
||||||
|
* @property-read mixed $attribute_without_type
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnPhpdocAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeWithIntReturnTypeAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnTypeAndPhpdocAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAttributeWithIntReturnTypeAndButPhpdocStringAttribute(): int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeWithoutTypeAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return what|ever|we-write/here
|
||||||
|
*/
|
||||||
|
public function getAttributeTakesPhpdocLiteralAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnTypeIntOrNullAttribute(): ?int
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsImportedClassAttribute(): DateTime
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsFqnClassAttribute(): \Illuminate\Support\Facades\Date
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsArrayAttribute(): array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableArrayAttribute(): ?array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsStdClassAttribute(): \stdClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableStdClassAttribute(): ?\stdClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsBoolAttribute(): bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableBoolAttribute(): ?bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsFloatAttribute(): bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableFloatAttribute(): ?bool
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsCallableAttribute(): callable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttributeReturnsNullableCallableAttribute(): ?callable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doesn't make sense, but…
|
||||||
|
*/
|
||||||
|
public function getAttributeReturnsVoidAttribute(): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Ignored extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class NotIgnored extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\Ignored;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
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/Ignored/Models',
|
||||||
|
],
|
||||||
|
'ignored_models' => [
|
||||||
|
Ignored::class
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Ignored.php'))
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/NotIgnored.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\NotIgnored
|
||||||
|
*
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\NotIgnored newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\NotIgnored newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\NotIgnored query()
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class NotIgnored extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Auth\Authenticatable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class User extends Model implements Authenticatable
|
||||||
|
{
|
||||||
|
public function getAuthIdentifierName()
|
||||||
|
{
|
||||||
|
// TODO: Implement getAuthIdentifierName() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthIdentifier()
|
||||||
|
{
|
||||||
|
// TODO: Implement getAuthIdentifier() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthPassword()
|
||||||
|
{
|
||||||
|
// TODO: Implement getAuthPassword() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRememberToken()
|
||||||
|
{
|
||||||
|
// TODO: Implement getRememberToken() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRememberToken($value)
|
||||||
|
{
|
||||||
|
// TODO: Implement setRememberToken() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRememberTokenName()
|
||||||
|
{
|
||||||
|
// TODO: Implement getRememberTokenName() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
final class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/Interfaces/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--nowrite' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?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\Interfaces\Models{
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User
|
||||||
|
*
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User query()
|
||||||
|
*/
|
||||||
|
class User extends \Eloquent implements \Illuminate\Contracts\Auth\Authenticatable {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
class CastedProperty
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithDocblockReturn implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @return CastedProperty
|
||||||
|
*/
|
||||||
|
public function get($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithNullablePrimitiveReturn implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get($model, string $key, $value, array $attributes): ?array
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithPrimitiveDocblockReturn implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public function get($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithPrimitiveReturn implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get($model, string $key, $value, array $attributes): array
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithReturnType implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get($model, string $key, $value, array $attributes): CastedProperty
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CustomCasterWithoutReturnType implements CastsAttributes
|
||||||
|
{
|
||||||
|
public function get($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
return new CastedProperty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function set($model, string $key, $value, array $attributes)
|
||||||
|
{
|
||||||
|
// TODO: Implement set() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithNullablePrimitiveReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithoutReturnType;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveDocblockReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithReturnType;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class CustomCast extends Model
|
||||||
|
{
|
||||||
|
protected $casts = [
|
||||||
|
'casted_property_with_return_type' => CustomCasterWithReturnType::class,
|
||||||
|
'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class,
|
||||||
|
'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class,
|
||||||
|
'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class,
|
||||||
|
'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class,
|
||||||
|
'casted_property_without_return' => CustomCasterWithoutReturnType::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
if (version_compare(Application::VERSION, '7.0', '<')) {
|
||||||
|
$this->markTestSkipped('This test requires Laravel 7.0 or higher');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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/LaravelCustomCasts/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_parses_casted_properties_correctly(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__.'/Models/CustomCast.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithDocblockReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithNullablePrimitiveReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithoutReturnType;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveDocblockReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithPrimitiveReturn;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CustomCasterWithReturnType;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast
|
||||||
|
*
|
||||||
|
* @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $casted_property_with_return_type
|
||||||
|
* @property \CastedProperty $casted_property_with_return_docblock
|
||||||
|
* @property array $casted_property_with_return_primitive
|
||||||
|
* @property array|null $casted_property_with_return_primitive_docblock
|
||||||
|
* @property array|null $casted_property_with_return_nullable_primitive
|
||||||
|
* @property $casted_property_without_return
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithReturnDocblock($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithReturnNullablePrimitive($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithReturnPrimitive($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithReturnPrimitiveDocblock($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithReturnType($value)
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Models\CustomCast whereCastedPropertyWithoutReturn($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class CustomCast extends Model
|
||||||
|
{
|
||||||
|
protected $casts = [
|
||||||
|
'casted_property_with_return_type' => CustomCasterWithReturnType::class,
|
||||||
|
'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class,
|
||||||
|
'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class,
|
||||||
|
'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class,
|
||||||
|
'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class,
|
||||||
|
'casted_property_without_return' => CustomCasterWithoutReturnType::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
use function file_get_contents;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/PHPStormNoInspection/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoinspectionNotPresent(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoinspectionPresent(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
'--phpstorm-noinspections' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
* @noinspection PhpFullyQualifiedNameUsageInspection
|
||||||
|
* @noinspection PhpUnnecessaryFullyQualifiedNameInspection
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
|
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
// Regular relations
|
||||||
|
public function relationHasMany(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasOne(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasOneWithDefault(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Simple::class)->withDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsTo(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToMany(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToManyWithSub(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Simple::class)->where('foo', 'bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToManyWithSubAnother(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->relationBelongsToManyWithSub()->where('foo', 'bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphTo(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphOne(): MorphOne
|
||||||
|
{
|
||||||
|
return $this->morphOne(Simple::class, 'relationMorphTo');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphMany(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->morphMany(Simple::class, 'relationMorphTo');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphedByMany(): MorphToMany
|
||||||
|
{
|
||||||
|
return $this->morphedByMany(Simple::class, 'foo');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom relations
|
||||||
|
|
||||||
|
public function relationBelongsToInAnotherNamespace(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AnotherModel::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToSameNameAsColumn(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AnotherModel::class, __FUNCTION__);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class AnotherModel extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/Relations/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple $relationBelongsTo
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToInAnotherNamespace
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToMany
|
||||||
|
* @property-read int|null $relation_belongs_to_many_count
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToManyWithSub
|
||||||
|
* @property-read int|null $relation_belongs_to_many_with_sub_count
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationBelongsToManyWithSubAnother
|
||||||
|
* @property-read int|null $relation_belongs_to_many_with_sub_another_count
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\ModelsOtherNamespace\AnotherModel $relationBelongsToSameNameAsColumn
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationHasMany
|
||||||
|
* @property-read int|null $relation_has_many_count
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple|null $relationHasOne
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple $relationHasOneWithDefault
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationMorphMany
|
||||||
|
* @property-read int|null $relation_morph_many_count
|
||||||
|
* @property-read \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple|null $relationMorphOne
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $relationMorphTo
|
||||||
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple[] $relationMorphedByMany
|
||||||
|
* @property-read int|null $relation_morphed_by_many_count
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
// Regular relations
|
||||||
|
public function relationHasMany(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasOne(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationHasOneWithDefault(): HasOne
|
||||||
|
{
|
||||||
|
return $this->hasOne(Simple::class)->withDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsTo(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToMany(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Simple::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToManyWithSub(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Simple::class)->where('foo', 'bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToManyWithSubAnother(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->relationBelongsToManyWithSub()->where('foo', 'bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphTo(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphOne(): MorphOne
|
||||||
|
{
|
||||||
|
return $this->morphOne(Simple::class, 'relationMorphTo');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphMany(): MorphMany
|
||||||
|
{
|
||||||
|
return $this->morphMany(Simple::class, 'relationMorphTo');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationMorphedByMany(): MorphToMany
|
||||||
|
{
|
||||||
|
return $this->morphedByMany(Simple::class, 'foo');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom relations
|
||||||
|
|
||||||
|
public function relationBelongsToInAnotherNamespace(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AnotherModel::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function relationBelongsToSameNameAsColumn(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AnotherModel::class, __FUNCTION__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text of existing phpdoc
|
||||||
|
*
|
||||||
|
* @property string $foo
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/ResetAndSmartReset/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoReset(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text of existing phpdoc
|
||||||
|
*
|
||||||
|
* @property string $foo
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReset(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
'--reset' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSmartReset(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
'--smart-reset' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text of existing phpdoc
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple whereId($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
protected function getEnvironmentSetUp($app)
|
||||||
|
{
|
||||||
|
parent::getEnvironmentSetUp($app);
|
||||||
|
|
||||||
|
$app['config']->set('ide-helper', [
|
||||||
|
'model_locations' => [
|
||||||
|
// This is calculated from the base_path() which points to
|
||||||
|
// vendor/orchestra/testbench-core/laravel
|
||||||
|
'/../../../../tests/Console/ModelsCommand/SoftDeletes/Models',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
$actualContent = null;
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
|
||||||
|
->once();
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::capture($actualContent)
|
||||||
|
)
|
||||||
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
||||||
|
->once();
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
|
||||||
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|
||||||
|
$tester = $this->runCommand($command, [
|
||||||
|
'--write' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
|
$this->assertEmpty($tester->getDisplay());
|
||||||
|
|
||||||
|
$expectedContent = <<<'PHP'
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple newModelQuery()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple newQuery()
|
||||||
|
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple onlyTrashed()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple query()
|
||||||
|
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple whereId($value)
|
||||||
|
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple withTrashed()
|
||||||
|
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple withoutTrashed()
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Simple extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP;
|
||||||
|
|
||||||
|
$this->assertSame($expectedContent, $actualContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CustomCastsTable extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('custom_casts', static function (Blueprint $table) {
|
||||||
|
$table->string('casted_property_with_return_type');
|
||||||
|
$table->string('casted_property_with_return_docblock');
|
||||||
|
$table->string('casted_property_with_return_primitive');
|
||||||
|
$table->string('casted_property_with_return_primitive_docblock');
|
||||||
|
$table->string('casted_property_with_return_nullable_primitive');
|
||||||
|
$table->string('casted_property_without_return');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CustomDatesTable extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('custom_dates', function (Blueprint $table) {
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class PostsTable extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('posts', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
|
||||||
|
$table->char('char_nullable')->nullable();
|
||||||
|
$table->char('char_not_nullable');
|
||||||
|
|
||||||
|
$table->string('string_nullable')->nullable();
|
||||||
|
$table->string('string_not_nullable');
|
||||||
|
|
||||||
|
$table->text('text_nullable')->nullable();
|
||||||
|
$table->text('text_not_nullable');
|
||||||
|
|
||||||
|
$table->mediumText('medium_text_nullable')->nullable();
|
||||||
|
$table->mediumText('medium_text_not_nullable');
|
||||||
|
|
||||||
|
$table->longText('long_text_nullable')->nullable();
|
||||||
|
$table->longText('long_text_not_nullable');
|
||||||
|
|
||||||
|
$table->integer('integer_nullable')->nullable();
|
||||||
|
$table->integer('integer_not_nullable');
|
||||||
|
|
||||||
|
$table->tinyInteger('tiny_integer_nullable')->nullable();
|
||||||
|
$table->tinyInteger('tiny_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->smallInteger('small_integer_nullable')->nullable();
|
||||||
|
$table->smallInteger('small_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->mediumInteger('medium_integer_nullable')->nullable();
|
||||||
|
$table->mediumInteger('medium_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->bigInteger('big_integer_nullable')->nullable();
|
||||||
|
$table->bigInteger('big_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedInteger('unsigned_integer_nullable')->nullable();
|
||||||
|
$table->unsignedInteger('unsigned_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedTinyInteger('unsigned_tiny_integer_nullable')->nullable();
|
||||||
|
$table->unsignedTinyInteger('unsigned_tiny_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedSmallInteger('unsigned_small_integer_nullable')->nullable();
|
||||||
|
$table->unsignedSmallInteger('unsigned_small_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedMediumInteger('unsigned_medium_integer_nullable')->nullable();
|
||||||
|
$table->unsignedMediumInteger('unsigned_medium_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedBigInteger('unsigned_big_integer_nullable')->nullable();
|
||||||
|
$table->unsignedBigInteger('unsigned_big_integer_not_nullable');
|
||||||
|
|
||||||
|
$table->float('float_nullable')->nullable();
|
||||||
|
$table->float('float_not_nullable');
|
||||||
|
|
||||||
|
$table->double('double_nullable')->nullable();
|
||||||
|
$table->double('double_not_nullable');
|
||||||
|
|
||||||
|
$table->decimal('decimal_nullable')->nullable();
|
||||||
|
$table->decimal('decimal_not_nullable');
|
||||||
|
|
||||||
|
$table->unsignedDecimal('unsigned_decimal_nullable')->nullable();
|
||||||
|
$table->unsignedDecimal('unsigned_decimal_not_nullable');
|
||||||
|
|
||||||
|
$table->boolean('boolean_nullable')->nullable();
|
||||||
|
$table->boolean('boolean_not_nullable');
|
||||||
|
|
||||||
|
$table->enum('enum_nullable', ['foo', 'bar'])->nullable();
|
||||||
|
$table->enum('enum_not_nullable', ['foo', 'bar']);
|
||||||
|
|
||||||
|
$table->json('json_nullable')->nullable();
|
||||||
|
$table->json('json_not_nullable');
|
||||||
|
|
||||||
|
$table->jsonb('jsonb_nullable')->nullable();
|
||||||
|
$table->jsonb('jsonb_not_nullable');
|
||||||
|
|
||||||
|
$table->date('date_nullable')->nullable();
|
||||||
|
$table->date('date_not_nullable');
|
||||||
|
|
||||||
|
$table->dateTime('datetime_nullable')->nullable();
|
||||||
|
$table->dateTime('datetime_not_nullable');
|
||||||
|
|
||||||
|
$table->dateTimeTz('datetimetz_nullable')->nullable();
|
||||||
|
$table->dateTimeTz('datetimetz_not_nullable');
|
||||||
|
|
||||||
|
$table->time('time_nullable')->nullable();
|
||||||
|
$table->time('time_not_nullable');
|
||||||
|
|
||||||
|
$table->timeTz('timetz_nullable')->nullable();
|
||||||
|
$table->timeTz('timetz_not_nullable');
|
||||||
|
|
||||||
|
$table->timestamp('timestamp_nullable')->nullable();
|
||||||
|
$table->timestamp('timestamp_not_nullable');
|
||||||
|
|
||||||
|
$table->timestampTz('timestamptz_nullable')->nullable();
|
||||||
|
$table->timestampTz('timestamptz_not_nullable');
|
||||||
|
|
||||||
|
$table->year('year_nullable')->nullable();
|
||||||
|
$table->year('year_not_nullable');
|
||||||
|
|
||||||
|
$table->binary('binary_nullable')->nullable();
|
||||||
|
$table->binary('binary_not_nullable');
|
||||||
|
|
||||||
|
$table->uuid('uuid_nullable')->nullable();
|
||||||
|
$table->uuid('uuid_not_nullable');
|
||||||
|
|
||||||
|
$table->ipAddress('ipaddress_nullable')->nullable();
|
||||||
|
$table->ipAddress('ipaddress_not_nullable');
|
||||||
|
|
||||||
|
$table->macAddress('macaddress_nullable')->nullable();
|
||||||
|
$table->macAddress('macaddress_not_nullable');
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class SimpleTable extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('simples', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
-8
@@ -1,8 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
class ExampleTest extends \PHPUnit_Framework_TestCase
|
use Barryvdh\LaravelIdeHelper\Method;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ExampleTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test that we can actually instantiate the class
|
* Test that we can actually instantiate the class
|
||||||
@@ -32,17 +35,33 @@ class ExampleTest extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @param string $last
|
* @param string $last
|
||||||
* @param string $first
|
* @param string $first
|
||||||
|
* @param string $middle
|
||||||
* @static
|
* @static
|
||||||
*/';
|
*/';
|
||||||
$this->assertEquals($output, $method->getDocComment(''));
|
$this->assertEquals($output, $method->getDocComment(''));
|
||||||
$this->assertEquals('setName', $method->getName());
|
$this->assertEquals('setName', $method->getName());
|
||||||
$this->assertEquals('\\'.ExampleClass::class, $method->getDeclaringClass());
|
$this->assertEquals('\\'.ExampleClass::class, $method->getDeclaringClass());
|
||||||
$this->assertEquals('$last, $first', $method->getParams(true));
|
$this->assertEquals('$last, $first, ...$middle', $method->getParams(true));
|
||||||
$this->assertEquals(['$last', '$first'], $method->getParams(false));
|
$this->assertEquals(['$last', '$first', '...$middle'], $method->getParams(false));
|
||||||
$this->assertEquals('$last, $first = \'Barry\'', $method->getParamsWithDefault(true));
|
$this->assertEquals('$last, $first = \'Barry\', ...$middle', $method->getParamsWithDefault(true));
|
||||||
$this->assertEquals(['$last', '$first = \'Barry\''], $method->getParamsWithDefault(false));
|
$this->assertEquals(['$last', '$first = \'Barry\'', '...$middle'], $method->getParamsWithDefault(false));
|
||||||
$this->assertEquals(true, $method->shouldReturn());
|
$this->assertEquals(true, $method->shouldReturn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test special characters in methods default values
|
||||||
|
*/
|
||||||
|
public function testDefaultSpecialChars()
|
||||||
|
{
|
||||||
|
$reflectionClass = new \ReflectionClass(ExampleClass::class);
|
||||||
|
$reflectionMethod = $reflectionClass->getMethod('setSpecialChars');
|
||||||
|
|
||||||
|
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
||||||
|
$this->assertEquals('$chars', $method->getParams(true));
|
||||||
|
$this->assertEquals(['$chars'], $method->getParams(false));
|
||||||
|
$this->assertEquals('$chars = \'$\\\'\\\\\'', $method->getParamsWithDefault(true));
|
||||||
|
$this->assertEquals(['$chars = \'$\\\'\\\\\''], $method->getParamsWithDefault(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExampleClass
|
class ExampleClass
|
||||||
@@ -50,9 +69,15 @@ class ExampleClass
|
|||||||
/**
|
/**
|
||||||
* @param string $last
|
* @param string $last
|
||||||
* @param string $first
|
* @param string $first
|
||||||
|
* @param string $middle
|
||||||
*/
|
*/
|
||||||
public function setName($last, $first = 'Barry')
|
public function setName($last, $first = 'Barry', ...$middle)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function setSpecialChars($chars = "\$'\\")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
|
abstract class TestCase extends BaseTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The `CommandTester` is directly returned, use methods like
|
||||||
|
* `->getDisplay()` or `->getStatusCode()` on it.
|
||||||
|
*
|
||||||
|
* @param Command $command
|
||||||
|
* @param array $arguments The command line arguments, array of key=>value
|
||||||
|
* Examples:
|
||||||
|
* - named arguments: ['model' => 'Post']
|
||||||
|
* - boolean flags: ['--all' => true]
|
||||||
|
* - arguments with values: ['--arg' => 'value']
|
||||||
|
* @param array $interactiveInput Interactive responses to the command
|
||||||
|
* I.e. anything the command `->ask()` or `->confirm()`, etc.
|
||||||
|
* @return CommandTester
|
||||||
|
*/
|
||||||
|
protected function runCommand(Command $command, array $arguments = [], array $interactiveInput = []): CommandTester
|
||||||
|
{
|
||||||
|
$command->setLaravel($this->app);
|
||||||
|
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->setInputs($interactiveInput);
|
||||||
|
|
||||||
|
$tester->execute($arguments);
|
||||||
|
|
||||||
|
return $tester;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user