Skip to content

Commit

Permalink
Upgraded test code, added Psalm PHPUnit plugin to better understand P…
Browse files Browse the repository at this point in the history
…HPUnit semantics
  • Loading branch information
Ocramius committed Feb 5, 2025
1 parent 6d1c3a0 commit 3f6f321
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 25 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ext-zip": "^1.15.0",
"roave/infection-static-analysis-plugin": "^1.36.0",
"phpunit/phpunit": "^9.6.22",
"psalm/plugin-phpunit": "^0.19.2",
"vimeo/psalm": "^6.3.0"
},
"replace": {
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 4 additions & 23 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
rememberPropertyAssignmentsAfterCall="false"
errorLevel="1"
>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>

<projectFiles>
<directory name="src"/>
<directory name="test/PackageVersionsTest"/>
Expand All @@ -14,27 +18,4 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<InternalClass>
<errorLevel type="suppress">
<directory name="test/PackageVersionsTest"/>
</errorLevel>
</InternalClass>
<InternalMethod>
<errorLevel type="suppress">
<directory name="test/PackageVersionsTest"/>
</errorLevel>
</InternalMethod>
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="test/PackageVersionsTest"/>
</errorLevel>
</PropertyNotSetInConstructor>
<DeprecatedMethod>
<errorLevel type="suppress">
<directory name="test/PackageVersionsTest"/>
</errorLevel>
</DeprecatedMethod>
</issueHandlers>
</psalm>
1 change: 1 addition & 0 deletions src/PackageVersions/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

final class Versions
{
/** @psalm-suppress UnusedConstructor */
private function __construct()
{
}
Expand Down
10 changes: 9 additions & 1 deletion test/PackageVersionsTest/VersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
use PHPUnit\Framework\TestCase;

use function array_merge;
use function assert;
use function file_get_contents;
use function is_string;
use function json_decode;
use function uniqid;

use const JSON_THROW_ON_ERROR;

/** @covers \PackageVersions\Versions */
final class VersionsTest extends TestCase
{
public function testValidVersions(): void
{
$contents = file_get_contents(__DIR__ . '/../../composer.lock');

assert(is_string($contents));

/**
* @var array{
* packages: array<string, array{
Expand All @@ -36,7 +44,7 @@ public function testValidVersions(): void
* }>,
* } $lockData
*/
$lockData = json_decode(file_get_contents(__DIR__ . '/../../composer.lock'), true);
$lockData = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);

$packages = array_merge($lockData['packages'], $lockData['packages-dev']);

Expand Down

0 comments on commit 3f6f321

Please sign in to comment.