test: add FlasherContainer tests

This commit is contained in:
Khoubza Younes
2023-01-22 21:49:31 +01:00
parent df7c886abd
commit 366787eb80
@@ -0,0 +1,60 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\Container;
use Flasher\Prime\Container\FlasherContainer;
use Flasher\Tests\Prime\TestCase;
class FlasherContainerTest extends TestCase
{
/**
* @return void
*/
public function testInit()
{
$this->setProperty('Flasher\Prime\Container\FlasherContainer', 'instance', null);
$container = $this->getMock('Flasher\Prime\Container\ContainerInterface');
FlasherContainer::init($container);
$property = $this->getProperty('Flasher\Prime\Container\FlasherContainer', 'container');
$this->assertEquals($container, $property);
}
/**
* @return void
*/
public function testCreate()
{
$this->setProperty('Flasher\Prime\Container\FlasherContainer', 'instance', null);
$container = $this->getMock('Flasher\Prime\Container\ContainerInterface');
$container
->method('get')
->willreturn($this->getMock('Flasher\Prime\FlasherInterface'));
FlasherContainer::init($container);
$service = FlasherContainer::create('flasher');
$this->assertInstanceOf('Flasher\Prime\FlasherInterface', $service);
}
/**
* @return void
*/
public function testThrowsExceptionIfNotInitialized()
{
$this->setExpectedException('\LogicException', 'Container is not initialized yet. Container::init() must be called with a real container.');
$this->setProperty('Flasher\Prime\Container\FlasherContainer', 'instance', null);
FlasherContainer::create('flasher');
}
}