Integrating Automation Testing Tools with PhpStorm on CentOS
PhpStorm provides seamless integration with popular PHP automation testing tools like PHPUnit (unit testing), Codeception (unit/functional/acceptance testing), and static analysis tools (PHPStan, Psalm). Below is a structured guide to setting up these integrations on a CentOS environment.
Before integrating testing tools, ensure your CentOS environment has:
php-cli, php-mbstring, php-xml, php-pdo, php-mysqlnd):sudo yum install php php-cli php-mbstring php-xml php-pdo php-mysqlnd
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
PHPUnit is the most widely used unit testing framework for PHP. Follow these steps to integrate it with PhpStorm:
Use Composer to install PHPUnit locally in your project (recommended) or globally:
composer require --dev phpunit/phpunit
sudo pecl install phpunit/phpunit
echo "extension=phpunit.so" | sudo tee /etc/php.d/phpunit.ini
sudo systemctl restart httpd # Restart web server (Apache/Nginx)
vendor/bin/phpunit (relative to your project root)./usr/bin/phpunit.tests/) in your project root.tests/ExampleTest.php):use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase {
public function testBasicTest() {
$this->assertTrue(true);
}
}
Codeception supports unit, functional, and acceptance testing with a single tool. Here’s how to integrate it:
Install Codeception via Composer (local or global):
composer require --dev codeception/codeception
codecept.phar from the Codeception website and save it to your project root.codecept bootstrap in your project root (via PhpStorm’s built-in terminal) to generate a codeception.yml file.codecept.phar (if globally installed) or vendor/bin/codecept (if local).tests/ directory as a “Test Sources Root” (right-click the directory → Mark Directory as → Test Sources Root) to enable code completion.codecept generate:test unit Example
This creates tests/unit/ExampleTest.php.class ExampleTest extends \Codeception\Test\Unit {
public function testBasicTest() {
$this->assertTrue(true);
}
}
codecept run).Static analysis tools catch potential errors without executing code. PhpStorm supports both PHPStan and Psalm:
Use Composer to install locally in your project:
composer require --dev phpstan/phpstan
composer require --dev vimeo/psalm
vendor/bin/phpstan.vendor/bin/psalm.vendor/bin directory) for project-specific dependencies to avoid conflicts.By following these steps, you can fully integrate PHPUnit, Codeception, and static analysis tools with PhpStorm on CentOS, enabling efficient automated testing and code quality management.