/** * @throws TypeNotNumeric if $limit is not numeric. * @throws TypeNotNumeric if the subject is not numeric. * @throws ValueTooBig if the subject is greater than $limit. * * @return $this */ public function isLessThanOrEqualTo($limit) { $this->isNumeric(); \Guardsman\check($limit)->isNumeric(); if ($this->getSubject() > $limit) { throw new ValueTooBig('Subject must be less than or equal to the limit'); } return $this; }
/** * @expectedException \Guardsman\Exceptions\TypeNotDateTime * @dataProvider nonDateTimeProvider */ public function testIsAfterOrEqualToGuardsAgainstNonDateTimeSubjects($subject) { \Guardsman\check($subject)->isAfterOrEqualTo(new \DateTime('13th July 2014')); }
/** * @expectedException \Guardsman\Exceptions\TypeNotString * @dataProvider invalidStringProvider */ public function testMatchesRegexGuardsAgainstNonStringPatterns($pattern) { \Guardsman\check('guardsman')->matchesRegex($pattern); }
/** * @throws TypeNotString if $pattern is not a string. * @throws TypeNotString if the subject is not a string. * @throws StringFailsRegex if the subject is not matched by the given patterm. * * @return $this */ public function matchesRegex($pattern) { \Guardsman\check($pattern)->isString(); $this->isString(); if (!preg_match($pattern, $this->getSubject())) { throw new StringFailsRegex('Subject must be matched by the given pattern'); } return $this; }
/** @dataProvider notEmptyProvider */ public function testIsNotEmpty($subject) { $this->assertInstanceOf(\Guardsman\Guardsman::class, \Guardsman\check($subject)->isNotEmpty()); }
/** * @expectedException \Guardsman\Exceptions\KeyExists * @dataProvider isKeyOfProvider */ public function testisNotKeyOfThrowsKeyExists($subject, $array) { \Guardsman\check($subject)->isNotKeyOf($array); }
/** * @expectedException \Guardsman\Exceptions\TypeNotNumeric * @dataProvider nonNumericProvider */ public function testIsNegativeGuardsAgainstNonNumericSubjects($subject) { \Guardsman\check($subject)->isNegative(); }