Git Bash inside PhpStorm

Hits: 191

Go to: File -> Settings -> Tools -> Terminal

If you are using 64 Bit Git Bash(Git for Windows) put this in the Shell Path field.

"C:\Program Files\Git\bin\sh.exe" -login -i

Or for 32 Bit Git Bash put this in the field

"C:\Program Files (x86)\Git\bin\sh.exe" -login -i

PSR-2 PHP_CodeSniffer Config

Hits: 142

# phpcs.xml, this file must be under project root folder.

<?xml version="1.0"?>
<ruleset name="Basic Project Coding Standards">
    <rule ref="PSR2" />

    <!-- extra rules for the laugh ;-) LOL -->
    <rule ref="Generic.CodeAnalysis.EmptyStatement" />
    <rule ref="Generic.Classes.DuplicateClassName"/>
    <rule ref="Generic.CodeAnalysis.EmptyStatement"/>
    <rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
    <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
    <rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
    <rule ref="Generic.ControlStructures.InlineControlStructure"/>
    <rule ref="Squiz.PHP.NonExecutableCode"/>

    <file>./src</file>
    <file>./test</file>
</ruleset>

 

Travis CI for PHPUnit and PHP_CodeSniffer

Hits: 332

# .travis.yml, this file must be under project root folder.

language: php
php:
    - 7.2
before_script:
    - composer self-update
    - composer install --prefer-source --no-interaction --dev
script:
    - phpunit
    - ./vendor/bin/phpcs

 

PHPUnit Boilerplate

Hits: 112

Of course first  phpunit/phpunit to be installed. I think, local installation much better.

composer require --dev phpunit/phpunit ^7

# phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./src</directory>
        </whitelist>
    </filter>
</phpunit>

# ExampleTest.php, this file must be under tests folder.

(root/tests/ExampleTest.php)

?php
namespace yourvendorname\yourpackagename;
use PHPUnit\Framework\TestCase;

/**
 * Description of ExampleTest
 *
 * @author Koray Zorluoglu <koray@d8devs.com>
 */
class ExampleTest extends TestCase
{

    public function testExampleMethod()
    {
        $count = 0;
        $this->assertSame(0, $count);
    }

}

# Run on Command prompt.

./vendor/bin/phpunit

# Example Output

$ ./vendor/bin/phpunit
PHPUnit 7.4.5 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 968 ms, Memory: 4.00MB

OK (4 tests, 4 assertions)