sweetchuck/env-var-storage

@todo project description

1.x-dev 2023-12-26 18:19 UTC

This package is auto-updated.

Last update: 2024-03-26 19:12:34 UTC


README

CircleCI codecov

This library provides a wrapper around the \getenv() and \putenv() functions.

Interface

EnvVarStorageInterface

Implementation - real

EnvVarStorage uses the real \getenv() and \putenv() functions to get/set environment variables.

Implementation - dummy

ArrayStorage uses an \ArrayObject instance to store „environment” variables. Use this one for testing purposes.

Service definition

services:
    env_var_storage:
        shared: true
        class: 'Sweetchuck\EnvVarStorage\EnvVarStorage'

Usage

<?php

use Sweetchuck\EnvVarStorage\EnvVarStorageInterface;

class Foo
{    
    protected EnvVarStorageInterface $envVarStorage;

    public function __construct(EnvVarStorageInterface $envVarStorage) {
        $this->envVarStorage = $envVarStorage;
    }
    
    public function doSomething(): string
    {
        return $this->envVarStorage->get('PATH');
    }
}

Usage in tests

<?php

class FooTest extends \PHPUnit\Framework\TestCase
{
    public function testDoSomething()
    {
        $envVarStorage = new \Sweetchuck\EnvVarStorage\ArrayStorage(new \ArrayObject(['PATH' => '/a:/b']))
        $foo = new \Foo($envVarStorage);
        $this->assertSame('/a:/b', $foo->doSomething());
    }
}