sweetchuck/env-var-storage

@todo project description

1.x-dev 2024-11-06 21:22 UTC

This package is auto-updated.

Last update: 2024-11-06 21:22:23 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());
    }
}