Difference between revisions of "Testing"

From Freephile Wiki
Jump to navigation Jump to search
m (wip)
Line 9: Line 9:
 
==Links==
 
==Links==
  
# https://github.com/wikimedia/mediawiki-tools-phan
+
#https://github.com/wikimedia/mediawiki-tools-phan
# https://github.com/phan/phan
+
#https://github.com/phan/phan
# https://www.mediawiki.org/wiki/Continuous_integration/Entry_points
+
#https://www.mediawiki.org/wiki/Continuous_integration/Entry_points
# https://www.mediawiki.org/wiki/Continuous_integration/Phan
+
#https://www.mediawiki.org/wiki/Continuous_integration/Phan
# https://www.mediawiki.org/wiki/Best_practices_for_extensions#File_structure
+
#https://www.mediawiki.org/wiki/Best_practices_for_extensions#File_structure
# https://github.com/nikic/php-ast
+
#https://github.com/nikic/php-ast
  
 
==Static Analysis of MediaWiki==
 
==Static Analysis of MediaWiki==
 
For some current analysis see https://doc.wikimedia.org/mediawiki-core/master/phpmetrics/complexity.html
 
For some current analysis see https://doc.wikimedia.org/mediawiki-core/master/phpmetrics/complexity.html
  
== PHPStan ==
+
The on-wiki documentation and even the upstream projects do not exactly provide a usable guide for '''MediaWiki extension''' developers to actually use Phan. If you download MediaWiki and composer update (to get dev dependencies) and also install PHP-AST, then you should be able to run composer phan or ./vendor/bin/phan -p . But, that analyzes the entire MediaWiki codebase, and does '''not''' analyze your extension (unless you specifically add a proper .phan/config.php file to your extension).
 +
 
 +
[[Mark Hershberger]] provides a good example of what that might look like in his CommentStreams configuration<syntaxhighlight lang="php">
 +
<?php
 +
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
 +
$extensions = [ "Echo", "SocialProfile" ];
 +
// Assume this extension exists in a directory with a bunch of other extensions that may, or may not be, $IP/extensions
 +
$extDir = realpath( __DIR__ . "/../.." );
 +
$dirList = array_filter(
 +
array_map( fn ( $dir ): string => "$extDir/$dir", $extensions ),
 +
fn ( $dir ): bool => is_dir( $dir )
 +
);
 +
$cfg['directory_list'] = array_merge( $cfg['directory_list'] ?? [], $dirList );
 +
$cfg['exclude_analysis_directory_list'] = array_merge(
 +
$cfg['exclude_analysis_directory_list'] ?? [], $dirList
 +
);
 +
$cfg['suppress_issue_types'][] = 'PhanUndeclaredConstant';
 +
return $cfg;
 +
</syntaxhighlight>the more traditional form of that is<syntaxhighlight lang="php">
 +
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
 +
 
 +
$cfg['directory_list'] = array_merge(
 +
$cfg['directory_list'],
 +
[
 +
'../../extensions/Echo',
 +
'../../extensions/SocialProfile',
 +
]
 +
);
 +
$cfg['exclude_analysis_directory_list'] = array_merge(
 +
$cfg['exclude_analysis_directory_list'],
 +
[
 +
'../../extensions/Echo',
 +
'../../extensions/SocialProfile',
 +
]
 +
);
 +
 
 +
return $cfg;
 +
</syntaxhighlight>
 +
 
 +
==PHPStan==
 
https://phpstan.org/
 
https://phpstan.org/
  
== Psalm ==
+
==Psalm==
 
https://psalm.dev/
 
https://psalm.dev/
  

Revision as of 19:50, 16 February 2024

Testing is software development.

Software development is writing code. Testing makes sure the code actually works, so in a nutshell: Testing is software development :-)

Phan is a static analyzer for PHP. Phan project on GitHub It will help you write better PHP7 code. You'll need the Abstract Syntax Tree generated by PHP. You can read a tutorial for how to get Phan working in your project

The MediaWiki project uses Phan. See the article Continuous_integration/Phan

Links[edit | edit source]

  1. https://github.com/wikimedia/mediawiki-tools-phan
  2. https://github.com/phan/phan
  3. https://www.mediawiki.org/wiki/Continuous_integration/Entry_points
  4. https://www.mediawiki.org/wiki/Continuous_integration/Phan
  5. https://www.mediawiki.org/wiki/Best_practices_for_extensions#File_structure
  6. https://github.com/nikic/php-ast

Static Analysis of MediaWiki[edit | edit source]

For some current analysis see https://doc.wikimedia.org/mediawiki-core/master/phpmetrics/complexity.html

The on-wiki documentation and even the upstream projects do not exactly provide a usable guide for MediaWiki extension developers to actually use Phan. If you download MediaWiki and composer update (to get dev dependencies) and also install PHP-AST, then you should be able to run composer phan or ./vendor/bin/phan -p . But, that analyzes the entire MediaWiki codebase, and does not analyze your extension (unless you specifically add a proper .phan/config.php file to your extension).

Mark Hershberger provides a good example of what that might look like in his CommentStreams configuration

<?php
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
$extensions = [ "Echo", "SocialProfile" ];
// Assume this extension exists in a directory with a bunch of other extensions that may, or may not be, $IP/extensions
$extDir = realpath( __DIR__ . "/../.." );
$dirList = array_filter(
	array_map( fn ( $dir ): string => "$extDir/$dir", $extensions ),
	fn ( $dir ): bool => is_dir( $dir )
);
$cfg['directory_list'] = array_merge( $cfg['directory_list'] ?? [], $dirList );
$cfg['exclude_analysis_directory_list'] = array_merge(
	$cfg['exclude_analysis_directory_list'] ?? [], $dirList
);
$cfg['suppress_issue_types'][] = 'PhanUndeclaredConstant';
return $cfg;

the more traditional form of that is

$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';

$cfg['directory_list'] = array_merge(
	$cfg['directory_list'],
	[
		'../../extensions/Echo',
		'../../extensions/SocialProfile',
	]
);
$cfg['exclude_analysis_directory_list'] = array_merge(
	$cfg['exclude_analysis_directory_list'],
	[
		'../../extensions/Echo',
		'../../extensions/SocialProfile',
	]
);

return $cfg;

PHPStan[edit | edit source]

https://phpstan.org/

Psalm[edit | edit source]

https://psalm.dev/