Skip to content

Add --custom-function parameter to check #6

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
72e3c10
Add --custom-function parameter to add custom functions to the list o…
Dec 11, 2018
3940349
Add test for custom function parameter and add .idea folder to gitignore
Dec 11, 2018
a43368b
Revert the .idea folder
umutphp Jan 5, 2019
73dcc40
Implement the CR "Please use ` instead of " to match other parameters…
umutphp Jan 5, 2019
5c74a77
Empty is used instead of count($customFunctions) > 0
umutphp Jan 5, 2019
a3a361b
Merge branch 'master' into master
umutphp Jan 5, 2019
43d823b
Merge remote-tracking branch 'upstream/master'
umutphp Aug 14, 2020
6e2a072
Add test for none function founded
umutphp Aug 14, 2020
38513d0
Remove horizontal align
umutphp Aug 14, 2020
5495e34
Remove unneccessary empty check
umutphp Aug 14, 2020
e537cda
Add the Symfony Vardumper dd() helper method introduced in 4.1
umutphp Aug 14, 2020
66a65a8
Changed package name - new organization
grogy Feb 12, 2020
eee8857
Fixed Travis CI configuration
grogy Feb 16, 2020
417f968
Added replace to composer for previous package
grogy Mar 15, 2020
95e0158
Added run CI with PHP 7.4
grogy Apr 25, 2020
f58fae3
Fixed vendor names in readme for install
grogy Apr 25, 2020
562b7aa
Created version 0.4
grogy Apr 25, 2020
5847d7e
Create .gitattributes
reedy Apr 27, 2020
a29a7eb
Added .gitattributes to changelog
grogy May 14, 2020
f79cba3
Replace array syntax with short array syntax
peter279k May 26, 2020
f7886fd
Added PHP array syntax to changelog
grogy May 27, 2020
d6cf4df
Added cleaning changes to changelog
grogy May 27, 2020
e779ac4
Composer: allow installation of more recent Parallel Lint
jrfnl Jun 28, 2020
5941fae
Added internal change to changelog
grogy Aug 14, 2020
252cd39
PHP 7.4: fix compatibility issue
jrfnl Jun 28, 2020
0f7b965
Added fix for PHP 7.4 to changelog
grogy Aug 14, 2020
52d9da7
Add test for none function founded
umutphp Aug 14, 2020
6476f7b
Remove horizontal align
umutphp Aug 14, 2020
10fecd3
Remove unneccessary empty check
umutphp Aug 14, 2020
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/vendor/
/composer.lock
/composer.lock
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

