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

Psalm integration #36

Merged
merged 4 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ precedence over the former when running tests, and is ignored by version
control. (If you want to make the modifications permanent, edit the
`phpunit.xml.dist` file.)

## Running Psalm Static Analysis

To run the supplied skeleton static analysis, you need to do one of the following:
It is recommended to install the test components from laminas (laminas/laminas-test),
as this is used in the tests supplied.

```bash
$ composer require --dev vimeo/psalm psalm/plugin-phpunit laminas/laminas-test
```

Once psalm support is present, you can run the static analysis using:

```bash
$ composer static-analysis
```

## Using Vagrant

This skeleton includes a `Vagrantfile` based on ubuntu 18.04 (bento box)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
"php -r 'if (file_exists(\"CHANGELOG.md\")) unlink(\"CHANGELOG.md\");'"
],
"serve": "php -S 0.0.0.0:8080 -t public",
"test": "phpunit"
"test": "phpunit",
"static-analysis": "vendor/bin/psalm --shepherd --stats"
},
"scripts-descriptions": {
"cs-check": "Run coding standards checks.",
Expand Down
2 changes: 1 addition & 1 deletion module/Application/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Module
{
public function getConfig() : array
{
return include __DIR__ . '/../config/module.config.php';
return (array) include __DIR__ . '/../config/module.config.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do with :

/** @var array $config */
$config = include __DIR__ . '/../config/module.config.php';
return $config;

instead of (array) cast as the config/module.config.php is an array already.

}
}
6 changes: 3 additions & 3 deletions module/Application/test/Controller/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setUp() : void
parent::setUp();
}

public function testIndexActionCanBeAccessed()
public function testIndexActionCanBeAccessed(): void
{
$this->dispatch('/', 'GET');
$this->assertResponseStatusCode(200);
Expand All @@ -42,13 +42,13 @@ public function testIndexActionCanBeAccessed()
$this->assertMatchedRouteName('home');
}

public function testIndexActionViewModelTemplateRenderedWithinLayout()
public function testIndexActionViewModelTemplateRenderedWithinLayout(): void
{
$this->dispatch('/', 'GET');
$this->assertQuery('.container .jumbotron');
}

public function testInvalidRouteDoesNotCrash()
public function testInvalidRouteDoesNotCrash(): void
{
$this->dispatch('/invalid/route', 'GET');
$this->assertResponseStatusCode(404);
Expand Down
38 changes: 38 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<psalm
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="module" />
<directory name="config" />

<file name="public/index.php" />

<ignoreFiles>
<directory name="vendor" />
<directory name="data" />
<directory name="bin" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<InternalMethod>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
</errorLevel>
</InternalMethod>
</issueHandlers>

<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>