Skip to content

Commit

Permalink
Merge pull request #248 from dkuzmenchuk/fix-undefined-method-call-in…
Browse files Browse the repository at this point in the history
…-fake-models-command

Rename method to get model's properties
  • Loading branch information
lptn authored Jan 14, 2023
2 parents 8093dd3 + b1d2701 commit 7f06992
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fakes/FakeModelsCommandLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getModels(): array
*
* @param Model $model
*/
public function getPropertiesFromTable($model): void
public function getProperties($model): void
{
$table_name = $model->getTable();

Expand Down
14 changes: 14 additions & 0 deletions tests/Support/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Module extends BaseModule
protected array $config = [
'psalm_path' => 'vendor/bin/psalm',
'default_dir' => 'tests/_run/',
'model_stubs_path' => 'cache/models.stubphp',
];

/** @var string */
Expand Down Expand Up @@ -200,6 +201,19 @@ public function seeNoErrors(): void
}
}

/**
* @Then Stubs were generated for these Eloquent Models
*/
public function stubsGeneratedForModels(TableNode $list): void
{
$this->fs()->openFile($this->config['model_stubs_path']);

foreach ($list->getRows() as $line) {
assert(is_array($line));
$this->fs()->seeInThisFile($line[0]);
}
}

private function packageSatisfiesVersionConstraint(string $package, string $versionConstraint): bool
{
try {
Expand Down
32 changes: 32 additions & 0 deletions tests/acceptance/EloquentModelStubGenerating.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: Eloquent Model stub generating
Stubs for Eloquent Models were correctly generated

Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm errorLevel="1" usePhpDocPropertiesWithoutMagicCall="true">
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
</plugins>
</psalm>
"""

Scenario: Generate stubs for Eloquent Models
When I run Psalm
Then Stubs were generated for these Eloquent Models
| final class Car extends \Eloquent |
| final class Comment extends \Eloquent |
| final class Image extends \Eloquent |
| final class Mechanic extends \Eloquent |
| final class Phone extends \Eloquent |
| final class Post extends \Eloquent |
| final class Role extends \Eloquent |
| final class Secret extends \Eloquent |
| final class Tag extends \Eloquent |
| final class User extends \Eloquent |
| final class Video extends \Eloquent |

0 comments on commit 7f06992

Please sign in to comment.