Abstract Class luya\testsuite\scopes\BaseScope
Inheritance | luya\testsuite\scopes\BaseScope |
---|---|
Subclasses | luya\testsuite\scopes\PageScope, luya\testsuite\scopes\PermissionScope |
Available since version | 1.0.21 |
Source Code | https://github.com/luyadev/luya-testsuite/blob/master/src/scopes/BaseScope.php |
Base Class for Scoped Actions.
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | Permission Scope contstructor. | luya\testsuite\scopes\BaseScope |
cleanup() | Clean up tables and fixtures. | luya\testsuite\scopes\BaseScope |
cleanupFixture() | A helper method to cleanup fixtures. | luya\testsuite\scopes\BaseScope |
configure() | Configured is used before prepare which allows you to configure the current scope. | luya\testsuite\scopes\BaseScope |
getApp() | Returns the Application instance. | luya\testsuite\scopes\BaseScope |
prepare() | This method is called before the callback runs in order to prepare and setup the permission scope. | luya\testsuite\scopes\BaseScope |
run() | Run a given function inside a permission scope. | luya\testsuite\scopes\BaseScope |
runCallable() | Run the provided callable function | luya\testsuite\scopes\BaseScope |
Method Details
Permission Scope contstructor.
public void __construct ( yii\base\Application $app, callable $fn, callable $invoke = null ) | ||
$app | yii\base\Application | |
$fn | callable | |
$invoke | callable |
public function __construct(Application $app, callable $fn, callable $invoke = null)
{
$this->_app = $app;
$this->_invoke = $invoke;
$this->_fn = $fn;
}
A helper method to cleanup fixtures.
If the given fixture property is not an instance of ActiveRecordFixture nothing happens, otherwise the cleanup() will be run.
public void cleanupFixture ( $fixture ) | ||
$fixture | mixed |
public function cleanupFixture($fixture)
{
if ($fixture instanceof ActiveRecordFixture) {
$fixture->cleanup();
}
}
Configured is used before prepare which allows you to configure the current scope.
public void configure ( ) |
public function configure()
{
if ($this->_invoke) {
call_user_func_array($this->_invoke, [$this]);
}
}
Returns the Application instance.
Getter method to access the private object.
public yii\base\Application getApp ( ) |
public function getApp()
{
return $this->_app;
}
This method is called before the callback runs in order to prepare and setup the permission scope.
public abstract void prepare ( ) |
abstract public function prepare();
Run a given function inside a permission scope.
public static mixed run ( yii\base\Application $app, callable $fn, callable $invoke = null ) | ||
$app | \luya\testsuite\scopes\yii\base\Application | |
$fn | callable |
The function to run. |
$invoke | callable |
The function to configure the scope. |
public static function run(Application $app, callable $fn, callable $invoke = null)
{
$scope = new static($app, $fn, $invoke);
$scope->configure();
$scope->prepare();
$response = $scope->runCallable($scope);
$scope->cleanup();
return $response;
}
Run the provided callable function
public mixed runCallable ( luya\testsuite\scopes\BaseScope $scope ) | ||
$scope | luya\testsuite\scopes\PermissionScope |
public function runCallable(BaseScope $scope)
{
return call_user_func_array($this->_fn, [$scope]);
}