Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TESTS] Add some basic tests for ModelsCommand #869

Merged
merged 7 commits into from
Jan 3, 2020

Conversation

mfn
Copy link
Collaborator

@mfn mfn commented Jan 3, 2020

Only add tests, no other functional change

Given that #865 was accepted and we've now the foundation for writing tests, I came up with some basic tests regarding the ModelsCommand.

The general idea is to show it's doable / easy (maybe not always 😄 ) and to inspire maybe others to contribute also to tests when they e.g. add/change features.

I added:

  • a primitive general test for phpdoc \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Test::test
  • one for custom date classes I recently added: \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Test::test

The tests might look a bit unconventional regarding:

  • directory with a single test file and a single test method
  • shared database migrations
    but
  • separate models

The main reason is that ModelsCommand behaves differently when scanning a directory with multiple models It would (of course) always process all of them, which makes testing / mocking more cumbersome. So I decided to split this and better isolate this from each other.

Please note this is only a very small "get things going" test additional and by all means, we know there's much more to test (relations etc.).

Tests are skipped for Laravel < 6.0

I started out trying to get it work for Laravel 5.5 and 5.8 but ran into problems. After investing some time I decided not to invest more and skipped it.

Problems I had with 5.5

Tests didn't work, threw this error:

1) Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Test::test

Symfony\Component\Console\Exception\InvalidOptionException: The "--realpath" option does not exist.
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Input/ArrayInput.php:172
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Input/ArrayInput.php:134
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Input/Input.php:63
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Command/Command.php:222
/home/travis/build/mfn/laravel-ide-helper/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Application.php:869
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Application.php:223
/home/travis/build/mfn/laravel-ide-helper/vendor/symfony/console/Application.php:130
/home/travis/build/mfn/laravel-ide-helper/vendor/laravel/framework/src/Illuminate/Console/Application.php:82
/home/travis/build/mfn/laravel-ide-helper/vendor/laravel/framework/src/Illuminate/Console/Application.php:171
/home/travis/build/mfn/laravel-ide-helper/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:258
/home/travis/build/mfn/laravel-ide-helper/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php:18
/home/travis/build/mfn/laravel-ide-helper/vendor/orchestra/testbench-core/src/Traits/WithLoadMigrationsFrom.php:26
/home/travis/build/mfn/laravel-ide-helper/tests/Console/ModelsCommand/AbstractModelsCommand.php:13
/home/travis/build/mfn/laravel-ide-helper/tests/Console/ModelsCommand/CustomDate/Test.php:17

I googled and came to orchestral/testbench#153 and https://github.com/orchestral/testbench/tree/3.5#running-testing-migrations but still couldn't make it work, thus skipped it.

I actually got this working for https://github.com/rebing/graphql-laravel but checked the sources and it looked the same => all traces of this attempt are however already removed.

Problems I had with 5.8

The generated types are different 🤪:

1) Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Test::test
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 /**
  * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpdoc\Models\Post
  *
- * @property integer $id
+ * @property int $id
  * @property string $title
  * @property string|null $body
- * @property integer $visible
+ * @property int $visible
  * @property string $publicated_at
  * @property \Illuminate\Support\Carbon|null $created_at
  * @property \Illuminate\Support\Carbon|null $updated_at

/home/travis/build/mfn/laravel-ide-helper/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php:88

I didn't wanted to invest too much here

@mfn
Copy link
Collaborator Author

mfn commented Jan 3, 2020

@barryvdh all green here √

@barryvdh barryvdh merged commit d9a731d into barryvdh:master Jan 3, 2020
@barryvdh
Copy link
Owner

barryvdh commented Jan 3, 2020

Thanks!

@mfn mfn deleted the mfn-modelscmd-tests branch January 3, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants