Scalr\Tests\Functional\Ui\Controller\Farms\BuilderTest::testCheckBounds PHP Method

testCheckBounds() public method

public testCheckBounds ( boolean $valid, string $minBound, string $maxBound, string $validator, boolean $allowEqual = false, mixed $msg = false )
$valid boolean Expected result of testing.
$minBound string Minimum bound.
$maxBound string Maximum bound.
$validator string Numeric type of bounds. [integer|float=default]
$allowEqual boolean Is equal bounds allowed.
$msg mixed Custom Error message.
    public function testCheckBounds($valid, $minBound, $maxBound, $validator, $allowEqual = false, $msg = false)
    {
        $roleId = 33;
        $setting = 'scaling';
        $methodName = 'checkBounds';
        $defaultErrMsg = 'Invalid bounds.';
        $checkBoundsFn = self::getAccessibleMethod($this->builder, $methodName);
        $checkTypeFn = $validator === 'integer' ? 'is_int' : 'is_float';
        $errCountBefore = $this->builder->errors['error_count'];
        $ret = $checkBoundsFn->invoke($this->builder, $roleId, $setting, $minBound, $maxBound, $validator, $allowEqual, $msg);
        if ($valid) {
            $this->assertTrue(is_array($ret) && count($ret) === 2 && isset($ret[0]) && $checkTypeFn($ret[0]) && isset($ret[1]) && $checkTypeFn($ret[1]) && ($allowEqual ? $ret[0] <= $ret[1] : $ret[0] < $ret[1]), 'Returns sorted array with two elements, both integer or float type.');
        } else {
            $this->assertFalse($ret, 'Check not passed.');
            if ($msg === false) {
                $this->assertEquals($errCountBefore, $this->builder->errors['error_count'], 'Explicitly set Error message to *FALSE* prevents set build error.');
            } else {
                $this->assertEquals($errCountBefore + 1, $this->builder->errors['error_count'], 'Error count have been incremented.');
                if (!$msg) {
                    $this->assertEquals($defaultErrMsg, $this->builder->errors['roles'][$roleId][$setting], 'Not provided Error message leads to set default one.');
                } else {
                    $this->assertEquals($msg, $this->builder->errors['roles'][$roleId][$setting], 'Provided Error message used.');
                }
            }
        }
    }