Introduction

Smoke testing is preliminary testing to reveal simple failures severe enough to (for example) reject a prospective software release.

So if our application are working with environment variables, a possible smoke test can be checking if in the machine where we are trying to do deploy are ready all environment variables need by our application.

Test to check environment variables

We can use the component symfony/dotenv to check our environment variables from our template file .env.dist (See more in related post runtime-environment-variables-in-symfony)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# my-project/tests/SmokeTesting/CheckEnvironmentVariablesTest.php

<?php

namespace Tests\SmokeTesting;

use Symfony\Component\Dotenv\Dotenv;

/**
 * @author bernardosecades
 * @link http://symfony.com/doc/master/components/dotenv.html
 */
class CheckEnvironmentVariablesTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function check()
    {
        $path = __DIR__.'/../../.env.dist';

        $dotenv = new Dotenv();
        $vars = $dotenv->parse(file_get_contents($path), $path);
        $varNames = array_keys($vars);

        foreach ($varNames as $varName) {
            $value = getenv($varName);
            if (false === $value) {
                $this->fail(
                    sprintf(
                        'Environment variable "%s" does not exist'
                        , $varName
                    )
                );
            }
            if (empty($value)) {
                $this->fail(
                    sprintf(
                        'Environment variable "%s" is empty'
                        , $varName
                    )
                );
            }
        }

        $this->assertTrue(true);
    }
}

See the example in github, smoke-testing.