/** * Asserts that a file permission matches, for example: 'drwxrwxrwx' or '0664'. * * @param int|string $permissions > 0 or string; format for example: 'drwxrwxrwx' * @param mixed $filename * @param string $message */ public static function assertFileHasPermissions($permissions, $filename, $message = '') { if (!is_string($permissions) && !(is_int($permissions) && $permissions >= 0)) { throw AssertHelper::createArgumentException(__TRAIT__, 'assertFileHasPermissions', 'int (>= 0) or string', $permissions); } try { $constraint = new FilePermissionsIsIdenticalConstraint($permissions); } catch (\InvalidArgumentException $e) { throw AssertHelper::createException(__TRAIT__, 'assertFileHasPermissions', substr($e->getMessage(), 0, -1)); } self::assertThatConstraint($filename, $message, 'assertFileHasPermissions', $constraint); }
/** * @param int|float $lowerBoundary * @param int|float $upperBoundary * @param mixed $actual * @param string $message * @param string $method name of method doing the testing * @param bool $onBoundary test on boundary or between boundary values * @param bool $negative test as negative */ private static function assertNumberRangeMatch($lowerBoundary, $upperBoundary, $actual, $message, $method, $onBoundary, $negative) { if (!is_int($lowerBoundary) && !is_float($lowerBoundary)) { throw AssertHelper::createArgumentException(__TRAIT__, $method, 'float or int', $lowerBoundary); } if (!is_int($upperBoundary) && !is_float($upperBoundary)) { throw AssertHelper::createArgumentException(__TRAIT__, $method, 'float or int', $upperBoundary, 2); } if ($lowerBoundary >= $upperBoundary) { $message = sprintf('lower boundary %s must be smaller than upper boundary %s', is_int($lowerBoundary) ? '%d' : '%.3f', is_int($upperBoundary) ? '%d' : '%.3f'); throw AssertHelper::createException(__TRAIT__, $method, sprintf($message, $lowerBoundary, $upperBoundary)); } $rangeConstraint = new NumberRangeConstraint($lowerBoundary, $upperBoundary, $onBoundary); if ($negative) { $rangeConstraint = new \PHPUnit_Framework_Constraint_Not($rangeConstraint); } AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat')); self::assertThat($actual, $rangeConstraint, $message); }