Commit Graph
112 Commits
Author SHA1 Message Date
Aleksei Lebedev 25cc68c75f Macro::initPhpDoc() will save original docblock if present. (#1116)
* `Macro::initPhpDoc()` will save original docblock if present.

* Added `MacroTest::testInitPhpDocClosureWithoutDocBlock()`.

* Mock class rename.

* Code cleanup.
2020-12-23 12:26:18 +01:00
Aleksei Lebedev 36c4406b3a Alias will grab macros from \Illuminate\Database\Eloquent\Builder too (#1118)
* `Alias` will grab macros from `\Illuminate\Database\Eloquent\Builder` too.

* `@return` will contains `|static` for Eloquent Builder macros which return Eloquent Builder instance.

* `Macro` tests.

* `Alias::detectMethods()` tests.

* Mock classes rename.
2020-12-21 11:15:47 +01:00
Kaloqn 5515cabea3 FQCN bugfix when writing external eloquent builder methods inside models. (#1113)
* Fix code that was causing the test to break and fix bug with not built in types

* Run cs fixer

* Remove fetching the doc block type and the putting it as a type hint as a php doc block is sufficient

* Revert doc block type hinting

* Enchance doc block type hinting

* Combine replacements

* Use the full builder class instead of the parsed one after the getClassName function and remove in array check

* Get the builder from the model itself instead of passing a string directly the function

* Use the full builder class to get the builder methods and reflection, but use the parsed builder class after setting its method in the doc

* Add test for fqn support on external eloquent builder

* Use the external builder if necessary when building the magic wheres

* Use the default eloquent builder if the user has disabled the external builder option
2020-12-06 09:55:05 +01:00
Kaloqn 9859958cfa Fix broken test "GeneratePhpdocWithExternalEloquentBuilder" (#1111)
* Fix code that was causing the test to break and fix bug with not built in types

* Run cs fixer

* Remove fetching the doc block type and the putting it as a type hint as a php doc block is sufficient

* Revert doc block type hinting

* Enchance doc block type hinting

* Combine replacements
2020-12-04 14:23:42 +01:00
Barry vd. Heuvel 113545bc1a Fix snapshot 2020-12-04 09:25:31 +01:00
Barry vd. Heuvel ff54a20d21 Fix CS 2020-12-04 09:22:58 +01:00
Kaloqn db53e8e2b5 Add support for dedicated eloquent builders and type/doc parameter support. (#1089)
* Add support for generating helpers for external eloquent builders

* Extract external builder methods generator to its own method and add an option to toggle this feature

* Check if we are using the default name of the eloquent builder

* Add tests with snapshots for external eloquent builder feature

* Refactor codegs

* Allow for type hinting

* Update test

* Run cs fix

* Update readme

* Use getName for parameter instead of relying on __toString()

* Do not use str_contains and use built in php method
2020-12-04 07:36:08 +01:00
Matthew Hailwood b3a79fe6c1 Allow casts with a return type of static or this to reference themselves (#1103)
* Allow casts with a return type of static or this to reference themselves

Supports

```php
/**
     * @param $model
     * @param string $key
     * @param $value
     * @param array $attributes
     * @return static
     */
    public function get($model, string $key, $value, array $attributes)
    {
        return new static($value);
    }
```

or

```php
/**
     * @param $model
     * @param string $key
     * @param $value
     * @param array $attributes
     * @return $this
     */
    public function get($model, string $key, $value, array $attributes)
    {
        return new static($value);
    }
```

* Update CHANGELOG.md
2020-12-04 07:33:45 +01:00
Markus Podar b4138e5122 [PHP8] Add initial compatibility (#1106)
* gha: run on PHP8 too

The composer.json constraint is unbound, so it's already "allowed" at least.

* gha: remove php-cs-fixer when running unit tests

- not necessary anyway
- not compatible with PHP8 currently

* gha: lumen 6 and 7 don't support PHP8

* composer.json: allow spatie/phpunit-snapshot-assertions 4.* for PHP8 compatibility

* php8-compat: Method ReflectionParameter::getClass() is deprecated

* php8-compat: adapt expected error message depending on PHP version

* composer.json: bump mockery to 1.3.3 minimum

This is the minimum version also supporting PHP8

* gha: disable prefer-lowest for PHP8

Some lower version requirements like doctrone/dbal won't work and
would require at least dbal 2.12.0, which in turn doesn't support PHP 7.2
anymore.

So instead of bumping dbal and excluding PHP 7.2 users, we ignore the
lowest version for PHP 8 for the time being.

* Update CHANGELOG.md
2020-12-04 07:28:07 +01:00
Chun-Sheng, Liandlaravel-ide-helper 317889805b Test enhancement (#1100)
* Improve PHPUnit assertions

* composer fix-style

Co-authored-by: laravel-ide-helper <[email protected]>
2020-11-30 15:33:15 +01:00
Isaac EarlandMarkus Podar 1044f466e9 allow model_locations to have glob patterns (#1059)
* allow model_locations to have glob patterns

This if statement check for a valid directory was happening to early.  It was checking the string that contained the wildcards to see if it is a valid directory and always failing.  Need to check after the foreach starts. fixes #1058 .

* test(#1059) Allow glob directories

* Fix tests to chdir() into where to expect the glob to work

* Update CHANGELOG.md

Co-authored-by: Markus Podar <[email protected]>
2020-09-20 22:06:24 +02:00
Igor Finagin fd4d280a80 [LARAVEL 8] include_factory_builders does not work anymore (#1047) (#1049)
* [LARAVEL 8] include_factory_builders does not work anymore (#1047)

* Change skip expression
Append comment about deprecated to config file
Append comment about deprecated to README file
2020-09-20 08:36:35 +02:00
Markus Podar 5db6029f2c Give feedback when a relation can't be resolved (#1052)
Improves https://github.com/barryvdh/laravel-ide-helper/pull/1017 slightly
2020-09-10 21:58:16 +02:00
efinder2andMarkus Podar 7305504c99 Created a positiblity to add custom relation type (#987)
* Created a positiblity to add custom relation type

* Changed access modifier

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

* fixed hints from code review

* Added Test for https://github.com/barryvdh/laravel-ide-helper/pull/987

* composer fix-style

* Clarify doc in config entry

* Update CHANGELOG.md

Co-authored-by: Markus Podar <[email protected]>
2020-09-08 07:18:43 +02:00
Artem KryukovandMarkus Podar 186340bedc Fix phpdoc generate for custom cast with parameter (#986)
* Fix phpdoc generate for custom cast with parameter

* Add param for cast

* Simplify cast class name normalizing

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

* Update changelog

* composer fix-style

Co-authored-by: Markus Podar <[email protected]>
2020-09-07 22:39:35 +02:00
edcorewebandMarkus Podar 24596b67f1 New --write-mixin option. (#764)
* New --write-mixin option.

* Keep all tags from the existing docblock.

* Update argument description to be more descriptive

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

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

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

* Update README.md

* composer fix-style

* Adapt test after refactoring recently done

Co-authored-by: Markus Podar <[email protected]>
2020-09-06 07:57:00 +02:00
Markus Podar 007d3adb68 Run composer fix-style and vendor/bin/phpunit -d --update-snapshots to solve failed build (#1032) 2020-09-01 19:50:05 +02:00
Markus PodarandBarry vd. Heuvel 764bc02b84 [CODESTYLE] Replace phpcs with php-cs-fixer (#1030)
* composer require --dev friendsofphp/php-cs-fixer:^2

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

* php-cs-fixer: initial config

* php-cs-fixer: replace commands in composer

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

* php-cs-fixer: apply PSR12 to codebase

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

* php-cs-fixer: apply no_unused_imports

* php-cs-fixer: apply array_syntax short

* php-cs-fixer: apply single_quote

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

Let's be opinionated here for consistency

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

* php-cs-fixer: apply declare_strict_types for tests

* php-cs-fixer: apply fully_qualified_strict_types

* php-cs-fixer: apply space_after_semicolon

* php-cs-fixer: apply trailing_comma_in_multiline_array

* php-cs-fixer: apply trim_array_spaces

* php-cs-fixer: apply unary_operator_spaces

* php-cs-fixer: apply whitespace_after_comma_in_array

* php-cs-fixer: apply native_function_invocation

* php-cs-fixer: apply concat_space

* grumphp: reflect we're using phpcsfixer now

* composer remove --dev squizlabs/php_codesniffer

* gha: simplify fix-style approach

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

Co-authored-by: Barry vd. Heuvel <[email protected]>
2020-09-01 11:32:31 +02:00
edvordo a96add6981 update(config/model command): add option to force usage of FQN + tests (#1031) 2020-09-01 09:11:12 +02:00
Markus Podar 1ca875fbca Make createLocalViewFactory compatible with Laravel 8 (#1026)
* Make createLocalViewFactory compatible with Laravel 8

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

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

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

* tests: show basic features for ide-helper:meta working
2020-08-31 06:20:02 +02:00
Markus Podar 3b66fea925 tests: no need for < 6 check, as we don't test < L6 anymore (#1025) 2020-08-30 21:32:15 +02:00
Markus Podar 707ec990e7 tests: remove L5.5 workaround (#1023) 2020-08-29 08:12:11 +02:00
Barry vd. Heuvelandbarryvdh a49cb46fdf Bump Laravel versions (#1022)
* Bump Laravel versions

* Test Laravel 8

* Update composer.json

* Update composer.json

* normalize composer.json

* Tweak MethodTest for Laravel 8

Co-authored-by: barryvdh <[email protected]>
2020-08-28 22:26:05 +02:00
Barry vd. Heuvel 9599cfbbc9 Simplify test by mocking filesystem always (#1019) 2020-08-25 17:43:39 +02:00
Barry vd. Heuvel c852650d7e Test dynamic relationships (#1017)
* Test dynamic

* Try/catch relationships

* Update snapshot

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

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

The call added in `runCommand` explicitly unregisters
`\Illuminate\Console\OutputStyle` and thus also throwing away possibly
mocked versions.
2020-08-25 06:29:44 +02:00
Markus Podar ba95d18ef5 [PHPCS] Extend to check/fix all source code and turn GHA into auto-commit fixer (#1003)
* phpcs: enable also for config, resources and tests

* composer fix-style

* vendor/bin/phpunit -d --update-snapshots

* gha: instead of checking the style, fix and auto-commit it 💪
2020-08-10 10:22:48 +02:00
Gabriel Langer e8044dc920 [Models] Fixed wrong imported name (#993)
* Fixes 992 (class names in phpdoc where using imported names incorrectly when writing to external file).
Disabled using imported name in external file, except for the models own name.

* Added missing declare strict types
2020-07-17 08:07:09 +02:00
Markus Podar 0531a58d24 tests: convert recently created tests to snapshots (#973)
They were created slightly before the snapshot PR was merged.
2020-06-24 15:29:19 +02:00
07d45d2d7a switch tests to snapshot assertions (#958)
* install spatie/phpunit-snapshot-assertions

* switch GenerateBasicPhpdocFinal test to snapshot assertion

* use v3 of spatie/phpunit-snapshot-assertions to be PHP7.2 compatible

* add txt snapshot driver

* fix EloquentCommandTest

* replace all heredocs by snapshots

* make test compatible with old/deprecated versions

* Update composer.json

* normalize composer.json

* fix merge conflict

* Allow older snapshot versions

* normalize composer.json

Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: barryvdh <[email protected]>
2020-06-24 11:11:35 +02:00
Luka Schäfer cca99b6d25 Make writing relation count properties optional (#969)
* Make writing relation count properties optional

* Clean up description

* Add test for write_model_magic_where=false

* Add test for write_model_relation_count_properties=false
2020-06-23 22:27:43 +02:00
Tom Witkowski b9293420c3 add phpunit tests (#957) 2020-06-22 13:32:19 +02:00
Gabriel Langer 6f20800eef [Model] Simplify full namespaces for already included resources (#954)
* Fixed #565 by using the imported class name if present. Fixed a bug where cast type was not properly added when the return type was found via phpdoc.

* Fixed errors with phpdocumentor/type-resolver:1.0
2020-06-20 12:53:36 +02:00
Tom Witkowski 7203ebee24 Fix inline doc-block for final models (#955)
* fix final model classes doc-block generation

* add phpunit tests
2020-06-20 08:22:07 +02:00
fgibaux d35ea6e1d4 Decimal columns as string in Models (#948)
* Decimal columns as string in Models

To follow Eloquent casts

* update tests for decimals
2020-06-09 20:54:26 +02:00
Daniel Mason 378adeb1f5 Add static return type to builder methods (#924)
* Add static return type to builder methods

* formatting

* add eloquent builder test

* change to use assertSame
2020-04-22 21:18:54 +02:00
belamov cfa9a81d65 Added support for Laravel 7 custom casts (#913)
* added support for laravel 7 custom casts

* refactored tests; added test cases

* added test case

* resolved method dublication
2020-04-22 06:32:40 +02:00
mzglinskiandMichał Zgliński dcf76c1a81 Generate noinspections PHPStorm tags (#905)
* Generate noinspections PHPStorm tags

* Add comments about PHPStorm noinspection tags

* Fix line to long warnings

* Add tests for PHPStorm noinspection

Co-authored-by: Michał Zgliński <[email protected]>
2020-04-21 21:36:27 +02:00
Barry vd. Heuvel bef8158d02 Merge pull request #901 from loilo/fix-default-param-values
Prevent generation of invalid code for certain parameter default values
2020-04-21 21:35:11 +02:00
Barry vd. Heuvel 8381a2ebdd Merge pull request #906 from mfn/mfn-return-reflection
Infer return type from reflection if no phpdoc given
2020-04-21 21:16:27 +02:00
Feek 2617352869 if a model implements interfaces, include them in the stub 2020-04-21 02:32:02 -07:00
Markus Podar f4ae4c4b45 Remove unnecessary and wrong definition of SoftDelete methods (#918)
These two methods are already regular methods on the trait, there's no
need to add them and additionally they're not static, so their
definition was changed for the worse.

The other methods are magic so it's fine to keep them.

Fixes https://github.com/barryvdh/laravel-ide-helper/issues/917
2020-04-19 07:49:54 +02:00
Daniel MasonandMarkus Podar 6a27c5df68 Add custom collection support for get and all methods (#903)
* Add custom collection support for get and all methods

* Only add get and all when using custom collection

* Use static instead of class name

* Add missing custom collection test with relation

* Use class reference over string

Co-Authored-By: Markus Podar <[email protected]>

* Fix when using class reference

Co-authored-by: Markus Podar <[email protected]>
2020-04-19 07:49:23 +02:00
Markus Podar b72689755b Infer return type from reflection if no phpdoc given 2020-04-01 22:44:26 +02:00
Florian ReuschelandMarkus Podar 3cc7d7ccf6 Improve test method doc block
Co-Authored-By: Markus Podar <[email protected]>
2020-03-31 21:19:33 +02:00
leo108 18588eacf3 Make hasOne / hasOneThrough and morphOne nullable. (#864) 2020-03-31 14:40:50 +02:00
Loilo da59650fb2 Add test for method default values with special chars 2020-03-26 09:37:33 +01:00
Pataar 0692626c41 Add ignored_models as config option (#890)
* Add ignored_models as config option

* Add README.md entry

* Add tests

* Change name of test class

* Add Ignored to the return values from the mocked filesystem

* Improve test speed by adding prestissimo

* Revert "Improve test speed by adding prestissimo"

This reverts commit 246a9f2a78.
2020-03-10 12:18:29 +01:00
Sergio García 90437012b8 Fix camelCase duplicated properties generator. (#881)
* Fix camelCase duplicated properties generator.

* Add basic tests for camel case
2020-03-10 12:17:29 +01:00
Kirill Uksusov e743f44011 Fixed #892 (#894)
* Fixed #892

* #892 test added
2020-03-03 10:48:00 +01:00