82 lines
2.0 KiB
PHP
82 lines
2.0 KiB
PHP
|
<?php
|
||
|
|
||
|
use Kahlan\Plugin\Stub;
|
||
|
use Kahlan\Plugin\Monkey;
|
||
|
|
||
|
use api\core\ModuleFactory;
|
||
|
use error\core\Error;
|
||
|
use error\core\Err;
|
||
|
|
||
|
describe('api', function(){
|
||
|
describe('core', function(){
|
||
|
describe('ModuleFactory', function(){
|
||
|
|
||
|
context('param error', function(){
|
||
|
|
||
|
it('fail if @module is not a <string>', function(){
|
||
|
|
||
|
$err = ModuleFactory::getModule(11);
|
||
|
|
||
|
expect($err)->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
expect($err->get())->toBe(Err::WrongParam);
|
||
|
|
||
|
});
|
||
|
|
||
|
it('fail if @arguments is not an <array>', function(){
|
||
|
|
||
|
$err = ModuleFactory::getModule('someMod', 12);
|
||
|
|
||
|
expect($err)->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
expect($err->get())->toBe(Err::WrongParam);
|
||
|
|
||
|
});
|
||
|
|
||
|
it('pass if @arguments not given (default value)', function(){
|
||
|
|
||
|
$err = ModuleFactory::getModule('bla');
|
||
|
|
||
|
expect($err)->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
expect($err->get())->not->toBe(Err::WrongParam);
|
||
|
|
||
|
});
|
||
|
|
||
|
it('fail if @module implementation file does not exist', function(){
|
||
|
|
||
|
allow('file_exists')->toBeCalled()->andReturn(false);
|
||
|
|
||
|
$err = ModuleFactory::getModule('bla');
|
||
|
|
||
|
expect($err)->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
expect($err->get())->toBe(Err::UncallableModule);
|
||
|
|
||
|
});
|
||
|
|
||
|
it('fail if @module implementation file exists but instanciation fails', function(){
|
||
|
|
||
|
allow('file_exists')->toBeCalled()->andReturn(true);
|
||
|
|
||
|
$err = ModuleFactory::getModule('bla');
|
||
|
|
||
|
expect($err)->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
expect($err->get())->toBe(Err::UncallableModule);
|
||
|
|
||
|
});
|
||
|
|
||
|
it('pass if @module implementation file exists and instanciation succeeds', function(){
|
||
|
|
||
|
allow('file_exists')->toBeCalled()->andReturn(true);
|
||
|
|
||
|
// normally the 'module' module is always here for testing purposes
|
||
|
$err = ModuleFactory::getModule('module');
|
||
|
|
||
|
expect($err)->not->toBeAnInstanceOf('\\error\\core\\Error');
|
||
|
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
});
|
||
|
|
||
|
});
|
||
|
});
|
||
|
});
|