Skip to content
A wrapper for defining constants in a more testable way.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests/php
.gitattributes
README.md
composer.json
phpunit.xml.dist

README.md

Jetpack Constants

A simple constant manager for Jetpack.

Testing constants is hard. Once you define a constant in PHP, it's defined. Constants Manager is an abstraction layer so that unit tests can set constants for tests.

Usage

Retrieve the value of a constant CONSTANT_NAME (returns null if it's not defined):

use Automattic\Jetpack\Constants;

$constant_value = Constants::get_constant( 'CONSTANT_NAME' );

Set the value of a constant CONSTANT_NAME to a particular value:

use Automattic\Jetpack\Constants;

$value = 'some value';
Constants::set_constant( 'CONSTANT_NAME', $value );

Check whether a constant CONSTANT_NAME is defined:

use Automattic\Jetpack\Constants;

$defined = Constants::is_defined( 'CONSTANT_NAME' );

Check whether a constant CONSTANT_NAME is truthy:

use Automattic\Jetpack\Constants;

$is_truthy = Constants::is_true( 'CONSTANT_NAME' );

Delete the CONSTANT_NAME constant:

use Automattic\Jetpack\Constants;

Constants::clear_single_constant( 'CONSTANT_NAME' );

Delete all known constants:

use Automattic\Jetpack\Constants;

Constants::clear_constants();
You can’t perform that action at this time.