File tree 17 files changed +343
-0
lines changed
17 files changed +343
-0
lines changed Original file line number Diff line number Diff line change
1
+ codeception.yml export-ignore
2
+ .gitattributes export-ignore
3
+ .github export-ignore
4
+ .gitignore export-ignore
5
+ phpcs.xml.dist export-ignore
6
+ phpunit.xml.dist export-ignore
7
+ psalm.xml.dist export-ignore
8
+ tests export-ignore
Original file line number Diff line number Diff line change
1
+ name : build
2
+
3
+ on : [push, pull_request]
4
+
5
+ jobs :
6
+ tests :
7
+ runs-on : ubuntu-latest
8
+ steps :
9
+ - uses : actions/checkout@v2
10
+ - uses : shivammathur/setup-php@v2
11
+ with :
12
+ php-version : 8.0
13
+ - uses : ramsey/composer-install@v1
14
+ - run : composer check
Original file line number Diff line number Diff line change
1
+ /vendor /
2
+ composer.lock
3
+ vendor
4
+ .php-version
5
+ .phpunit.result.cache
6
+ tests /_run /*
7
+ tests /_support /_generated /*
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Weirdan \PsalmPluginSkeleton ;
4
+
5
+ use SimpleXMLElement ;
6
+ use Psalm \Plugin \PluginEntryPointInterface ;
7
+ use Psalm \Plugin \RegistrationInterface ;
8
+
9
+ class Plugin implements PluginEntryPointInterface
10
+ {
11
+ /** @return void */
12
+ public function __invoke (RegistrationInterface $ psalm , ?SimpleXMLElement $ config = null ): void
13
+ {
14
+ // This is plugin entry point. You can initialize things you need here,
15
+ // and hook them into psalm using RegistrationInterface
16
+ //
17
+ // Here's some examples:
18
+ // 1. Add a stub file
19
+ // ```php
20
+ // $psalm->addStubFile(__DIR__ . '/stubs/YourStub.php');
21
+ // ```
22
+ foreach ($ this ->getStubFiles () as $ file ) {
23
+ $ psalm ->addStubFile ($ file );
24
+ }
25
+
26
+ // Psalm allows arbitrary content to be stored under you plugin entry in
27
+ // its config file, psalm.xml, so your plugin users can put some configuration
28
+ // values there. They will be provided to your plugin entry point in $config
29
+ // parameter, as a SimpleXmlElement object. If there's no configuration present,
30
+ // null will be passed instead.
31
+ }
32
+
33
+ /** @return list<string> */
34
+ private function getStubFiles (): array
35
+ {
36
+ return glob (__DIR__ . '/stubs/*.phpstub ' ) ?: [];
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ namespace : Weirdan\PsalmPluginSkeleton\Tests
2
+ paths :
3
+ tests : tests
4
+ output : tests/_output
5
+ data : tests/_data
6
+ support : tests/_support
7
+ envs : tests/_envs
8
+ actor_suffix : Tester
9
+ extensions :
10
+ enabled :
11
+ - Codeception\Extension\RunFailed
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " weirdan/psalm-plugin-skeleton" ,
3
+ "description" : " Template to create psalm-plugin projects from" ,
4
+ "type" : " psalm-plugin" ,
5
+ "license" : " MIT" ,
6
+ "authors" : [
7
+ {
8
+ "name" : " Bruce Weirdan" ,
9
+ "email" : " weirdan@gmail.com"
10
+ }
11
+ ],
12
+ "require" : {
13
+ "vimeo/psalm" : " dev-master"
14
+ },
15
+ "require-dev" : {
16
+ "phpunit/phpunit" : " ^9.5.5" ,
17
+ "squizlabs/php_codesniffer" : " ^3.3" ,
18
+ "psalm/plugin-phpunit" : " ^0.16.0" ,
19
+ "weirdan/prophecy-shim" : " ^2.0" ,
20
+ "weirdan/codeception-psalm-module" : " ^0.13.1" ,
21
+ "codeception/codeception" : " ^4.1"
22
+ },
23
+ "extra" : {
24
+ "psalm" : {
25
+ "pluginClass" : " Weirdan\\ PsalmPluginSkeleton\\ Plugin"
26
+ }
27
+ },
28
+ "autoload" : {
29
+ "psr-4" : {
30
+ "Weirdan\\ PsalmPluginSkeleton\\ " : [
31
+ " ."
32
+ ]
33
+ }
34
+ },
35
+ "autoload-dev" : {
36
+ "psr-4" : {
37
+ "Weirdan\\ PsalmPluginSkeleton\\ Tests\\ " : [
38
+ " tests/_support" ,
39
+ " tests"
40
+ ]
41
+ }
42
+ },
43
+ "scripts" : {
44
+ "check" : [
45
+ " @analyze" ,
46
+ " @cs-check" ,
47
+ " @unit-tests" ,
48
+ " @acceptance-tests"
49
+ ],
50
+ "analyze" : " codecept build && psalm" ,
51
+ "cs-check" : " phpcs" ,
52
+ "cs-fix" : " phpcbf" ,
53
+ "unit-tests" : " phpunit --colors=always" ,
54
+ "acceptance-tests" : " codecept build && codecept --ansi run acceptance"
55
+ }
56
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <ruleset name =" invajo" >
3
+ <!-- display progress -->
4
+ <arg value =" p" />
5
+ <arg name =" colors" />
6
+
7
+ <!-- Paths to check -->
8
+ <file >Plugin.php</file >
9
+ <file >tests</file >
10
+
11
+
12
+ <!-- inherit rules from: -->
13
+ <rule ref =" PSR12" />
14
+
15
+ <rule ref =" Generic.Arrays.DisallowLongArraySyntax" />
16
+ <rule ref =" Generic.Files.ByteOrderMark" />
17
+ <rule ref =" Generic.Files.LineEndings" />
18
+ <rule ref =" Generic.Files.LineLength" >
19
+ <properties >
20
+ <property name =" absoluteLineLimit" value =" 120" /><!-- even though psr-2 specifies it as soft-limit only -->
21
+ </properties >
22
+ </rule >
23
+ <rule ref =" Generic.PHP.DeprecatedFunctions" />
24
+ <rule ref =" Generic.PHP.ForbiddenFunctions" />
25
+
26
+ <rule ref =" Squiz.WhiteSpace.SuperfluousWhitespace" >
27
+ <properties >
28
+ <property name =" ignoreBlankLines" value =" false" />
29
+ </properties >
30
+ </rule >
31
+ </ruleset >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <phpunit
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : noNamespaceSchemaLocation =" vendor/phpunit/phpunit/phpunit.xsd"
5
+ bootstrap =" vendor/autoload.php"
6
+ colors =" true"
7
+ >
8
+ <testsuites >
9
+ <testsuite name =" default" >
10
+ <directory >tests</directory >
11
+ </testsuite >
12
+ </testsuites >
13
+ </phpunit >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <psalm
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns =" https://getpsalm.org/schema/config"
5
+ xsi : schemaLocation =" https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
6
+
7
+ totallyTyped =" true"
8
+ >
9
+ <projectFiles >
10
+ <directory name =" ." />
11
+ <ignoreFiles >
12
+ <directory name =" vendor" />
13
+ <directory name =" tests/_support/_generated" />
14
+ <directory name =" tests/_run" />
15
+ </ignoreFiles >
16
+ </projectFiles >
17
+
18
+ <issueHandlers >
19
+ <LessSpecificReturnType errorLevel =" info" />
20
+ </issueHandlers >
21
+
22
+ <plugins >
23
+ <pluginClass class =" Psalm\PhpUnitPlugin\Plugin" />
24
+ </plugins >
25
+ </psalm >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Weirdan \PsalmPluginSkeleton \Tests ;
4
+
5
+ use SimpleXMLElement ;
6
+ use Weirdan \PsalmPluginSkeleton \Plugin ;
7
+ use PHPUnit \Framework \TestCase ;
8
+ use Prophecy \PhpUnit \ProphecyTrait ;
9
+ use Prophecy \Prophecy \ObjectProphecy ;
10
+ use Psalm \Plugin \RegistrationInterface ;
11
+
12
+ class PluginTest extends TestCase
13
+ {
14
+ use ProphecyTrait;
15
+
16
+ /**
17
+ * @var ObjectProphecy<RegistrationInterface>
18
+ */
19
+ private $ registration ;
20
+
21
+ /**
22
+ * @return void
23
+ */
24
+ public function setUp (): void
25
+ {
26
+ $ this ->registration = $ this ->prophesize (RegistrationInterface::class);
27
+ }
28
+
29
+ /**
30
+ * @test
31
+ * @return void
32
+ */
33
+ public function hasEntryPoint ()
34
+ {
35
+ $ this ->expectNotToPerformAssertions ();
36
+ $ plugin = new Plugin ();
37
+ $ plugin ($ this ->registration ->reveal (), null );
38
+ }
39
+
40
+ /**
41
+ * @test
42
+ * @return void
43
+ */
44
+ public function acceptsConfig ()
45
+ {
46
+ $ this ->expectNotToPerformAssertions ();
47
+ $ plugin = new Plugin ();
48
+ $ plugin ($ this ->registration ->reveal (), new SimpleXMLElement ('<myConfig></myConfig> ' ));
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Weirdan \PsalmPluginSkeleton \Tests ;
4
+
5
+ /**
6
+ * Inherited Methods
7
+ * @method static wantToTest($text)
8
+ * @method static wantTo($text)
9
+ * @method static execute($callable)
10
+ * @method static expectTo($prediction)
11
+ * @method static expect($prediction)
12
+ * @method static amGoingTo($argumentation)
13
+ * @method static am($role)
14
+ * @method static lookForwardTo($achieveValue)
15
+ * @method static comment($description)
16
+ * @method static pause()
17
+ *
18
+ * @SuppressWarnings(PHPMD)
19
+ */
20
+ class AcceptanceTester extends \Codeception \Actor
21
+ {
22
+ use _generated \AcceptanceTesterActions;
23
+
24
+ /**
25
+ * Define custom actions here
26
+ */
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Weirdan \PsalmPluginSkeleton \Tests \Helper ;
4
+
5
+ // here you can define custom actions
6
+ // all public methods declared in helper class will be available in $I
7
+
8
+ class Acceptance extends \Codeception \Module
9
+ {
10
+
11
+ }
Original file line number Diff line number Diff line change
1
+ # Codeception Test Suite Configuration
2
+ #
3
+ # Suite for acceptance tests.
4
+ # Perform tests in browser using the WebDriver or PhpBrowser.
5
+ # If you need both WebDriver and PHPBrowser tests - create a separate suite.
6
+
7
+ actor : AcceptanceTester
8
+ modules :
9
+ enabled :
10
+ - Cli
11
+ - Filesystem
12
+ - \Weirdan\Codeception\Psalm\Module
13
+ - \Weirdan\PsalmPluginSkeleton\Tests\Helper\Acceptance
Original file line number Diff line number Diff line change
1
+ Feature : basics
2
+ In order to test my plugin
3
+ As a plugin developer
4
+ I need to have tests
5
+
6
+ Background :
7
+ Given I have the following config
8
+ """
9
+ <?xml version="1.0"?>
10
+ <psalm totallyTyped="true">
11
+ <projectFiles>
12
+ <directory name="."/>
13
+ </projectFiles>
14
+ <plugins>
15
+ <pluginClass class="Weirdan\PsalmPluginSkeleton\Plugin" />
16
+ </plugins>
17
+ </psalm>
18
+ """
19
+ Scenario : run without errors
20
+ Given I have the following code
21
+ """
22
+ <?php
23
+ echo atan(1);
24
+ """
25
+ When I run Psalm
26
+ Then I see no errors
27
+
28
+ Scenario : run with errors
29
+ Given I have the following code
30
+ """
31
+ <?php
32
+ echo atan("not a number");
33
+ """
34
+ When I run Psalm
35
+ Then I see these errors
36
+ | Type | Message |
37
+ | InvalidScalarArgument | /Argument 1 of atan expects float , (string (not a number )\|"not a number ") provided / |
38
+ And I see no other errors
39
+
You can’t perform that action at this time.
0 commit comments