2017-09-21 13:29:36 +00:00
|
|
|
<?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
|
2017-11-11 12:09:30 +00:00
|
|
|
$err = ModuleFactory::getModule('documentationDefault');
|
2017-09-21 13:29:36 +00:00
|
|
|
|
2017-11-11 12:09:30 +00:00
|
|
|
expect($err)->not->toBeAnInstanceOf("\\error\\core\\Error");
|
2017-09-21 13:29:36 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|