Pressbooks\Container::set PHP Method

set() static public method

static public set ( string $key, mixed $val, string $type = null )
$key string
$val mixed
$type string (optional)
    static function set($key, $val, $type = null)
    {
        if (!static::$pimple) {
            throw new \LogicException('\\Pimple\\Container not set, call init() or setPimple() before using set().');
        }
        if ('factory' == $type) {
            static::$pimple[$key] = static::$pimple->factory($val);
        } elseif ('protect' == $type) {
            static::$pimple[$key] = static::$pimple->protect($val);
        } else {
            static::$pimple[$key] = $val;
        }
    }

Usage Example

 /**
  * Override
  */
 public function setUp()
 {
     parent::setUp();
     // Replace GlobalTypography service with mock
     Container::set('GlobalTypography', function () {
         $stub = $this->getMockBuilder('\\Pressbooks\\GlobalTypography')->getMock();
         return $stub;
     });
     // Replace Sass service with mock
     Container::set('Sass', function () {
         $stub = $this->getMockBuilder('\\Pressbooks\\Sass')->getMock();
         $stub->method('pathToUserGeneratedCss')->willReturn($this->_createTmpDir());
         $stub->method('pathToPartials')->willReturn(PB_PLUGIN_DIR . 'assets/scss/partials');
         return $stub;
     });
 }
All Usage Examples Of Pressbooks\Container::set