dev-master
9999999-devSmoke testing for php projects
proprietary
The Requires
Wallogit.com
2017 © Pedro Peláez
Smoke testing for php projects
Smoke testing package for PHP projects., (*1)
If you want to add smoke testing to check if environment variables are loaded and are not empty
in your machine you only need extends from class CheckEnvironment class:, (*2)
namespace Tests\SmokeTesting;
use BgSmokeTesting\Environment\CheckEnvironment;
class BgFlashCheckEnvironmentTest extends CheckEnvironment
{
/**
* {@inheritdoc}
*/
public function getEnvPath(): string
{
return'{ROOT_PROJECT_PATH}/.env.dist'; // OR .env.development
}
}
And implement the method getEnvPath(). If for example in your file .env.distyou have
the variable DB_CONNECTION but this is not loaded or is empty the assertion will fail with a message like this:, (*3)
"Environment variable 'DB_CONNECTION' does not exist" or "Environment variable 'DB_CONNECTION' is empty"., (*4)
If you resolve in bad way conflicts with files composer.json and composer.lock it is necessary ensure your lock file is not out date., (*5)
So to add smoke testing to avoid these kind of problems you can extends from class LockFileOutOfDate class:, (*6)
namespace Tests\SmokeTesting;
use BernardoSecades\SmokeTesting\Composer\LockFileOutOfDate;
class MyLockFileOutOfDateTest extends LockFileOutOfDate
{
/**
* {@inheritdoc}
*/
public function getProjectPath(): string
{
return'{ROOT_PROJECT_PATH}';
}
}
If you are working with frameworks like Symfony, Laravel, Yii, ... you are using a container to handle dependency injections. These frameworks are using containers follow PSR-11 so this smoke test ensure your container is working properly. You can use this smoke testing in any framework follow PSR-11., (*7)
Example for laravel framework:, (*8)
namespace Tests\Smoke;
use BernardoSecades\SmokeTesting\ServiceContainer\CheckServiceContainer;
use Psr\Container\ContainerInterface;
use Illuminate\Container\Container;
class MyCheckServiceContainer extends CheckServiceContainer
{
/**
* @return Container
*/
protected function getLaravelContainer(): Container
{
return require __DIR__.'/../../bootstrap/app.php';
}
/**
* {@inheritdoc}
*/
protected function getContainer(): ContainerInterface
{
return $this->getLaravelContainer();
}
/**
* {@inheritdoc}
*/
protected function getAllServiceNames(): array
{
$bidings = $this->getLaravelContainer()->getBindings();
if (empty($bidings)) {
return [];
}
return array_keys($bidings);
}
}
Docker guide helps developers to setup staging/development env in docker. Docker guidelines for this project, (*9)
./vendor/bin/phpnit, (*10)
Smoke testing for php projects
proprietary