Skip to content

Commit 8d5d96f

Browse files
committed
Add basic unit test
1 parent a242e13 commit 8d5d96f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/RectorPluginTest.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Phpcq\PluginRectorTest;
6+
7+
use Phpcq\PluginApi\Version10\Configuration\PluginConfigurationBuilderInterface;
8+
use Phpcq\PluginApi\Version10\Configuration\PluginConfigurationInterface;
9+
use Phpcq\PluginApi\Version10\DiagnosticsPluginInterface;
10+
use Phpcq\PluginApi\Version10\EnvironmentInterface;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/** @covers src/rector.php */
14+
final class RectorPluginTest extends TestCase
15+
{
16+
private function instantiate(): DiagnosticsPluginInterface
17+
{
18+
return include dirname(__DIR__) . '/src/rector.php';
19+
}
20+
21+
public function testPluginDescribesConfig(): void
22+
{
23+
$configOptionsBuilder = $this->getMockForAbstractClass(
24+
PluginConfigurationBuilderInterface::class
25+
);
26+
27+
$configOptionsBuilder->expects(self::once())
28+
->method('describeStringOption')
29+
->with('config', 'Path to config file');
30+
31+
$configOptionsBuilder->expects(self::once())
32+
->method('describeBoolOption')
33+
->with('dry-run', 'Only see the diff of changes, do not save them to files.');
34+
35+
$this->instantiate()->describeConfiguration($configOptionsBuilder);
36+
37+
// We assume it worked out as the plugin did execute correctly.
38+
$this->addToAssertionCount(1);
39+
}
40+
public function testPluginCreatesDiagnosticTasks(): void
41+
{
42+
$config = $this->getMockForAbstractClass(PluginConfigurationInterface::class);
43+
$environment = $this->getMockForAbstractClass(EnvironmentInterface::class);
44+
45+
$this->instantiate()->createDiagnosticTasks($config, $environment);
46+
47+
// We assume it worked out as the plugin did execute correctly.
48+
$this->addToAssertionCount(1);
49+
}
50+
}

0 commit comments

Comments
 (0)