- Added .gitattributes from [@reedy](https://github.com/reedy).

### Fixed

- PHP 7.4: fix compatibility issue [#7](https://github.com/php-parallel-lint/PHP-Var-Dump-Check/pull/7) from [@jrfnl](https://github.com/jrfnl).

### Internal

- Replaced array syntax with short array syntax from [@peter279k](https://github.com/peter279k).
- Added EOF (end of file) for some PHP files from [@peter279k](https://github.com/peter279k).
- Removed $loader variable on bootstrap.php file because it's unused from [@peter279k](https://github.com/peter279k).
- To be compatible with future PHPUnit version, using the ^4.8.36 version at least from [@peter279k](https://github.com/peter279k).
- Changed namespace to PHPunit\Framework\TestCase class namesapce from [@peter279k](https://github.com/peter279k).
- Composer: allow installation of more recent Parallel Lint [#9](https://github.com/php-parallel-lint/PHP-Var-Dump-Check/pull/9) from [@jrfnl](https://github.com/jrfnl).

## [v0.4] - 2020-04-25

### Added

- Added check for Symfony dump function `dd` from [@antograssiot](https://github.com/antograssiot).
- Added check for Laravel dump function `dump` from [@Douglasdc3](https://github.com/Douglasdc3).
- Added changelog.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Options for run
- `--doctrine` - check dump: `Doctrine::dump`, `\Doctrine\Common\Util\Debug::dump`
- `--symfony` - check dump: `dump`, `VarDumper::dump`, `VarDumper::setHandler`, `VarDumper::dd`
- `--laravel` - check dump: `dd`, `dump`
- `--custom-function` - comma separated custom function name(s) to check like `pre_echo`
Copy link
Member

Choose a reason for hiding this comment

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

This commit can be squash with implementation

- `--no-colors` - disable colors from output
- `--exclude folder/` - exclude *folder/* from check
- `--extensions php,phpt,php7` - map file extensions for check
Expand Down
9 changes: 9 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function parseArguments(array $arguments)
{
$arguments = new ArrayIterator(array_slice($arguments, 1));
$setting = new self;
$customFunctions = array();

foreach ($arguments as $argument) {
if ($argument[0] !== '-') {
Expand Down Expand Up @@ -124,6 +125,10 @@ public static function parseArguments(array $arguments)
$setting->functionsToCheck[] = self::LARAVEL_DUMP;
break;

case '--custom-function':
$customFunctions = array_map('trim', explode(',', $arguments->getNext()));
break;

case '--doctrine':
$setting->functionsToCheck[] = self::DOCTRINE_DUMP;
$setting->functionsToCheck[] = self::DOCTRINE_DUMP_2;
Expand All @@ -134,7 +139,11 @@ public static function parseArguments(array $arguments)
}
}
}

// Merge if any custom function is given
$setting->functionsToCheck = array_merge($setting->functionsToCheck, $customFunctions);
$setting->functionsToCheck = array_unique($setting->functionsToCheck);

return $setting;
}

Expand Down
79 changes: 79 additions & 0 deletions tests/JakubOnderka/PhpVarDumpCheck/CustomFunctionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

Please, why isn't this commit included in implementation? I mean that will be better for people who read Git history :)


use JakubOnderka\PhpVarDumpCheck;

class CustomFunctionTest extends PHPUnit_Framework_TestCase
{

public function testCheck_noDebugFunction()
{
$settings = new PhpVarDumpCheck\Settings();

$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
'functionName1'
));

$uut = new PhpVarDumpCheck\Checker($settings);
$content = <<<PHP
<?php
nonDebugFunction1(\$var);
\$i++;
nonDebugFunction2(\$i);
PHP;
$result = $uut->check($content);
$this->assertCount(0, $result);
}

Copy link
Member

Choose a reason for hiding this comment

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

What about add test for none function founded? (I mean when code does not includes functionName1) It coverage all cases

public function testCheck_singleFunction()
{
$settings = new PhpVarDumpCheck\Settings();

$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
'functionName1'
));

$uut = new PhpVarDumpCheck\Checker($settings);
$content = <<<PHP
<?php
functionName1(\$var);
PHP;
$result = $uut->check($content);
$this->assertCount(1, $result);
}


public function testCheck_multipleFunction()
{
$settings = new PhpVarDumpCheck\Settings();

$settings->functionsToCheck = array_merge($settings->functionsToCheck, array(
'functionName1',
'functionName2'
));

$uut = new PhpVarDumpCheck\Checker($settings);

$content1 = <<<PHP
<?php
functionName1(\$var);
PHP;
$content2 = <<<PHP
<?php
functionName2(\$var);
PHP;
$content3 = <<<PHP
<?php
functionName1(\$var);
sleep(4);
functionName2(\$var);
PHP;
$result = $uut->check($content1);
$this->assertCount(1, $result);

$result = $uut->check($content2);
$this->assertCount(1, $result);

$result = $uut->check($content3);
$this->assertCount(2, $result);
}
}
27 changes: 14 additions & 13 deletions var-dump-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
function showOptions() {
?>
Options:
--tracy Enable support for Tracy (Debugger::dump)
--zend Enable support for Zend (Zend_Debug::dump and \Zend\Debug\Debug::dump)
--ladybug Enable support for Ladybug (ladybug_dump, ladybug_dump_die, ld, ldd)
--symfony Enable support for Symfony2 (dump, VarDumper::dump, VarDumper::setHandler, Vardumper::dd())
--doctrine Enable support for Doctrine (Doctrine::dump, \Doctrine\Common\Util\Debug::dump)
--laravel Enable support for Laravel (dd, dump)
--extensions Check only files with selected extensions separated by comma
(default: php, php3, php4, php5, phtml)
--exclude Exclude directory. If you want exclude multiple directory, use
multiple exclude parameters.
--no-colors Disable colors in console output.
-V, --version Show version.
-h, --help Print this help.
--tracy Enable support for Tracy (Debugger::dump)
--zend Enable support for Zend (Zend_Debug::dump and \Zend\Debug\Debug::dump)
--ladybug Enable support for Ladybug (ladybug_dump, ladybug_dump_die, ld, ldd)
--symfony Enable support for Symfony2 (dump, VarDumper::dump, VarDumper::setHandler, Vardumper::dd())
--doctrine Enable support for Doctrine (Doctrine::dump, \Doctrine\Common\Util\Debug::dump)
--laravel Enable support for Laravel (dd, dump)
--custom-function Comma separated custom function name(s) to check like "pre_echo".
--extensions Check only files with selected extensions separated by comma
(default: php, php3, php4, php5, phtml)
--exclude Exclude directory. If you want exclude multiple directory, use
multiple exclude parameters.
--no-colors Disable colors in console output.
-V, --version Show version.
-h, --help Print this help.
<?php
}

Expand Down